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