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