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    /**
19     * @return Collection
20     */
21    #[\Override]
22    protected function parseData($data)
23    {
24        $itemList = new Collection();
25        foreach ($data['data'] as $item) {
26            $itemList[$item['id']] = new Entity($item);
27        }
28        return $itemList;
29    }
30
31    /**
32     * fetch locations for a list of service and group by authority
33     *
34     * @return Collection
35     */
36    public function fetchList($servicelist = false)
37    {
38        $service_csv = implode(',', (array)$servicelist);
39        $authoritylist = $this->getItemList()->removeLocations();
40        $locationlist = $this->access()->fromLocation($this->locale)->fetchList($service_csv);
41        if ($service_csv !== "") {
42            $servicelist = $this->access()
43                ->fromService($this->locale)
44                ->fetchFromCsv($service_csv);
45            $authoritylist = $authoritylist->toListWithAssociatedLocations($locationlist);
46            $authoritylist = new Collection(array_filter((array) $authoritylist, function ($item) use ($servicelist) {
47                $authority = new Entity($item);
48                if ($authority->isInServiceList($servicelist)) {
49                    return $authority;
50                }
51            }));
52        } else {
53            foreach ($locationlist as $location) {
54                if ($location->isLocale($this->locale)) {
55                    $authoritylist->addLocation($location);
56                }
57            }
58        }
59        return $authoritylist;
60    }
61
62    /**
63     * Take an file search result and return a authority list
64     *
65     * @return Collection
66     */
67    public function fromLocationResults($resultList)
68    {
69        $authorityList = new Collection();
70        foreach ($resultList as $result) {
71            $location = new \BO\Zmsdldb\Entity\Location($result);
72            $authorityList->addLocation($location);
73        }
74        return $authorityList;
75    }
76
77    /**
78     *
79     * @return Collection
80     * @psalm-api
81     */
82    public function readListByOfficePath($officepath)
83    {
84        $authoritylist = $this->fetchList();
85        if ($officepath) {
86            $authoritylist = $authoritylist->toListWithOfficePath($officepath);
87        }
88        return $authoritylist;
89    }
90
91    /** @psalm-api */
92    public function fetchSource()
93    {
94        return $this->getItemList();
95    }
96}