Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ResourceTranslatableRepository | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
find | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 |
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) 2024 (original work) Open Assessment Technologies SA; |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\tao\model\Translation\Repository; |
24 | |
25 | use oat\generis\model\data\Ontology; |
26 | use oat\tao\model\TaoOntology; |
27 | use oat\tao\model\Translation\Entity\ResourceCollection; |
28 | use oat\tao\model\Translation\Factory\ResourceTranslatableFactory; |
29 | use oat\tao\model\Translation\Query\ResourceTranslatableQuery; |
30 | |
31 | class ResourceTranslatableRepository |
32 | { |
33 | private Ontology $ontology; |
34 | private ResourceTranslatableFactory $factory; |
35 | |
36 | public function __construct(Ontology $ontology, ResourceTranslatableFactory $factory) |
37 | { |
38 | $this->ontology = $ontology; |
39 | $this->factory = $factory; |
40 | } |
41 | |
42 | public function find(ResourceTranslatableQuery $query): ResourceCollection |
43 | { |
44 | $output = []; |
45 | $resource = $this->ontology->getResource($query->getResourceUri()); |
46 | $typeProperty = $this->ontology->getProperty(TaoOntology::PROPERTY_TRANSLATION_TYPE); |
47 | |
48 | $typeValue = $resource->getOnePropertyValue($typeProperty); |
49 | |
50 | if (!$typeValue || $typeValue->getUri() !== TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_TRANSLATION) { |
51 | $output[] = $this->factory->create($resource); |
52 | } |
53 | |
54 | return new ResourceCollection(...$output); |
55 | } |
56 | } |