Lines
54.25%
51 / 94
Methods
61.11%
11 / 18
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| [BO\Zmsdldb\Collection\Authorities] __clone | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsdldb\Collection\Authorities] addLocation | 100.00% | 15 / 15 | 100.00% | 1 / 1 | 9 | ||
| [BO\Zmsdldb\Collection\Authorities] addAuthority | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsdldb\Collection\Authorities] hasAuthority | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [BO\Zmsdldb\Collection\Authorities] readByExtendedService | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 12 | ||
| [BO\Zmsdldb\Collection\Authorities] hasLocations | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 12 | ||
| [BO\Zmsdldb\Collection\Authorities] hasAppointments | 75.00% | 3 / 4 | 0.00% | 0 / 1 | 3.14 | ||
| [BO\Zmsdldb\Collection\Authorities] hasLocationId | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 3 | ||
| [BO\Zmsdldb\Collection\Authorities] removeLocation | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsdldb\Collection\Authorities] removeLocationsWithoutAppointments | 0.00% | 0 / 12 | 0.00% | 0 / 1 | 56 | ||
| [BO\Zmsdldb\Collection\Authorities] removeEmptyAuthorities | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | ||
| [BO\Zmsdldb\Collection\Authorities] removeLocations | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsdldb\Collection\Authorities] toListWithOfficePath | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsdldb\Collection\Authorities] toListWithAssociatedLocations | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsdldb\Collection\Authorities] getAuthorityIds | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | ||
| [BO\Zmsdldb\Collection\Base] offsetSet | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [BO\Zmsdldb\Collection\Base] sortByName | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 2 | ||
| [BO\Zmsdldb\Collection\Base] sortWithCollator | 0.00% | 0 / 12 | 0.00% | 0 / 1 | 6 | ||
| 15 | class Authorities extends Base | |
| 16 | { | |
| 17 | } |
Inherited from BO\Zmsdldb\Collection\Authorities
| 18 | public function __clone() | |
| 19 | { | |
| 20 | foreach ($this as $key => $authority) { | |
| 21 | $this[$key] = clone $authority; | |
| 22 | } | |
| 23 | } |
| 25 | public function addLocation(\BO\Zmsdldb\Entity\Location $location): static | |
| 26 | { | |
| 27 | if ( | |
| 28 | $location->offsetExists('authority') | |
| 29 | && (($location['authority'] instanceof \BO\Zmsdldb\Entity\Base | |
| 30 | && $location['authority']->offsetExists('id') | |
| 31 | && $location['authority']->offsetExists('authority') | |
| 32 | ) || ( | |
| 33 | is_array($location['authority']) | |
| 34 | && array_key_exists('id', $location['authority']) | |
| 35 | && array_key_exists('name', $location['authority']) | |
| 36 | ) | |
| 37 | ) | |
| 38 | && $location['authority']['id'] | |
| 39 | ) { | |
| 40 | $authorityId = $location['authority']['id']; | |
| 41 | $this->addAuthority($authorityId, $location['authority']['name']); | |
| 42 | $authority = $this[$authorityId]; | |
| 43 | $authority['locations'][$location['id']] = $location; | |
| 44 | } | |
| 45 | return $this; | |
| 46 | } |
| 48 | public function addAuthority(mixed $authority_id, mixed $name): static | |
| 49 | { | |
| 50 | if (! $this->hasAuthority($authority_id)) { | |
| 51 | $authority = \BO\Zmsdldb\Entity\Authority::create($name); | |
| 52 | $this[$authority_id] = $authority; | |
| 53 | } | |
| 54 | return $this; | |
| 55 | } |
| 57 | public function hasAuthority(mixed $authority_id): bool | |
| 58 | { | |
| 59 | return $this->offsetExists($authority_id); | |
| 60 | } |
| 65 | public function readByExtendedService(mixed $service): static | |
| 66 | { | |
| 67 | foreach ($service['authorities'] as $authority) { | |
| 68 | if (! $this->hasAuthority($authority['id'])) { | |
| 69 | $this->addAuthority($authority['id'], $authority['name']); | |
| 70 | $this[$authority['id']]['webinfo'] = $authority['webinfo']; | |
| 71 | } | |
| 72 | } | |
| 73 | return $this; | |
| 74 | } |
| 82 | public function hasLocations() | |
| 83 | { | |
| 84 | foreach ($this as $authority) { | |
| 85 | if ($authority->hasLocations()) { | |
| 86 | return true; | |
| 87 | } | |
| 88 | } | |
| 89 | return false; | |
| 90 | } |
| 103 | public function hasAppointments($serviceCsv = null, $external = false) | |
| 104 | { | |
| 105 | foreach ($this as $authority) { | |
| 106 | if ($authority->hasAppointments($serviceCsv, $external)) { | |
| 107 | return true; | |
| 108 | } | |
| 109 | } | |
| 110 | return false; | |
| 111 | } |
| 121 | public function hasLocationId($locationId) | |
| 122 | { | |
| 123 | foreach ($this as $authority) { | |
| 124 | if ($authority->hasLocationId($locationId)) { | |
| 125 | return true; | |
| 126 | } | |
| 127 | } | |
| 128 | return false; | |
| 129 | } |
| 139 | public function removeLocation($locationId) | |
| 140 | { | |
| 141 | $authorityList = clone $this; | |
| 142 | foreach ($authorityList as $key => $authority) { | |
| 143 | $authorityList[$key] = $authority->removeLocation($locationId); | |
| 144 | } | |
| 145 | return $authorityList; | |
| 146 | } |
| 159 | public function removeLocationsWithoutAppointments($serviceCsv = null, $external = false) | |
| 160 | { | |
| 161 | $authorityIterator = $this->getIterator(); | |
| 162 | foreach ($authorityIterator as $key => $authority) { | |
| 163 | if (!$authority instanceof \BO\Zmsdldb\Entity\Authority) { | |
| 164 | continue; | |
| 165 | } | |
| 166 | if ($authority->hasAppointments($serviceCsv, $external)) { | |
| 167 | $locationIterator = $authority['locations']->getIterator(); | |
| 168 | foreach ($locationIterator as $subkey => $location) { | |
| 169 | if (! $location->hasAppointments($serviceCsv, $external)) { | |
| 170 | $locationIterator->offsetUnset($subkey); | |
| 171 | } | |
| 172 | } | |
| 173 | } else { | |
| 174 | if ($key !== null) { | |
| 175 | $authorityIterator->offsetUnset($key); | |
| 176 | } | |
| 177 | } | |
| 178 | } | |
| 179 | return $this; | |
| 180 | } |
| 182 | public function removeEmptyAuthorities(): self | |
| 183 | { | |
| 184 | $authoritylist = new self(); | |
| 185 | foreach ($this as $key => $authority) { | |
| 186 | if ($authority->hasLocations()) { | |
| 187 | $authoritylist[$key] = clone $authority; | |
| 188 | } | |
| 189 | } | |
| 190 | return $authoritylist; | |
| 191 | } |
| 193 | public function removeLocations(): static | |
| 194 | { | |
| 195 | $authoritylist = clone $this; | |
| 196 | foreach ($authoritylist as $authority) { | |
| 197 | $authority['locations'] = new Locations(); | |
| 198 | } | |
| 199 | return $authoritylist; | |
| 200 | } |
| 202 | public function toListWithOfficePath(mixed $officepath): \BO\Zmsdldb\Collection\Authorities | |
| 203 | { | |
| 204 | $authoritylist = clone $this; | |
| 205 | foreach ($authoritylist as $key => $authority) { | |
| 206 | $authoritylist[$key] = $authority->getLocationListByOfficePath($officepath); | |
| 207 | } | |
| 208 | return $authoritylist->removeEmptyAuthorities(); | |
| 209 | } |
| 218 | public function toListWithAssociatedLocations(mixed $locationlist) | |
| 219 | { | |
| 220 | $authoritylist = $this->removeLocations(); | |
| 221 | foreach ($locationlist as $location) { | |
| 222 | $authoritylist->addLocation($location); | |
| 223 | } | |
| 224 | return $authoritylist; | |
| 225 | } |
| 233 | public function getAuthorityIds(): array | |
| 234 | { | |
| 235 | $ids = []; | |
| 236 | ||
| 237 | foreach ($this as $key => $authority) { | |
| 238 | $ids[] = $authority['id'] ?? $key; | |
| 239 | } | |
| 240 | return $ids; | |
| 241 | } |
Inherited from BO\Zmsdldb\Collection\Base
| 19 | public function offsetSet(mixed $key, mixed $value): void | |
| 20 | { | |
| 21 | parent::offsetSet($key, $value); | |
| 22 | } |
| 24 | public function sortByName(): static | |
| 25 | { | |
| 26 | $itemList = clone $this; | |
| 27 | $itemList->uasort(function ($a, $b) { | |
| 28 | return strcmp(Sorter::toSortableString($a->getName()), Sorter::toSortableString($b->getName())); | |
| 29 | }); | |
| 30 | return $itemList; | |
| 31 | } |
| 36 | public function sortWithCollator(string $field = 'name', string $locale = 'de'): static | |
| 37 | { | |
| 38 | $collator = collator_create($locale); | |
| 39 | if ($collator === null) { | |
| 40 | throw new \RuntimeException('Could not create collator for locale ' . $locale); | |
| 41 | } | |
| 42 | $collator->setStrength(\Collator::QUATERNARY); | |
| 43 | $collator->setAttribute(\Collator::QUATERNARY, \Collator::ON); | |
| 44 | $collator->setAttribute(\Collator::CASE_FIRST, \Collator::ON); | |
| 45 | $collator->setAttribute(\Collator::NUMERIC_COLLATION, \Collator::ON); | |
| 46 | ||
| 47 | $itemList = clone $this; | |
| 48 | $itemList->uasort(function ($itemA, $itemB) use ($collator, $field) { | |
| 49 | return collator_compare($collator, $itemA[$field], $itemB[$field]); | |
| 50 | }); | |
| 51 | return $itemList; | |
| 52 | } |