Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.77% |
30 / 31 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Authority | |
96.77% |
30 / 31 |
|
80.00% |
4 / 5 |
12 | |
0.00% |
0 / 1 |
| parseData | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| fetchList | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
5 | |||
| fromLocationResults | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| readListByOfficePath | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| fetchSource | |
0.00% |
0 / 1 |
|
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\Authority as Entity; |
| 11 | use BO\Zmsdldb\Collection\Authorities as Collection; |
| 12 | |
| 13 | /** |
| 14 | * Common methods shared by access classes |
| 15 | */ |
| 16 | class Authority extends Base |
| 17 | { |
| 18 | protected function parseData($data) |
| 19 | { |
| 20 | $itemList = new Collection(); |
| 21 | foreach ($data['data'] as $item) { |
| 22 | $itemList[$item['id']] = new Entity($item); |
| 23 | } |
| 24 | return $itemList; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * fetch locations for a list of service and group by authority |
| 29 | * |
| 30 | * @return Collection |
| 31 | */ |
| 32 | public function fetchList($servicelist = false) |
| 33 | { |
| 34 | $service_csv = implode(',', (array)$servicelist); |
| 35 | $authoritylist = $this->getItemList()->removeLocations(); |
| 36 | $locationlist = $this->access()->fromLocation($this->locale)->fetchList($service_csv); |
| 37 | if ($service_csv !== "") { |
| 38 | $servicelist = $this->access() |
| 39 | ->fromService($this->locale) |
| 40 | ->fetchFromCsv($service_csv); |
| 41 | $authoritylist = $authoritylist->toListWithAssociatedLocations($locationlist); |
| 42 | $authoritylist = new Collection(array_filter((array) $authoritylist, function ($item) use ($servicelist) { |
| 43 | $authority = new Entity($item); |
| 44 | if ($authority->isInServiceList($servicelist)) { |
| 45 | return $authority; |
| 46 | } |
| 47 | })); |
| 48 | } else { |
| 49 | foreach ($locationlist as $location) { |
| 50 | if ($location->isLocale($this->locale)) { |
| 51 | $authoritylist->addLocation($location); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | return $authoritylist; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Take an file search result and return a authority list |
| 60 | * |
| 61 | * @return Collection\Authorities |
| 62 | */ |
| 63 | public function fromLocationResults($resultList) |
| 64 | { |
| 65 | $authorityList = new Collection(); |
| 66 | foreach ($resultList as $result) { |
| 67 | $location = new \BO\Zmsdldb\Entity\Location($result); |
| 68 | $authorityList->addLocation($location); |
| 69 | } |
| 70 | return $authorityList; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * |
| 75 | * @return Collection |
| 76 | */ |
| 77 | public function readListByOfficePath($officepath) |
| 78 | { |
| 79 | $authoritylist = $this->fetchList(); |
| 80 | if ($officepath) { |
| 81 | $authoritylist = $authoritylist->toListWithOfficePath($officepath); |
| 82 | } |
| 83 | return $authoritylist; |
| 84 | } |
| 85 | |
| 86 | public function fetchSource() |
| 87 | { |
| 88 | return $this->getItemList(); |
| 89 | } |
| 90 | } |