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