Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 67 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Authority | |
0.00% |
0 / 67 |
|
0.00% |
0 / 3 |
182 | |
0.00% |
0 / 1 |
fetchList | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
42 | |||
fetchId | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
readListByOfficePath | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * @package ClientDldb |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsdldb\MySQL; |
9 | |
10 | use BO\Zmsdldb\MySQL\Collection\Authorities as Collection; |
11 | use BO\Zmsdldb\Elastic\Authority as Base; |
12 | |
13 | /** |
14 | */ |
15 | class Authority extends Base |
16 | { |
17 | /** |
18 | * fetch locations for a list of service and group by authority |
19 | * |
20 | * @return Collection\Authorities |
21 | */ |
22 | public function fetchList($servicelist = []) |
23 | { |
24 | try { |
25 | $authorityList = new Collection(); |
26 | |
27 | $sqlArgs = []; |
28 | |
29 | if (!empty($servicelist)) { |
30 | $sqlArgs = ['de',$this->locale]; |
31 | $questionMarks = array_fill(0, count($servicelist), '?'); |
32 | |
33 | $sql = "SELECT a.data_json |
34 | FROM authority_service AS aservice |
35 | LEFT JOIN authority AS a ON a.id = aservice.authority_id AND a.locale = ? |
36 | WHERE aservice.locale = ? AND aservice.service_id IN (" . implode(', ', $questionMarks) . ")"; |
37 | |
38 | array_push($sqlArgs, ...$servicelist); |
39 | |
40 | $stm = $this->access()->prepare($sql); |
41 | $stm->execute($sqlArgs); |
42 | $stm->fetchAll(\PDO::FETCH_FUNC, function ($data_json) use ($authorityList) { |
43 | $authority = new \BO\Zmsdldb\MySQL\Entity\Authority(); |
44 | $authority->offsetSet('data_json', $data_json); |
45 | $authorityList[$authority['id']] = $authority; |
46 | $authority->clearLocations(); |
47 | }); |
48 | |
49 | $sqlArgs = [$this->locale]; |
50 | $questionMarks = array_fill(0, count($servicelist), '?'); |
51 | |
52 | $sql = "SELECT ls.location_id AS id |
53 | FROM location_service ls |
54 | -- LEFT JOIN location AS l ON l.id = ls.location_id AND l.locale = ? |
55 | WHERE ls.locale = ? AND ls.service_id IN (" . implode(', ', $questionMarks) . ") |
56 | GROUP BY ls.location_id |
57 | "; |
58 | |
59 | array_push($sqlArgs, ...$servicelist); |
60 | |
61 | $stm = $this->access()->prepare($sql); |
62 | $stm->setFetchMode(\PDO::FETCH_OBJ); |
63 | $stm->execute($sqlArgs); |
64 | |
65 | $locations = $stm->fetchAll(); |
66 | $locationsIds = []; |
67 | |
68 | foreach ($locations as $location) { |
69 | $locationsIds[] = $location->id; |
70 | } |
71 | |
72 | $locations = $this->access()->fromLocation($this->locale) |
73 | ->fetchFromCsv(implode(',', $locationsIds), true); |
74 | |
75 | foreach ($locations as $location) { |
76 | $authorityList[$location['authority']['id']]->addLocation($location); |
77 | } |
78 | } else { |
79 | $sqlArgs = ['de']; |
80 | $sql = 'SELECT data_json FROM authority WHERE locale = ?'; |
81 | $stm = $this->access()->prepare($sql); |
82 | $stm->execute($sqlArgs); |
83 | $stm->fetchAll(\PDO::FETCH_FUNC, function ($data_json) use ($authorityList) { |
84 | $authority = new \BO\Zmsdldb\MySQL\Entity\Authority(); |
85 | $authority->offsetSet('data_json', $data_json); |
86 | $authorityList[$authority['id']] = $authority; |
87 | $authority->clearLocations(); |
88 | }); |
89 | |
90 | $locations = $this->access()->fromLocation($this->locale)->fetchList(false, true); |
91 | |
92 | foreach ($locations as $location) { |
93 | $authorityList[$location['authority']['id']]->addLocation($location); |
94 | } |
95 | } |
96 | return $authorityList; |
97 | } catch (\Exception $e) { |
98 | throw $e; |
99 | } |
100 | } |
101 | |
102 | /** |
103 | * fetch locations for a list of service and group by authority |
104 | * |
105 | * @return Collection\Authorities |
106 | */ |
107 | public function fetchId($authorityid) |
108 | { |
109 | try { |
110 | $sqlArgs = [$this->locale, $authorityid]; |
111 | $sqlArgs = ['de', $authorityid]; |
112 | |
113 | $sql = 'SELECT data_json FROM authority WHERE locale = ? AND id = ?'; |
114 | $stm = $this->access()->prepare($sql); |
115 | $stm->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, '\\BO\\Zmsdldb\\MySQL\\Entity\\Authority'); |
116 | $stm->execute($sqlArgs); |
117 | |
118 | $stm->execute($sqlArgs); |
119 | if (!$stm || ($stm && $stm->rowCount() == 0)) { |
120 | return false; |
121 | } |
122 | $authority = $stm->fetch(); |
123 | return $authority; |
124 | } catch (\Exception $e) { |
125 | throw $e; |
126 | } |
127 | } |
128 | |
129 | /** |
130 | * |
131 | * @return Collection |
132 | */ |
133 | public function readListByOfficePath($officepath) |
134 | { |
135 | $authorityList = new Collection(); |
136 | |
137 | $locations = $this->access()->fromLocation($this->locale)->fetchListByOffice($officepath); |
138 | |
139 | foreach ($locations as $location) { |
140 | $authorityList->addLocation($location); |
141 | } |
142 | |
143 | return $authorityList; |
144 | } |
145 | } |