Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
ProcessFree | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
7 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
7 |
1 | <?php |
2 | |
3 | /** |
4 | * @package ZMS API |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsapi; |
9 | |
10 | use BO\Slim\Render; |
11 | use BO\Mellon\Validator; |
12 | use BO\Zmsdb\ProcessStatusFree as Query; |
13 | |
14 | class ProcessFree extends BaseController |
15 | { |
16 | /** |
17 | * @SuppressWarnings(Param) |
18 | * @return String |
19 | */ |
20 | public function readResponse( |
21 | \Psr\Http\Message\RequestInterface $request, |
22 | \Psr\Http\Message\ResponseInterface $response, |
23 | array $args |
24 | ) { |
25 | $slotsRequired = Validator::param('slotsRequired')->isNumber()->getValue(); |
26 | $groupData = Validator::param('groupData')->isNumber()->getValue(); |
27 | $slotType = Validator::param('slotType')->isString()->getValue(); |
28 | $keepLessData = Validator::param('keepLessData')->isArray()->setDefault([])->getValue(); |
29 | if ($slotType || $slotsRequired) { |
30 | (new Helper\User($request))->checkRights(); |
31 | } else { |
32 | $slotsRequired = 0; |
33 | $slotType = 'public'; |
34 | } |
35 | |
36 | $calendarData = Validator::input()->isJson()->assertValid()->getValue(); |
37 | $calendar = new \BO\Zmsentities\Calendar($calendarData); |
38 | $message = Response\Message::create($request); |
39 | $processList = (new Query()) |
40 | ->readFreeProcesses($calendar, \App::getNow(), $slotType, $slotsRequired, $groupData ? true : false) |
41 | ->withLessData($keepLessData) |
42 | ; |
43 | if ($groupData && count($processList) >= $groupData) { |
44 | $processList = $processList->withUniqueScope(true); |
45 | } elseif ($groupData) { |
46 | $processList = $processList->withUniqueScope(false); |
47 | } |
48 | $message->data = $processList; |
49 | |
50 | $response = Render::withLastModified($response, time(), '0'); |
51 | return Render::withJson($response, $message, 200); |
52 | } |
53 | } |