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