Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
97.22% covered (success)
97.22%
35 / 36
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
OverallCalendarLoadData
97.22% covered (success)
97.22%
35 / 36
0.00% covered (danger)
0.00%
0 / 1
9
0.00% covered (danger)
0.00%
0 / 1
 readResponse
97.22% covered (success)
97.22%
35 / 36
0.00% covered (danger)
0.00%
0 / 1
9
1<?php
2
3namespace BO\Zmsadmin;
4
5use BO\Mellon\Validator;
6use BO\Zmsdb\Request;
7use BO\Zmsentities\Collection\RequestList;
8use BO\Zmsentities\Department as DepartmentEntity;
9use BO\Zmsentities\Collection\DepartmentList;
10use Psr\Http\Message\RequestInterface;
11use Psr\Http\Message\ResponseInterface;
12
13class OverallCalendarLoadData extends BaseController
14{
15    public function readResponse(
16        RequestInterface $request,
17        ResponseInterface $response,
18        array $args
19    ) {
20        $scopeIds    = $_GET['scopeIds']    ?? null;
21        $dateFrom    = $_GET['dateFrom']    ?? null;
22        $dateUntil   = $_GET['dateUntil']   ?? null;
23        $updateAfter = $_GET['updateAfter'] ?? null;
24
25        if ($scopeIds === null && $dateFrom === null && $dateUntil === null) {
26            $response->getBody()->write(json_encode([]));
27            return $response
28                ->withHeader('Content-Type', 'application/json');
29        }
30
31        $missing = [];
32        if (!$scopeIds) {
33            $missing[] = 'scopeIds';
34        }
35        if (!$dateFrom) {
36            $missing[] = 'dateFrom';
37        }
38        if (!$dateUntil) {
39            $missing[] = 'dateUntil';
40        }
41        if (!empty($missing)) {
42            $error = [
43                'error'   => true,
44                'message' => 'Missing required parameters: ' . implode(', ', $missing),
45            ];
46            $response->getBody()->write(json_encode($error));
47            return $response
48                ->withStatus(400)
49                ->withHeader('Content-Type', 'application/json');
50        }
51
52        $params = [
53            'scopeIds'  => $scopeIds,
54            'dateFrom'  => $dateFrom,
55            'dateUntil' => $dateUntil,
56        ];
57        if ($updateAfter) {
58            $params['updateAfter'] = $updateAfter;
59        }
60
61        $apiResult = \App::$http->readGetResult('/overallcalendar/', $params);
62        $rawBody   = (string)$apiResult->getResponse()->getBody();
63
64        $response->getBody()->write($rawBody);
65        return $response
66            ->withHeader('Content-Type', 'application/json');
67    }
68}