Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
47.76% |
32 / 67 |
|
42.86% |
3 / 7 |
CRAP | |
0.00% |
0 / 1 |
| Location | |
47.76% |
32 / 67 |
|
42.86% |
3 / 7 |
122.37 | |
0.00% |
0 / 1 |
| containsService | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
6.04 | |||
| isLocale | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getServiceInfo | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| getServiceInfoList | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
| hasAppointments | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
9 | |||
| getAppointmentForService | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getGeoJson | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package Zmsdldb |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 6 | **/ |
| 7 | |
| 8 | namespace BO\Zmsdldb\Entity; |
| 9 | |
| 10 | /** |
| 11 | * Helper for service export |
| 12 | * |
| 13 | */ |
| 14 | class Location extends Base |
| 15 | { |
| 16 | /** |
| 17 | * @return Bool |
| 18 | */ |
| 19 | public function containsService(mixed $service_csv) |
| 20 | { |
| 21 | if (!is_string($service_csv) && !is_int($service_csv) && !is_float($service_csv)) { |
| 22 | return false; |
| 23 | } |
| 24 | $location = $this->getArrayCopy(); |
| 25 | $servicecompare = explode(',', (string) $service_csv); |
| 26 | $servicecount = array(); |
| 27 | foreach ($location['services'] as $serviceinfo) { |
| 28 | $service_id = $serviceinfo['service']; |
| 29 | if (in_array($service_id, $servicecompare)) { |
| 30 | $servicecount[$service_id] = $service_id; |
| 31 | } |
| 32 | } |
| 33 | return count($servicecount) == count($servicecompare); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @return Bool |
| 38 | */ |
| 39 | public function isLocale(string $locale) |
| 40 | { |
| 41 | $location = $this->getArrayCopy(); |
| 42 | return $location['meta']['locale'] == $locale; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param int $service_id |
| 47 | * |
| 48 | * @return FALSE or Array |
| 49 | * @psalm-api |
| 50 | */ |
| 51 | public function getServiceInfo(mixed $service_id) |
| 52 | { |
| 53 | foreach ($this['services'] as $service) { |
| 54 | if ($service['service'] == $service_id) { |
| 55 | return $service; |
| 56 | } |
| 57 | } |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @param string|int|float|null $serviceCsv only check for this serviceCsv |
| 63 | * |
| 64 | * @return Array |
| 65 | */ |
| 66 | public function getServiceInfoList($serviceCsv = null) |
| 67 | { |
| 68 | if (null === $serviceCsv) { |
| 69 | return $this['services']; |
| 70 | } |
| 71 | $location = $this->getArrayCopy(); |
| 72 | $servicecompare = explode(',', (string) $serviceCsv); |
| 73 | |
| 74 | $serviceList = array(); |
| 75 | foreach ($location['services'] as $serviceinfo) { |
| 76 | $service_id = $serviceinfo['service']; |
| 77 | if (in_array($service_id, $servicecompare)) { |
| 78 | $serviceList[$service_id] = $serviceinfo; |
| 79 | } |
| 80 | } |
| 81 | return $serviceList; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Check if appointments are available |
| 86 | * |
| 87 | * @param string|int|float|null $serviceCsv only check for this serviceCsv |
| 88 | * @param Bool $external allow external links, default false |
| 89 | * |
| 90 | * @return Bool |
| 91 | * @psalm-api |
| 92 | */ |
| 93 | public function hasAppointments($serviceCsv = null, $external = false) |
| 94 | { |
| 95 | $serviceList = $this->getServiceInfoList($serviceCsv); |
| 96 | $servicecount = array(); |
| 97 | foreach ($serviceList as $serviceinfo) { |
| 98 | if ( |
| 99 | true === static::hasValidOffset($serviceinfo, 'appointment') |
| 100 | && $serviceinfo['appointment']['allowed'] |
| 101 | && ($external || $serviceinfo['appointment']['external'] === false) |
| 102 | ) { |
| 103 | $service_id = $serviceinfo['service']; |
| 104 | $servicecount[$service_id] = $service_id; |
| 105 | } |
| 106 | } |
| 107 | if (null === $serviceCsv) { |
| 108 | return count($servicecount) ? true : false; |
| 109 | } else { |
| 110 | return count($serviceList) > 0 && count($servicecount) == count($serviceList); |
| 111 | } |
| 112 | } |
| 113 | /** |
| 114 | * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
| 115 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 116 | * @psalm-api |
| 117 | */ |
| 118 | public function getAppointmentForService(mixed $service_id, bool $external = false): mixed |
| 119 | { |
| 120 | $serviceList = $this->getServiceInfoList($service_id); |
| 121 | |
| 122 | if (!empty($serviceList)) { |
| 123 | $service = end($serviceList); |
| 124 | return $service['appointment']; |
| 125 | } |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * return geoJson |
| 131 | * |
| 132 | * |
| 133 | * @return array |
| 134 | */ |
| 135 | public function getGeoJson() |
| 136 | { |
| 137 | return [ |
| 138 | 'type' => 'Feature', |
| 139 | 'id' => $this['id'], |
| 140 | 'properties' => [ |
| 141 | 'name' => $this['name'], |
| 142 | 'description' => '<div>' |
| 143 | . ($this['authority']['name'] ?? $this['authority_name'] ?? '') |
| 144 | . '</div><p>' |
| 145 | . $this['address']['street'] |
| 146 | . ' ' |
| 147 | . $this['address']['house_number'] |
| 148 | . ', ' |
| 149 | . $this['address']['postal_code'] |
| 150 | . ' ' |
| 151 | . $this['address']['city'] |
| 152 | . '<br /><a href="' |
| 153 | . ($this['meta']['url'] ?? $this['url']) |
| 154 | . '" class="gmap-marker-link">Zum Standort</a>', |
| 155 | 'categoryIdentifier' => $this['category']['identifier'], |
| 156 | ], |
| 157 | 'geometry' => [ |
| 158 | 'type' => 'Point', |
| 159 | 'coordinates' => [$this['geo']['lon'], $this['geo']['lat']], |
| 160 | ] |
| 161 | ]; |
| 162 | } |
| 163 | } |