Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.62% covered (warning)
84.62%
22 / 26
87.50% covered (warning)
87.50%
7 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
Locations
84.62% covered (warning)
84.62%
22 / 26
87.50% covered (warning)
87.50%
7 / 8
16.93
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
 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%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getLocationsWithAppointmentsFor
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 getIds
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getNames
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getCSV
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLocationListByOfficePath
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 * @package Zmsdldb
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsdldb\Collection;
9
10class Locations extends Base
11{
12    public function __clone()
13    {
14        foreach ($this as $key => $location) {
15            $this[$key] = clone $location;
16        }
17    }
18
19    /**
20     * @param int $locationId
21     *
22     * @return Bool
23     */
24    public function hasLocationId($locationId): bool
25    {
26        return $this->offsetExists($locationId);
27    }
28
29    /**
30     * Remove a location
31     *
32     * @param Int $locationId
33     *
34     * @return self
35     * @psalm-api
36     */
37    public function removeLocation($locationId)
38    {
39        $locationList = clone $this;
40        if ($locationList->hasLocationId($locationId)) {
41            unset($locationList[$locationId]);
42        }
43        return $locationList;
44    }
45
46    /**
47     * find locations with appointments
48     *
49     * @param String $serviceCsv only check for this serviceCsv
50     * @param Bool $external allow external links, default false
51     */
52    public function getLocationsWithAppointmentsFor($serviceCsv = null, $external = false): self
53    {
54        $list = new self();
55        foreach ($this as $location) {
56            if ($location->hasAppointments($serviceCsv, $external)) {
57                $list[] = $location;
58            }
59        }
60        return $list;
61    }
62
63    public function getIds(): array
64    {
65        $idList = array();
66        foreach ($this as $location) {
67            $idList[] = $location['id'];
68        }
69        return $idList;
70    }
71
72    /**
73     * @psalm-api
74     */
75    public function getNames(): array
76    {
77        $nameList = array();
78        foreach ($this as $location) {
79            $nameList[$location['id']] = $location['name'];
80        }
81        return $nameList;
82    }
83
84    public function getCSV(): string
85    {
86        return implode(',', $this->getIds());
87    }
88
89    public function getLocationListByOfficePath(string $officepath): self
90    {
91        $locationList = new self();
92        foreach ($this as $location_id => $location) {
93            if ($location['office'] == $officepath) {
94                $locationList[$location_id] = $location;
95            }
96        }
97        return $locationList;
98    }
99}