Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WarehousePeriodGet
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsapi;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12
13class 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
31        $exchangeClass = '\BO\Zmsdb\Exchange' . ucfirst($subject);
32        if (! class_exists($exchangeClass)) {
33            throw new Exception\Warehouse\UnknownReportType();
34        }
35        $periodHelper = new Helper\ExchangePeriod($period);
36        $subjectPeriod = (new $exchangeClass())->readEntity(
37            $subjectId,
38            $periodHelper->getStartDateTime(),
39            $periodHelper->getEndDateTime(),
40            $periodHelper->getPeriodIdentifier($groupby)
41        );
42        if (0 == count($subjectPeriod['data'])) {
43            throw new Exception\Warehouse\ReportNotFound();
44        }
45
46        $message = Response\Message::create($request);
47        $message->data = (new Helper\ExchangeAccessFilter($subjectPeriod, $workstation))->getFilteredEntity();
48
49        $response = Render::withLastModified($response, time(), '0');
50        $response = Render::withJson($response, $message, $message->getStatuscode());
51        return $response;
52    }
53}