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    /**
19     * @return Collection
20     */
21    #[\Override]
22    protected function parseData($data)
23    {
24        $itemList = new Collection();
25        foreach ($data['data'] as $item) {
26            $location = new Entity($item);
27            if ($location->isLocale($this->locale)) {
28                $itemList[$item['id']] = $location;
29            }
30        }
31        return $itemList;
32    }
33
34    /**
35     *
36     * @return Collection
37     */
38    public function fetchList($service_csv = false)
39    {
40        $locationlist = $this->getItemList();
41        if ($service_csv) {
42            $locationlist = new Collection(array_filter((array) $locationlist, function ($item) use ($service_csv) {
43                $location = new Entity($item);
44                return $location->containsService($service_csv);
45            }));
46        }
47        return $locationlist;
48    }
49
50    /**
51     *
52     * @return Collection
53     * @psalm-api
54     */
55    public function fetchFromCsv($location_csv)
56    {
57        $locationlist = new Collection();
58        foreach (explode(',', $location_csv) as $location_id) {
59            $location = $this->fetchId($location_id);
60            if ($location && $location->isLocale($this->locale)) {
61                $locationlist[$location_id] = $location;
62            }
63        }
64        return $locationlist;
65    }
66
67    /**
68     *
69     * @return Collection
70     * @psalm-api
71     */
72    public function readSearchResultList($query, $service_csv = '')
73    {
74        $locationlist = $this->fetchList($service_csv);
75        $locationlist = new Collection(array_filter((array) $locationlist, function ($item) use ($query) {
76            return false !== strpos($item['name'], $query);
77        }));
78        return $this->access()
79            ->fromAuthority()
80            ->fromLocationResults($locationlist);
81    }
82
83    /** @psalm-api */
84    public function fetchListByOffice($office)
85    {
86        return $this->access()->fromAuthority()
87        ->readListByOfficePath($office)
88        ->removeEmptyAuthorities()
89        ->sortByName();
90    }
91}