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 | * @return bool |
| 73 | */ |
| 74 | public function hasLocations() |
| 75 | { |
| 76 | foreach ($this as $authority) { |
| 77 | if ($authority->hasLocations()) { |
| 78 | return true; |
| 79 | } |
| 80 | } |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Check if appointments are available |
| 86 | * |
| 87 | * @param String $serviceCsv |
| 88 | * only check for this serviceCsv |
| 89 | * @param Bool $external |
| 90 | * allow external links, default false |
| 91 | * |
| 92 | * @return Bool |
| 93 | */ |
| 94 | public function hasAppointments($serviceCsv = null, $external = false) |
| 95 | { |
| 96 | foreach ($this as $authority) { |
| 97 | if ($authority->hasAppointments($serviceCsv, $external)) { |
| 98 | return true; |
| 99 | } |
| 100 | } |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Check if ea_id location exists |
| 106 | * |
| 107 | * @param Int $locationId |
| 108 | * |
| 109 | * @return Bool |
| 110 | */ |
| 111 | public function hasLocationId($locationId) |
| 112 | { |
| 113 | foreach ($this as $authority) { |
| 114 | if ($authority->hasLocationId($locationId)) { |
| 115 | return true; |
| 116 | } |
| 117 | } |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Remove a location |
| 123 | * |
| 124 | * @param Int $locationId |
| 125 | * |
| 126 | * @return self |
| 127 | */ |
| 128 | public function removeLocation($locationId) |
| 129 | { |
| 130 | $authorityList = clone $this; |
| 131 | foreach ($authorityList as $key => $authority) { |
| 132 | $authorityList[$key] = $authority->removeLocation($locationId); |
| 133 | } |
| 134 | return $authorityList; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * remove locations if no appointment is available |
| 139 | * |
| 140 | * @param String $serviceCsv |
| 141 | * only check for this serviceCsv |
| 142 | * @param Bool $external |
| 143 | * allow external links, default false |
| 144 | * |
| 145 | * @return self |
| 146 | */ |
| 147 | public function removeLocationsWithoutAppointments($serviceCsv = null, $external = false) |
| 148 | { |
| 149 | $authorityIterator = $this->getIterator(); |
| 150 | foreach ($authorityIterator as $key => $authority) { |
| 151 | if ($authority->hasAppointments($serviceCsv, $external)) { |
| 152 | $locationIterator = $authority['locations']->getIterator(); |
| 153 | foreach ($locationIterator as $subkey => $location) { |
| 154 | if (! $location->hasAppointments($serviceCsv, $external)) { |
| 155 | $locationIterator->offsetUnset($subkey); |
| 156 | } |
| 157 | } |
| 158 | } else { |
| 159 | $authorityIterator->offsetUnset($key); |
| 160 | } |
| 161 | } |
| 162 | return $this; |
| 163 | } |
| 164 | |
| 165 | public function removeEmptyAuthorities() |
| 166 | { |
| 167 | $authoritylist = new self(); |
| 168 | foreach ($this as $key => $authority) { |
| 169 | if ($authority->hasLocations()) { |
| 170 | $authoritylist[$key] = clone $authority; |
| 171 | } |
| 172 | } |
| 173 | return $authoritylist; |
| 174 | } |
| 175 | |
| 176 | public function removeLocations() |
| 177 | { |
| 178 | $authoritylist = clone $this; |
| 179 | foreach ($authoritylist as $authority) { |
| 180 | $authority['locations'] = new Locations(); |
| 181 | } |
| 182 | return $authoritylist; |
| 183 | } |
| 184 | |
| 185 | public function toListWithOfficePath($officepath) |
| 186 | { |
| 187 | $authoritylist = clone $this; |
| 188 | foreach ($authoritylist as $key => $authority) { |
| 189 | $authoritylist[$key] = $authority->getLocationListByOfficePath($officepath); |
| 190 | } |
| 191 | return $authoritylist->removeEmptyAuthorities(); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * transform list to authorities with accociated locations |
| 196 | * |
| 197 | * @return self |
| 198 | */ |
| 199 | |
| 200 | public function toListWithAssociatedLocations($locationlist) |
| 201 | { |
| 202 | $authoritylist = $this->removeLocations(); |
| 203 | foreach ($locationlist as $location) { |
| 204 | $authoritylist->addLocation($location); |
| 205 | } |
| 206 | return $authoritylist; |
| 207 | } |
| 208 | |
| 209 | public function getAuthorityIds() |
| 210 | { |
| 211 | $ids = []; |
| 212 | |
| 213 | foreach ($this as $key => $authority) { |
| 214 | $ids[] = $authority['id'] ?? $key; |
| 215 | } |
| 216 | return $ids; |
| 217 | } |
| 218 | } |