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