Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
67.61% |
48 / 71 |
|
66.67% |
10 / 15 |
CRAP | |
0.00% |
0 / 1 |
Authorities | |
67.61% |
48 / 71 |
|
66.67% |
10 / 15 |
109.81 | |
0.00% |
0 / 1 |
__clone | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
addLocation | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
9 | |||
addAuthority | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
hasAuthority | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
readByExtendedService | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
hasLocations | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
hasAppointments | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 | |||
hasLocationId | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
removeLocation | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
removeLocationsWithoutAppointments | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |||
removeEmptyAuthorities | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
removeLocations | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
toListWithOfficePath | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
toListWithAssociatedLocations | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getAuthorityIds | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * @package Zmsdldb |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsdldb\Collection; |
9 | |
10 | /** |
11 | * @SuppressWarnings(TooManyPublicMethods) |
12 | * Methods to apply on this collection |
13 | */ |
14 | class Authorities extends Base |
15 | { |
16 | public function __clone() |
17 | { |
18 | foreach ($this as $key => $authority) { |
19 | $this[$key] = clone $authority; |
20 | } |
21 | } |
22 | |
23 | public function addLocation(\BO\Zmsdldb\Entity\Location $location) |
24 | { |
25 | if ( |
26 | $location->offsetExists('authority') |
27 | && (($location['authority'] instanceof \BO\Zmsdldb\Entity\Base |
28 | && $location['authority']->offsetExists('id') |
29 | && $location['authority']->offsetExists('authority') |
30 | ) || ( |
31 | is_array($location['authority']) |
32 | && array_key_exists('id', $location['authority']) |
33 | && array_key_exists('name', $location['authority']) |
34 | ) |
35 | ) |
36 | && $location['authority']['id'] |
37 | ) { |
38 | $this->addAuthority($location['authority']['id'], $location['authority']['name']); |
39 | $this[$location['authority']['id']]['locations'][$location['id']] = $location; |
40 | } |
41 | return $this; |
42 | } |
43 | |
44 | public function addAuthority($authority_id, $name) |
45 | { |
46 | if (! $this->hasAuthority($authority_id)) { |
47 | $authority = \BO\Zmsdldb\Entity\Authority::create($name); |
48 | $this[$authority_id] = $authority; |
49 | } |
50 | return $this; |
51 | } |
52 | |
53 | public function hasAuthority($authority_id): bool |
54 | { |
55 | return $this->offsetExists($authority_id); |
56 | } |
57 | |
58 | public function readByExtendedService($service) |
59 | { |
60 | foreach ($service['authorities'] as $authority) { |
61 | if (! $this->hasAuthority($authority['id'])) { |
62 | $this->addAuthority($authority['id'], $authority['name']); |
63 | $this[$authority['id']]['webinfo'] = $authority['webinfo']; |
64 | } |
65 | } |
66 | return $this; |
67 | } |
68 | |
69 | /** |
70 | * Check if appointments are available |
71 | * |
72 | * @param String $serviceCsv |
73 | * only check for this serviceCsv |
74 | * @param Bool $external |
75 | * allow external links, default false |
76 | * |
77 | * @return Bool |
78 | */ |
79 | public function hasLocations() |
80 | { |
81 | foreach ($this as $authority) { |
82 | if ($authority->hasLocations()) { |
83 | return true; |
84 | } |
85 | } |
86 | return false; |
87 | } |
88 | |
89 | /** |
90 | * Check if appointments are available |
91 | * |
92 | * @param String $serviceCsv |
93 | * only check for this serviceCsv |
94 | * @param Bool $external |
95 | * allow external links, default false |
96 | * |
97 | * @return Bool |
98 | */ |
99 | public function hasAppointments($serviceCsv = null, $external = false) |
100 | { |
101 | foreach ($this as $authority) { |
102 | if ($authority->hasAppointments($serviceCsv, $external)) { |
103 | return true; |
104 | } |
105 | } |
106 | return false; |
107 | } |
108 | |
109 | /** |
110 | * Check if ea_id location exists |
111 | * |
112 | * @param Int $locationId |
113 | * |
114 | * @return Bool |
115 | */ |
116 | public function hasLocationId($locationId) |
117 | { |
118 | foreach ($this as $authority) { |
119 | if ($authority->hasLocationId($locationId)) { |
120 | return true; |
121 | } |
122 | } |
123 | return false; |
124 | } |
125 | |
126 | /** |
127 | * Remove a location |
128 | * |
129 | * @param Int $locationId |
130 | * |
131 | * @return clone self |
132 | */ |
133 | public function removeLocation($locationId) |
134 | { |
135 | $authorityList = clone $this; |
136 | foreach ($authorityList as $key => $authority) { |
137 | $authorityList[$key] = $authority->removeLocation($locationId); |
138 | } |
139 | return $authorityList; |
140 | } |
141 | |
142 | /** |
143 | * remove locations if no appointment is available |
144 | * |
145 | * @param String $serviceCsv |
146 | * only check for this serviceCsv |
147 | * @param Bool $external |
148 | * allow external links, default false |
149 | * |
150 | * @return self |
151 | */ |
152 | public function removeLocationsWithoutAppointments($serviceCsv = null, $external = false) |
153 | { |
154 | $authorityIterator = $this->getIterator(); |
155 | foreach ($authorityIterator as $key => $authority) { |
156 | if ($authority->hasAppointments($serviceCsv, $external)) { |
157 | $locationIterator = $authority['locations']->getIterator(); |
158 | foreach ($locationIterator as $subkey => $location) { |
159 | if (! $location->hasAppointments($serviceCsv, $external)) { |
160 | $locationIterator->offsetUnset($subkey); |
161 | } |
162 | } |
163 | } else { |
164 | $authorityIterator->offsetUnset($key); |
165 | } |
166 | } |
167 | return $this; |
168 | } |
169 | |
170 | public function removeEmptyAuthorities() |
171 | { |
172 | $authoritylist = new self(); |
173 | foreach ($this as $key => $authority) { |
174 | if ($authority->hasLocations()) { |
175 | $authoritylist[$key] = clone $authority; |
176 | } |
177 | } |
178 | return $authoritylist; |
179 | } |
180 | |
181 | public function removeLocations() |
182 | { |
183 | $authoritylist = clone $this; |
184 | foreach ($authoritylist as $authority) { |
185 | $authority['locations'] = new Locations(); |
186 | } |
187 | return $authoritylist; |
188 | } |
189 | |
190 | public function toListWithOfficePath($officepath) |
191 | { |
192 | $authoritylist = clone $this; |
193 | foreach ($authoritylist as $key => $authority) { |
194 | $authoritylist[$key] = $authority->getLocationListByOfficePath($officepath); |
195 | } |
196 | return $authoritylist->removeEmptyAuthorities(); |
197 | } |
198 | |
199 | /** |
200 | * transform list to authorities with accociated locations |
201 | * |
202 | * @return Collection |
203 | */ |
204 | |
205 | public function toListWithAssociatedLocations($locationlist) |
206 | { |
207 | $authoritylist = $this->removeLocations(); |
208 | foreach ($locationlist as $location) { |
209 | $authoritylist->addLocation($location); |
210 | } |
211 | return $authoritylist; |
212 | } |
213 | |
214 | public function getAuthorityIds() |
215 | { |
216 | $ids = []; |
217 | |
218 | foreach ($this as $key => $authority) { |
219 | $ids[] = $authority['id'] ?? $key; |
220 | } |
221 | return $ids; |
222 | } |
223 | } |