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