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