Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.07% covered (warning)
62.07%
18 / 29
50.00% covered (danger)
50.00%
3 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Service
62.07% covered (warning)
62.07%
18 / 29
50.00% covered (danger)
50.00%
3 / 6
29.97
0.00% covered (danger)
0.00%
0 / 1
 containsLocation
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 hasLocation
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 hasAppointments
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
6
 isResponsibleForAll
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isLocale
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLocations
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
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 Service extends Base
15{
16    /**
17     * Checks, if it contains _all_ locations
18     * Necessary, cause service A might be in location C but not location D,
19     * but service B is in location C and D. On partial check, service a
20     * would be valid for location D.
21     *
22     * @return Bool
23     */
24    public function containsLocation($location_csv)
25    {
26        $service = $this->getArrayCopy();
27        $locationcompare = explode(',', $location_csv);
28        $locationsfound = array();
29        foreach ($service['locations'] as $locationinfo) {
30            $location_id = $locationinfo['location'];
31            if (in_array($location_id, $locationcompare)) {
32                $locationsfound[$location_id] = $location_id;
33            }
34        }
35        return count($locationcompare) == count($locationsfound);
36    }
37
38    public function hasLocation($location_csv)
39    {
40        $service = $this->getArrayCopy();
41        $locationcompare = explode(',', $location_csv);
42        foreach ($service['locations'] as $locationinfo) {
43            if (in_array($locationinfo['location'], $locationcompare)) {
44                return true;
45            }
46        }
47        return false;
48    }
49
50    public function hasAppointments($external = false)
51    {
52        foreach ($this['locations'] as $location) {
53            if (isset($location['appointment']['allowed'])) {
54                if ($location['appointment']['allowed']) {
55                    if ($external) {
56                        return true;
57                    } elseif ($location['appointment']['external'] === false) {
58                        return true;
59                    }
60                }
61            }
62        }
63        return false;
64    }
65
66
67    public function isResponsibleForAll()
68    {
69        return $this['responsibility_all'];
70    }
71
72    /**
73     * @return Bool
74     */
75    public function isLocale($locale)
76    {
77        $service = $this->getArrayCopy();
78        return $service['meta']['locale'] == $locale;
79    }
80
81    public function getLocations()
82    {
83        $locations = [];
84        foreach ($this['locations'] as $location) {
85            $locations[$location['location']] = $location;
86        }
87        return $locations;
88    }
89}