Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| WarehousePeriodGet | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| readResponse | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package ZMS API |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 6 | **/ |
| 7 | |
| 8 | namespace BO\Zmsapi; |
| 9 | |
| 10 | use BO\Slim\Render; |
| 11 | use BO\Mellon\Validator; |
| 12 | |
| 13 | class WarehousePeriodGet extends BaseController |
| 14 | { |
| 15 | /** |
| 16 | * @SuppressWarnings(Param) |
| 17 | * @return String |
| 18 | */ |
| 19 | public function readResponse( |
| 20 | \Psr\Http\Message\RequestInterface $request, |
| 21 | \Psr\Http\Message\ResponseInterface $response, |
| 22 | array $args |
| 23 | ) { |
| 24 | $workstation = (new Helper\User($request, 2))->checkRights('scope'); |
| 25 | $subject = Validator::value($args['subject'])->isString()->getValue(); |
| 26 | $subjectId = Validator::value($args['subjectId'])->isString()->getValue(); |
| 27 | $period = Validator::value($args['period'])->isString()->isBiggerThan(2)->setDefault('_')->getValue(); |
| 28 | $validator = $request->getAttribute('validator'); |
| 29 | $groupby = $validator->getParameter('groupby')->isString()->isBiggerThan(2)->getValue(); |
| 30 | $fromDate = $validator->getParameter('fromDate')->isString()->getValue(); |
| 31 | $toDate = $validator->getParameter('toDate')->isString()->getValue(); |
| 32 | |
| 33 | $exchangeClass = '\BO\Zmsdb\Exchange' . ucfirst($subject ?? ''); |
| 34 | if (! class_exists($exchangeClass)) { |
| 35 | throw new Exception\Warehouse\UnknownReportType(); |
| 36 | } |
| 37 | |
| 38 | $periodHelper = new Helper\ExchangePeriod($period); |
| 39 | $start = $periodHelper->getStartDateTime(); |
| 40 | $end = $periodHelper->getEndDateTime(); |
| 41 | |
| 42 | $subjectPeriod = (new $exchangeClass())->readEntity( |
| 43 | $subjectId, |
| 44 | $fromDate ? new \DateTime($fromDate) : $start, |
| 45 | $toDate ? new \DateTime($toDate) : $end, |
| 46 | $periodHelper->getPeriodIdentifier($groupby) |
| 47 | ); |
| 48 | if (0 == count($subjectPeriod['data'])) { |
| 49 | throw new Exception\Warehouse\ReportNotFound(); |
| 50 | } |
| 51 | |
| 52 | $message = Response\Message::create($request); |
| 53 | $message->data = (new Helper\ExchangeAccessFilter($subjectPeriod, $workstation))->getFilteredEntity(); |
| 54 | |
| 55 | $response = Render::withLastModified($response, time(), '0'); |
| 56 | $response = Render::withJson($response, $message, $message->getStatuscode()); |
| 57 | return $response; |
| 58 | } |
| 59 | } |