Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.10% covered (success)
93.10%
27 / 29
80.00% covered (warning)
80.00%
8 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
Authority
93.10% covered (success)
93.10%
27 / 29
80.00% covered (warning)
80.00%
8 / 10
19.12
0.00% covered (danger)
0.00%
0 / 1
 __clone
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 create
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 hasAppointments
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 hasLocations
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getLocationListByOfficePath
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 hasLocationId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 removeLocation
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 isInServiceList
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
 clearLocations
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addLocation
0.00% covered (danger)
0.00%
0 / 1
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 */
13class Authority extends Base
14{
15    public function __clone()
16    {
17        if ($this['locations'] instanceof \BO\Zmsdldb\Collection\Locations) {
18            $this['locations'] = clone $this['locations'];
19        }
20    }
21
22    public static function create($name): self
23    {
24        $data = array(
25            'name' => $name,
26            'locations' => new \BO\Zmsdldb\Collection\Locations()
27        );
28        return new self($data);
29    }
30
31    /**
32     * Check if appointments are available
33     *
34     * @param String $serviceCsv
35     *            only check for this serviceCsv
36     * @param Bool $external
37     *            allow external links, default false
38     *
39     * @return Bool
40     * @psalm-api
41     */
42    public function hasAppointments($serviceCsv = null, $external = false)
43    {
44        foreach ($this['locations'] as $location) {
45            if ($location->hasAppointments($serviceCsv, $external)) {
46                return true;
47            }
48        }
49        return false;
50    }
51
52    /**
53     * Check if locations are available
54     *
55     * @return Bool
56     * @psalm-api
57     */
58    public function hasLocations()
59    {
60        return count($this['locations']) > 0 ? true : false;
61    }
62
63    /**
64     *
65     * @param String $officepath
66     *            only check for this office
67     * @return Authority
68     *
69     * @psalm-api
70     */
71    public function getLocationListByOfficePath($officepath)
72    {
73        $authority = clone $this;
74        if (count($authority['locations'])) {
75            $locations = new \BO\Zmsdldb\Collection\Locations($authority['locations']);
76            $authority['locations'] = $locations->getLocationListByOfficePath($officepath);
77        }
78        return $authority;
79    }
80
81    /**
82     *
83     * @param Int $locationId
84     *
85     * @return Bool
86     * @psalm-api
87     */
88    public function hasLocationId($locationId)
89    {
90        return $this['locations']->hasLocationId($locationId);
91    }
92
93    /**
94     * Remove a location
95     *
96     * @param Int $locationId
97     *
98     * @return self
99     * @psalm-api
100     */
101    public function removeLocation($locationId)
102    {
103        $authority = clone $this;
104        $authority['locations'] = $authority['locations']->removeLocation($locationId);
105        return $authority;
106    }
107
108    /**
109     * Check if Authority is part of ServiceList
110     *
111     * @param String $serviceCsv
112     *            only check for this serviceCsv
113     *
114     * @return self
115     */
116    public function isInServiceList($servicelist = array())
117    {
118        foreach ($servicelist as $service) {
119            if ($service->offsetExists('authorities')) {
120                foreach ($service['authorities'] as $authority) {
121                    if ($authority['id'] == $this['id']) {
122                        return true;
123                    }
124                }
125            }
126        }
127        return false;
128    }
129
130    public function clearLocations(): void
131    {
132        $this['locations'] = new \BO\Zmsdldb\Collection\Locations();
133    }
134
135    public function addLocation(\BO\Zmsdldb\Entity\Location $location): void
136    {
137        $this['locations'][$location['id']] = $location;
138    }
139}