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