Lines
97.22%
35 / 36
Functions and Methods
0.00%
0 / 1
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| OverallCalendarClosureLoadData | 97.22% | 35 / 36 | 0.00% | 0 / 1 | 10 | 0.00% | 0 / 1 | |||
| readResponse | 97.22% | 35 / 36 | 0.00% | 0 / 1 | 10 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsadmin; | |
| 4 | ||
| 5 | use Psr\Http\Message\RequestInterface; | |
| 6 | use Psr\Http\Message\ResponseInterface; | |
| 7 | ||
| 8 | class OverallCalendarClosureLoadData extends BaseController | |
| 9 | { | |
| 10 | /** | |
| 11 | * @return ResponseInterface | |
| 12 | */ | |
| 13 | #[\Override] | |
| 14 | public function readResponse( | |
| 15 | RequestInterface $request, | |
| 16 | ResponseInterface $response, | |
| 17 | array $args | |
| 18 | ) { | |
| 19 | $scopeIds = $_GET['scopeIds'] ?? null; | |
| 20 | $dateFrom = $_GET['dateFrom'] ?? null; | |
| 21 | $dateUntil = $_GET['dateUntil'] ?? null; | |
| 22 | ||
| 23 | if ($scopeIds === null && $dateFrom === null && $dateUntil === null) { | |
| 24 | $response->getBody()->write(json_encode([])); | |
| 25 | return $response->withHeader('Content-Type', 'application/json'); | |
| 26 | } | |
| 27 | ||
| 28 | if (!$scopeIds || !$dateFrom || !$dateUntil) { | |
| 29 | $error = [ | |
| 30 | 'error' => true, | |
| 31 | 'message' => 'Missing required parameters: scopeIds, dateFrom, dateUntil', | |
| 32 | ]; | |
| 33 | $response->getBody()->write(json_encode($error)); | |
| 34 | return $response | |
| 35 | ->withStatus(400) | |
| 36 | ->withHeader('Content-Type', 'application/json'); | |
| 37 | } | |
| 38 | ||
| 39 | $params = [ | |
| 40 | 'scopeIds' => $scopeIds, | |
| 41 | 'dateFrom' => $dateFrom, | |
| 42 | 'dateUntil' => $dateUntil, | |
| 43 | ]; | |
| 44 | ||
| 45 | $apiResult = \App::$http->readGetResult('/closure/', $params); | |
| 46 | $apiResponse = $apiResult->getResponse(); | |
| 47 | ||
| 48 | $lastMod = $apiResponse->getHeaderLine('Last-Modified'); | |
| 49 | if ($lastMod !== '') { | |
| 50 | $response = $response->withHeader('Last-Modified', $lastMod); | |
| 51 | } | |
| 52 | ||
| 53 | $contentType = $apiResponse->getHeaderLine('Content-Type'); | |
| 54 | $response = $response->withHeader( | |
| 55 | 'Content-Type', | |
| 56 | $contentType !== '' ? $contentType : 'application/json' | |
| 57 | ); | |
| 58 | ||
| 59 | $bodyStream = $apiResponse->getBody(); | |
| 60 | if ($bodyStream->isSeekable()) { | |
| 61 | $bodyStream->rewind(); | |
| 62 | } | |
| 63 | $rawBody = (string) $bodyStream; | |
| 64 | ||
| 65 | $response->getBody()->write($rawBody); | |
| 66 | ||
| 67 | return $response->withStatus($apiResponse->getStatusCode()); | |
| 68 | } | |
| 69 | } |