Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
64.79% |
46 / 71 |
|
55.56% |
5 / 9 |
CRAP | |
0.00% |
0 / 1 |
Service | |
64.79% |
46 / 71 |
|
55.56% |
5 / 9 |
62.23 | |
0.00% |
0 / 1 |
parseData | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
searchAll | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
fetchList | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
fetchListRelated | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
fetchCombinations | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
fetchLocationCsv | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 | |||
fetchFromCsv | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
fetchListFromTopic | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
7.01 | |||
readSearchResultList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
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\Service as Entity; |
11 | use BO\Zmsdldb\Collection\Services as Collection; |
12 | |
13 | /** |
14 | * Common methods shared by access classes |
15 | */ |
16 | class Service extends Base |
17 | { |
18 | protected function parseData($data) |
19 | { |
20 | $itemList = new Collection(); |
21 | foreach ($data['data'] as $item) { |
22 | $service = new Entity($item); |
23 | if ($service->isLocale($this->locale)) { |
24 | $itemList[$item['id']] = $service; |
25 | } |
26 | } |
27 | return $itemList; |
28 | } |
29 | |
30 | /** |
31 | * |
32 | * @SuppressWarnings(Param) |
33 | * @return Collection |
34 | */ |
35 | public function searchAll($querystring, $service_csv = false, $location_csv = false) |
36 | { |
37 | $serviceList = $this->fetchList($location_csv); |
38 | if ($querystring) { |
39 | $serviceList = new Collection(array_filter((array) $serviceList, function ($item) use ($querystring) { |
40 | $length = (3 < strlen($querystring)) ? strlen($querystring) : 3; |
41 | $nameMatch = preg_match('/[' . $querystring . ']{' . $length . ',}/i', $item['name']); |
42 | $keywordMatch = preg_match('/[' . $querystring . ']{' . $length . ',}/i', $item['meta']['keywords']); |
43 | return ($nameMatch || $keywordMatch); |
44 | })); |
45 | } |
46 | $serviceList = $serviceList->sortByName(); |
47 | return ($location_csv) ? $serviceList->containsLocation($location_csv) : $serviceList; |
48 | } |
49 | |
50 | /** |
51 | * |
52 | * @return Collection |
53 | */ |
54 | public function fetchList($location_csv = false) |
55 | { |
56 | #echo '<pre>' . print_r($this,1) . '</pre>';exit; |
57 | $servicelist = $this->getItemList(); |
58 | if ($location_csv) { |
59 | $servicelist = new Collection(array_filter((array) $servicelist, function ($item) use ($location_csv) { |
60 | $service = new Entity($item); |
61 | return $service->containsLocation($location_csv); |
62 | })); |
63 | } |
64 | return $servicelist; |
65 | } |
66 | |
67 | /** |
68 | * |
69 | * @return Collection |
70 | */ |
71 | public function fetchListRelated($service_id) |
72 | { |
73 | $service = $this->fetchId($service_id); |
74 | $serviceList = $this->getItemList(); |
75 | |
76 | $relatedList = new Collection( |
77 | array_filter( |
78 | (array) $serviceList, |
79 | function ($item) use ($service) { |
80 | $leikaIdentItem = substr(strval($item['leika']), 0, 11); |
81 | $leikaIdentService = substr(strval($service['leika']), 0, 11); |
82 | return ($leikaIdentItem == $leikaIdentService && $item['id'] != $service['id']); |
83 | } |
84 | ) |
85 | ); |
86 | return ($relatedList) ? $relatedList : new Collection(); |
87 | } |
88 | |
89 | /** |
90 | * |
91 | * @return Collection |
92 | */ |
93 | public function fetchCombinations($service_csv) |
94 | { |
95 | return $this->fetchList($this->fetchLocationCsv($service_csv)); |
96 | } |
97 | |
98 | /** |
99 | * |
100 | * @return String |
101 | */ |
102 | protected function fetchLocationCsv($service_csv) |
103 | { |
104 | $locationlist = $this->access() |
105 | ->fromLocation() |
106 | ->fetchList($service_csv); |
107 | $locationIdList = array(); |
108 | foreach ($locationlist as $location) { |
109 | $locationIdList[] = $location['id']; |
110 | } |
111 | return implode(',', $locationIdList); |
112 | } |
113 | |
114 | /** |
115 | * |
116 | * @return Collection |
117 | */ |
118 | public function fetchFromCsv($service_csv) |
119 | { |
120 | $servicelist = new Collection(); |
121 | foreach (explode(',', $service_csv) as $service_id) { |
122 | $service = $this->fetchId($service_id); |
123 | if ($service && $service->isLocale($this->locale)) { |
124 | $servicelist[$service_id] = $service; |
125 | } |
126 | } |
127 | return $servicelist; |
128 | } |
129 | |
130 | /** |
131 | * Return services by topic |
132 | * If topic is root, include sub-services |
133 | * root_topic in realations not usable because of multiple roots for one service |
134 | * |
135 | * @return Collection |
136 | */ |
137 | public function fetchListFromTopic(\BO\Zmsdldb\Entity\Topic $topic) |
138 | { |
139 | $itemlist = new Collection(); |
140 | $serviceIds = array(); |
141 | if ($topic) { |
142 | $serviceIds = $topic->getServiceIds(); |
143 | if ($topic['relation']['navi'] && isset($topic['relation']['childs'])) { |
144 | foreach ($topic['relation']['childs'] as $child) { |
145 | $childtopic = $this->access() |
146 | ->fromTopic() |
147 | ->fetchPath($child['path']); |
148 | if ($childtopic) { |
149 | $serviceIds = array_merge($serviceIds, $childtopic->getServiceIds()); |
150 | } |
151 | } |
152 | } |
153 | } |
154 | if (count($serviceIds)) { |
155 | $servicelistCSV = implode(',', $serviceIds); |
156 | $servicelist = $this->fetchFromCsv($servicelistCSV); |
157 | return $servicelist; |
158 | } |
159 | return $itemlist->sortByName(); |
160 | } |
161 | |
162 | /** |
163 | * |
164 | * @return Collection |
165 | */ |
166 | public function readSearchResultList($query, $service_csv = '') |
167 | { |
168 | $servicelist = $this->fetchCombinations($service_csv); |
169 | $servicelist = new Collection(array_filter((array) $servicelist, function ($item) use ($query) { |
170 | return false !== strpos($item['name'], $query); |
171 | })); |
172 | return $servicelist; |
173 | } |
174 | } |