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): static |
| 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): static |
| 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 | /** |
| 59 | * @psalm-api |
| 60 | */ |
| 61 | public function readByExtendedService($service): static |
| 62 | { |
| 63 | foreach ($service['authorities'] as $authority) { |
| 64 | if (! $this->hasAuthority($authority['id'])) { |
| 65 | $this->addAuthority($authority['id'], $authority['name']); |
| 66 | $this[$authority['id']]['webinfo'] = $authority['webinfo']; |
| 67 | } |
| 68 | } |
| 69 | return $this; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Check if appointments are available |
| 74 | * |
| 75 | * @return bool |
| 76 | * @psalm-api |
| 77 | */ |
| 78 | public function hasLocations() |
| 79 | { |
| 80 | foreach ($this as $authority) { |
| 81 | if ($authority->hasLocations()) { |
| 82 | return true; |
| 83 | } |
| 84 | } |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Check if appointments are available |
| 90 | * |
| 91 | * @param String $serviceCsv |
| 92 | * only check for this serviceCsv |
| 93 | * @param Bool $external |
| 94 | * allow external links, default false |
| 95 | * |
| 96 | * @return Bool |
| 97 | * @psalm-api |
| 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 | * @psalm-api |
| 116 | */ |
| 117 | public function hasLocationId($locationId) |
| 118 | { |
| 119 | foreach ($this as $authority) { |
| 120 | if ($authority->hasLocationId($locationId)) { |
| 121 | return true; |
| 122 | } |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Remove a location |
| 129 | * |
| 130 | * @param Int $locationId |
| 131 | * |
| 132 | * @return self |
| 133 | * @psalm-api |
| 134 | */ |
| 135 | public function removeLocation($locationId) |
| 136 | { |
| 137 | $authorityList = clone $this; |
| 138 | foreach ($authorityList as $key => $authority) { |
| 139 | $authorityList[$key] = $authority->removeLocation($locationId); |
| 140 | } |
| 141 | return $authorityList; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * remove locations if no appointment is available |
| 146 | * |
| 147 | * @param String $serviceCsv |
| 148 | * only check for this serviceCsv |
| 149 | * @param Bool $external |
| 150 | * allow external links, default false |
| 151 | * |
| 152 | * @return self |
| 153 | * @psalm-api |
| 154 | */ |
| 155 | public function removeLocationsWithoutAppointments($serviceCsv = null, $external = false) |
| 156 | { |
| 157 | $authorityIterator = $this->getIterator(); |
| 158 | foreach ($authorityIterator as $key => $authority) { |
| 159 | if ($authority->hasAppointments($serviceCsv, $external)) { |
| 160 | $locationIterator = $authority['locations']->getIterator(); |
| 161 | foreach ($locationIterator as $subkey => $location) { |
| 162 | if (! $location->hasAppointments($serviceCsv, $external)) { |
| 163 | $locationIterator->offsetUnset($subkey); |
| 164 | } |
| 165 | } |
| 166 | } else { |
| 167 | $authorityIterator->offsetUnset($key); |
| 168 | } |
| 169 | } |
| 170 | return $this; |
| 171 | } |
| 172 | |
| 173 | public function removeEmptyAuthorities(): self |
| 174 | { |
| 175 | $authoritylist = new self(); |
| 176 | foreach ($this as $key => $authority) { |
| 177 | if ($authority->hasLocations()) { |
| 178 | $authoritylist[$key] = clone $authority; |
| 179 | } |
| 180 | } |
| 181 | return $authoritylist; |
| 182 | } |
| 183 | |
| 184 | public function removeLocations(): static |
| 185 | { |
| 186 | $authoritylist = clone $this; |
| 187 | foreach ($authoritylist as $authority) { |
| 188 | $authority['locations'] = new Locations(); |
| 189 | } |
| 190 | return $authoritylist; |
| 191 | } |
| 192 | |
| 193 | public function toListWithOfficePath($officepath) |
| 194 | { |
| 195 | $authoritylist = clone $this; |
| 196 | foreach ($authoritylist as $key => $authority) { |
| 197 | $authoritylist[$key] = $authority->getLocationListByOfficePath($officepath); |
| 198 | } |
| 199 | return $authoritylist->removeEmptyAuthorities(); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * transform list to authorities with accociated locations |
| 204 | * |
| 205 | * @return self |
| 206 | * @psalm-api |
| 207 | */ |
| 208 | |
| 209 | public function toListWithAssociatedLocations($locationlist) |
| 210 | { |
| 211 | $authoritylist = $this->removeLocations(); |
| 212 | foreach ($locationlist as $location) { |
| 213 | $authoritylist->addLocation($location); |
| 214 | } |
| 215 | return $authoritylist; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * @psalm-api |
| 220 | * |
| 221 | * @return (int|mixed|string)[] |
| 222 | * |
| 223 | */ |
| 224 | public function getAuthorityIds(): array |
| 225 | { |
| 226 | $ids = []; |
| 227 | |
| 228 | foreach ($this as $key => $authority) { |
| 229 | $ids[] = $authority['id'] ?? $key; |
| 230 | } |
| 231 | return $ids; |
| 232 | } |
| 233 | } |