Lines
0.00%
0 / 20
Functions and Methods
0.00%
0 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Authority | 0.00% | 0 / 20 | 0.00% | 0 / 2 | 30 | 0.00% | 0 / 1 | |||
| fetchList | 0.00% | 0 / 15 | 0.00% | 0 / 1 | 12 | |||||
| fromLocationResults | 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\Elastic; | |
| 9 | ||
| 10 | use BO\Zmsdldb\Collection\Authorities as Collection; | |
| 11 | use BO\Zmsdldb\File\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(mixed $servicelist = false) | |
| 24 | { | |
| 25 | $boolquery = Helper::boolFilteredQuery(); | |
| 26 | $boolquery->getFilter()->addMust(Helper::localeFilter($this->locale)); | |
| 27 | $query = \Elastica\Query::create($boolquery); | |
| 28 | $limit = 1000; | |
| 29 | ||
| 30 | /** @psalm-suppress RiskyTruthyFalsyComparison */ | |
| 31 | if (is_array($servicelist) && $servicelist !== []) { | |
| 32 | $filter = new \Elastica\Filter\Terms('services.service', array_values($servicelist)); | |
| 33 | $filter->setExecution('and'); | |
| 34 | $query->setPostFilter($filter); | |
| 35 | } | |
| 36 | $query->addSort(['sort' => 'asc']); | |
| 37 | $resultList = $this | |
| 38 | ->access() | |
| 39 | ->getIndex() | |
| 40 | ->getType('location') | |
| 41 | ->search($query, $limit); | |
| 42 | return $this->fromLocationResults($resultList); | |
| 43 | } | |
| 44 | ||
| 45 | ||
| 46 | /** | |
| 47 | * Take an elasticsearch result and return a authority list | |
| 48 | * | |
| 49 | * @return Collection | |
| 50 | */ | |
| 51 | #[\Override] | |
| 52 | public function fromLocationResults(mixed $resultList) | |
| 53 | { | |
| 54 | $authorityList = new Collection(); | |
| 55 | foreach ($resultList as $result) { | |
| 56 | $location = new \BO\Zmsdldb\Entity\Location($result->getData()); | |
| 57 | $authorityList->addLocation($location); | |
| 58 | } | |
| 59 | return $authorityList; | |
| 60 | } | |
| 61 | } |