Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
86.67% covered (warning)
86.67%
26 / 30
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Location
86.67% covered (warning)
86.67%
26 / 30
80.00% covered (warning)
80.00%
4 / 5
11.29
0.00% covered (danger)
0.00%
0 / 1
 parseData
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 fetchList
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 fetchFromCsv
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 readSearchResultList
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 fetchListByOffice
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * @package 115Mandant
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsdldb\File;
9
10use BO\Zmsdldb\Entity\Location as Entity;
11use BO\Zmsdldb\Collection\Locations as Collection;
12
13/**
14 * Common methods shared by access classes
15 */
16class Location extends Base
17{
18    #[\Override]
19    protected function parseData($data)
20    {
21        $itemList = new Collection();
22        foreach ($data['data'] as $item) {
23            $location = new Entity($item);
24            if ($location->isLocale($this->locale)) {
25                $itemList[$item['id']] = $location;
26            }
27        }
28        return $itemList;
29    }
30
31    /**
32     *
33     * @return Collection
34     */
35    public function fetchList($service_csv = false)
36    {
37        $locationlist = $this->getItemList();
38        if ($service_csv) {
39            $locationlist = new Collection(array_filter((array) $locationlist, function ($item) use ($service_csv) {
40                $location = new Entity($item);
41                return $location->containsService($service_csv);
42            }));
43        }
44        return $locationlist;
45    }
46
47    /**
48     *
49     * @return Collection
50     */
51    public function fetchFromCsv($location_csv)
52    {
53        $locationlist = new Collection();
54        foreach (explode(',', $location_csv) as $location_id) {
55            $location = $this->fetchId($location_id);
56            if ($location && $location->isLocale($this->locale)) {
57                $locationlist[$location_id] = $location;
58            }
59        }
60        return $locationlist;
61    }
62
63    /**
64     *
65     * @return Collection
66     */
67    public function readSearchResultList($query, $service_csv = '')
68    {
69        $locationlist = $this->fetchList($service_csv);
70        $locationlist = new Collection(array_filter((array) $locationlist, function ($item) use ($query) {
71            return false !== strpos($item['name'], $query);
72        }));
73        return $this->access()
74            ->fromAuthority()
75            ->fromLocationResults($locationlist);
76    }
77
78    public function fetchListByOffice($office)
79    {
80        return $this->access()->fromAuthority()
81        ->readListByOfficePath($office)
82        ->removeEmptyAuthorities()
83        ->sortByName();
84    }
85}