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