Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
96.88% |
31 / 32 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
LanguageRepository | |
96.88% |
31 / 32 |
|
50.00% |
1 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
findAvailableLanguagesByUsage | |
96.67% |
29 / 30 |
|
0.00% |
0 / 1 |
5 |
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) 2022 (original work) Open Assessment Technologies SA; |
19 | * |
20 | * @author Gabriel Felipe Soares <gabriel.felipe.soares@taotesting.com> |
21 | */ |
22 | |
23 | declare(strict_types=1); |
24 | |
25 | namespace oat\tao\model\Language\Repository; |
26 | |
27 | use core_kernel_classes_Resource; |
28 | use oat\generis\model\data\Ontology; |
29 | use oat\generis\model\OntologyRdf; |
30 | use oat\tao\model\Language\Business\Contract\LanguageRepositoryInterface; |
31 | use oat\tao\model\Language\Language; |
32 | use oat\tao\model\Language\LanguageCollection; |
33 | use tao_models_classes_LanguageService; |
34 | |
35 | class LanguageRepository implements LanguageRepositoryInterface |
36 | { |
37 | /** @var Ontology */ |
38 | private $ontology; |
39 | |
40 | /** @var tao_models_classes_LanguageService */ |
41 | private $languageService; |
42 | |
43 | public function __construct(Ontology $ontology, tao_models_classes_LanguageService $languageService) |
44 | { |
45 | $this->ontology = $ontology; |
46 | $this->languageService = $languageService; |
47 | } |
48 | |
49 | public function findAvailableLanguagesByUsage(): LanguageCollection |
50 | { |
51 | $languages = $this->languageService->getAvailableLanguagesByUsage( |
52 | $this->ontology->getResource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA) |
53 | ); |
54 | |
55 | $output = new LanguageCollection(); |
56 | |
57 | /** @var core_kernel_classes_Resource[] $languages */ |
58 | foreach ($languages as $language) { |
59 | $values = $language->getPropertiesValues( |
60 | [ |
61 | OntologyRdf::RDF_VALUE, |
62 | tao_models_classes_LanguageService::PROPERTY_LANGUAGE_ORIENTATION, |
63 | tao_models_classes_LanguageService::PROPERTY_LANGUAGE_VERTICAL_WRITING_MODE |
64 | ] |
65 | ); |
66 | |
67 | $orientationUri = $values[tao_models_classes_LanguageService::PROPERTY_LANGUAGE_ORIENTATION][0]->getUri(); |
68 | |
69 | $verticalMode = null; |
70 | $verticalPropVal = $values[tao_models_classes_LanguageService::PROPERTY_LANGUAGE_VERTICAL_WRITING_MODE]; |
71 | if ($verticalPropVal) { |
72 | $verticalUri = $verticalPropVal[0]->getUri(); |
73 | $verticalMode = $verticalUri === tao_models_classes_LanguageService::INSTANCE_VERTICAL_WRITING_MODE_RL |
74 | ? 'vertical-rl' |
75 | : 'vertical-lr'; |
76 | } |
77 | |
78 | $output->add( |
79 | new Language( |
80 | $language->getUri(), |
81 | $values[OntologyRdf::RDF_VALUE][0]->__toString(), |
82 | $language->getLabel(), |
83 | $orientationUri === tao_models_classes_LanguageService::INSTANCE_ORIENTATION_RTL ? 'rtl' : 'ltr', |
84 | $verticalMode |
85 | ) |
86 | ); |
87 | } |
88 | |
89 | return $output; |
90 | } |
91 | } |