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