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    #[\Override]
16    public function readResponse(
17        RequestInterface $request,
18        ResponseInterface $response,
19        array $args
20    ) {
21        $scopeIds    = $_GET['scopeIds']    ?? null;
22        $dateFrom    = $_GET['dateFrom']    ?? null;
23        $dateUntil   = $_GET['dateUntil']   ?? null;
24        $updateAfter = $_GET['updateAfter'] ?? null;
25
26        if ($scopeIds === null && $dateFrom === null && $dateUntil === null) {
27            $response->getBody()->write(json_encode([]));
28            return $response
29                ->withHeader('Content-Type', 'application/json');
30        }
31
32        $missing = [];
33        if (!$scopeIds) {
34            $missing[] = 'scopeIds';
35        }
36        if (!$dateFrom) {
37            $missing[] = 'dateFrom';
38        }
39        if (!$dateUntil) {
40            $missing[] = 'dateUntil';
41        }
42        if (!empty($missing)) {
43            $error = [
44                'error'   => true,
45                'message' => 'Missing required parameters: ' . implode(', ', $missing),
46            ];
47            $response->getBody()->write(json_encode($error));
48            return $response
49                ->withStatus(400)
50                ->withHeader('Content-Type', 'application/json');
51        }
52
53        $params = [
54            'scopeIds'  => $scopeIds,
55            'dateFrom'  => $dateFrom,
56            'dateUntil' => $dateUntil,
57        ];
58        if ($updateAfter) {
59            $params['updateAfter'] = $updateAfter;
60        }
61
62        $apiResult = \App::$http->readGetResult('/overallcalendar/', $params);
63        $rawBody   = (string)$apiResult->getResponse()->getBody();
64
65        $response->getBody()->write($rawBody);
66        return $response
67            ->withHeader('Content-Type', 'application/json');
68    }
69}