Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.59% |
25 / 27 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
ParentPropertyListRepository | |
92.59% |
25 / 27 |
|
75.00% |
3 / 4 |
8.03 | |
0.00% |
0 / 1 |
findAllUris | |
91.67% |
22 / 24 |
|
0.00% |
0 / 1 |
5.01 | |||
getRdsValueCollectionRepository | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDependencyRepository | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getComplexSearchService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2021 (original work) Open Assessment Technologies SA; |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\tao\model\Lists\DataAccess\Repository; |
24 | |
25 | use InvalidArgumentException; |
26 | use oat\generis\model\OntologyRdf; |
27 | use oat\generis\model\OntologyRdfs; |
28 | use oat\oatbox\service\ConfigurableService; |
29 | use oat\search\helper\SupportedOperatorHelper; |
30 | use oat\tao\model\Lists\Business\Domain\ValueCollectionSearchRequest; |
31 | use oat\tao\model\Lists\Business\Contract\DependencyRepositoryInterface; |
32 | use oat\tao\model\Lists\Business\Contract\ValueCollectionRepositoryInterface; |
33 | use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; |
34 | use oat\tao\model\Lists\Business\Contract\ParentPropertyListRepositoryInterface; |
35 | |
36 | class ParentPropertyListRepository extends ConfigurableService implements ParentPropertyListRepositoryInterface |
37 | { |
38 | public function findAllUris(array $options): array |
39 | { |
40 | if (empty($options['listUri'])) { |
41 | throw new InvalidArgumentException('listUri must be provided as a filter'); |
42 | } |
43 | |
44 | $dependencies = $this->getDependencyRepository()->findAll( |
45 | [ |
46 | 'listUri' => $options['listUri'], |
47 | ] |
48 | )->getValues(); |
49 | |
50 | if (empty($dependencies)) { |
51 | return []; |
52 | } |
53 | |
54 | $dependencyListUris = $this->getRdsValueCollectionRepository() |
55 | ->findAll((new ValueCollectionSearchRequest())->setUris(...$dependencies)) |
56 | ->getListUris(); |
57 | |
58 | if (empty($dependencyListUris)) { |
59 | return []; |
60 | } |
61 | |
62 | $propertyList = []; |
63 | |
64 | $search = $this->getComplexSearchService(); |
65 | $propertyListQueryBuilder = $search->query(); |
66 | $propertyListQuery = $search->searchType($propertyListQueryBuilder, OntologyRdf::RDF_PROPERTY, true); |
67 | $propertyListQuery->addCriterion(OntologyRdfs::RDFS_RANGE, SupportedOperatorHelper::IN, $dependencyListUris); |
68 | $propertyListQueryBuilder->setCriteria($propertyListQuery); |
69 | $propertyListResult = $search->getGateway()->search($propertyListQueryBuilder); |
70 | |
71 | foreach ($propertyListResult as $property) { |
72 | $propertyList[] = $property->getUri(); |
73 | } |
74 | |
75 | return $propertyList; |
76 | } |
77 | |
78 | private function getRdsValueCollectionRepository(): ValueCollectionRepositoryInterface |
79 | { |
80 | return $this->getServiceLocator()->get(RdsValueCollectionRepository::SERVICE_ID); |
81 | } |
82 | |
83 | private function getDependencyRepository(): DependencyRepositoryInterface |
84 | { |
85 | return $this->getServiceLocator()->getContainer()->get(DependencyRepository::class); |
86 | } |
87 | |
88 | private function getComplexSearchService(): ComplexSearchService |
89 | { |
90 | return $this->getServiceLocator()->get(ComplexSearchService::SERVICE_ID); |
91 | } |
92 | } |