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