Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
40 / 40 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| RequestList | |
100.00% |
40 / 40 |
|
100.00% |
6 / 6 |
22 | |
100.00% |
1 / 1 |
| hasRequests | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| toSortedByGroup | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| withCountList | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
| hasAppointmentFromProviderData | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| withUniqueRequests | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| withDataAsObject | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities\Collection; |
| 4 | |
| 5 | use BO\Zmsentities\Helper\Property; |
| 6 | |
| 7 | class RequestList extends Base |
| 8 | { |
| 9 | public const ENTITY_CLASS = '\BO\Zmsentities\Request'; |
| 10 | |
| 11 | public function hasRequests($requestIdCsv) |
| 12 | { |
| 13 | $requestIdCsv = explode(',', $requestIdCsv); |
| 14 | foreach ($requestIdCsv as $requestId) { |
| 15 | if (!in_array($requestId, $this->getIds())) { |
| 16 | return false; |
| 17 | } |
| 18 | } |
| 19 | return true; |
| 20 | } |
| 21 | |
| 22 | public function toSortedByGroup() |
| 23 | { |
| 24 | $list = array(); |
| 25 | foreach ($this as $entity) { |
| 26 | if (! Property::__keyExists($entity->group, $list)) { |
| 27 | $list[$entity->group] = new self(); |
| 28 | } |
| 29 | $list[$entity->group]->addEntity($entity)->sortByName(); |
| 30 | } |
| 31 | ksort($list); |
| 32 | return $list; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Filter the request list and return a new list with appropriate numbers of requests |
| 37 | * |
| 38 | * @param array $countlist - a list with the request.id as number and a count as value |
| 39 | * |
| 40 | * @return RequestList |
| 41 | */ |
| 42 | public function withCountList($countList) |
| 43 | { |
| 44 | $requestList = new self(); |
| 45 | foreach ($countList as $requestId => $counter) { |
| 46 | if (!$this->hasEntity($requestId)) { |
| 47 | throw new \BO\Zmsentities\Exception\RequestListMissing( |
| 48 | "Requested item '$requestId' in RequestList is missing" |
| 49 | ); |
| 50 | } |
| 51 | while ($counter-- > 0) { |
| 52 | $requestList[] = $this->getEntity($requestId); |
| 53 | } |
| 54 | } |
| 55 | return $requestList; |
| 56 | } |
| 57 | |
| 58 | public function hasAppointmentFromProviderData() |
| 59 | { |
| 60 | foreach ($this as $entity) { |
| 61 | if ($entity->hasAppointmentFromProviderData()) { |
| 62 | return true; |
| 63 | } |
| 64 | } |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | public function withUniqueRequests() |
| 69 | { |
| 70 | $requestList = new self(); |
| 71 | foreach ($this as $request) { |
| 72 | if (! $requestList->hasEntity($request->id)) { |
| 73 | $requestList->addEntity(clone $request); |
| 74 | } |
| 75 | } |
| 76 | return $requestList; |
| 77 | } |
| 78 | |
| 79 | public function withDataAsObject() |
| 80 | { |
| 81 | $list = new self(); |
| 82 | foreach ($this as $request) { |
| 83 | if (isset($request['data']) && '{}' != $request->data) { |
| 84 | if (is_string($request->data)) { |
| 85 | $request->data = json_decode($request->data); |
| 86 | } elseif (is_array($request->data)) { |
| 87 | $request->data = json_decode(json_encode($request->data, JSON_FORCE_OBJECT)); |
| 88 | } |
| 89 | } else { |
| 90 | unset($request['data']); |
| 91 | } |
| 92 | $list->addEntity($request); |
| 93 | } |
| 94 | return $list; |
| 95 | } |
| 96 | } |