Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
98.28% |
57 / 58 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
ScopeAvailabilityMonth | |
98.28% |
57 / 58 |
|
50.00% |
1 / 2 |
6 | |
0.00% |
0 / 1 |
readResponse | |
97.73% |
43 / 44 |
|
0.00% |
0 / 1 |
3 | |||
getAvailabilityList | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | /** |
4 | * Return availability list by scope in month view. |
5 | * |
6 | * @copyright 2018 BerlinOnline Stadtportal GmbH & Co. KG |
7 | */ |
8 | |
9 | namespace BO\Zmsadmin; |
10 | |
11 | use BO\Mellon\Validator; |
12 | use BO\Zmsentities\Calendar; |
13 | use BO\Zmsentities\Collection\AvailabilityList; |
14 | use BO\Zmsentities\Collection\ProcessList; |
15 | |
16 | class ScopeAvailabilityMonth extends BaseController |
17 | { |
18 | /** |
19 | * Return response. |
20 | * |
21 | * @SuppressWarnings(Param) |
22 | * |
23 | * @param \Psr\Http\Message\RequestInterface $request The request instance |
24 | * @param \Psr\Http\Message\ResponseInterface $response The response instance |
25 | * @param array $args The path arguments |
26 | * |
27 | * @return string |
28 | */ |
29 | public function readResponse( |
30 | \Psr\Http\Message\RequestInterface $request, |
31 | \Psr\Http\Message\ResponseInterface $response, |
32 | array $args |
33 | ) { |
34 | $workstation = \App::$http->readGetResult('/workstation/', [ |
35 | 'resolveReferences' => 1, |
36 | 'gql' => Helper\GraphDefaults::getWorkstation() |
37 | ])->getEntity(); |
38 | |
39 | $dateTime = (isset($args['date'])) ? new \BO\Zmsentities\Helper\DateTime($args['date']) : \App::$now; |
40 | $startDate = $dateTime->modify('first day of this month'); |
41 | $endDate = $dateTime->modify('last day of this month'); |
42 | |
43 | $scopeId = Validator::value($args['id'])->isNumber()->getValue(); |
44 | $scope = \App::$http->readGetResult('/scope/' . $scopeId . '/', [ |
45 | 'resolveReferences' => 1 |
46 | ])->getEntity(); |
47 | $calendar = new Helper\Calendar($dateTime->format('Y-m-d')); |
48 | $scopeList = (new \BO\Zmsentities\Collection\ScopeList())->addEntity($scope); |
49 | $month = $calendar->readMonthListByScopeList($scopeList, 'intern', 0)->getFirst(); |
50 | |
51 | $availabilityList = $this->getAvailabilityList($scope, $startDate, $endDate); |
52 | $processConflictList = \App::$http |
53 | ->readGetResult('/scope/' . $scope->getId() . '/conflict/', [ |
54 | 'startDate' => \App::$now->format('Y-m-d'), |
55 | 'endDate' => $endDate->format('Y-m-d'), |
56 | ]) |
57 | ->getCollection(); |
58 | $processConflictList = $processConflictList ? |
59 | $processConflictList->toConflictListByDay() : |
60 | new \BO\Zmsentities\Collection\ProcessList(); |
61 | |
62 | return \BO\Slim\Render::withHtml( |
63 | $response, |
64 | 'page/availabilityMonth.twig', |
65 | array( |
66 | 'availabilityList' => $availabilityList, |
67 | 'conflicts' => $processConflictList, |
68 | 'calendar' => $calendar, |
69 | 'dayoffList' => $scope->getDayoffList(), |
70 | 'dateTime' => $dateTime, |
71 | 'timestamp' => $dateTime->getTimeStamp(), |
72 | 'month' => $month, |
73 | 'scope' => $scope, |
74 | 'menuActive' => 'owner', |
75 | 'title' => 'Behörden und Standorte - Öffnungszeiten', |
76 | 'workstation' => $workstation, |
77 | 'baseMonthString' => $startDate->format('m'), |
78 | 'baseYearString' => $endDate->format('Y'), |
79 | 'baseMonth_timestamp' => $startDate->getTimeStamp(), |
80 | ) |
81 | ); |
82 | } |
83 | |
84 | protected function getAvailabilityList($scope, $startDate, $endDate) |
85 | { |
86 | try { |
87 | $availabilityList = \App::$http |
88 | ->readGetResult( |
89 | '/scope/' . $scope->getId() . '/availability/', |
90 | [ |
91 | 'startDate' => $startDate->format('Y-m-d'), |
92 | 'endDate' => $endDate->format('Y-m-d') |
93 | ] |
94 | ) |
95 | ->getCollection(); |
96 | } catch (\BO\Zmsclient\Exception $exception) { |
97 | if ($exception->template != 'BO\Zmsapi\Exception\Availability\AvailabilityNotFound') { |
98 | throw $exception; |
99 | } |
100 | $availabilityList = new \BO\Zmsentities\Collection\AvailabilityList(); |
101 | } |
102 | return $availabilityList; |
103 | } |
104 | } |