Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.33% |
14 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
TranslationFormModifier | |
93.33% |
14 / 15 |
|
50.00% |
1 / 2 |
7.01 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
modify | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
6.02 |
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\taoTests\models\Translation\Form\Modifier; |
24 | |
25 | use core_kernel_classes_Literal; |
26 | use core_kernel_classes_Resource; |
27 | use oat\generis\model\data\Ontology; |
28 | use oat\tao\model\featureFlag\FeatureFlagCheckerInterface; |
29 | use oat\tao\model\form\Modifier\AbstractFormModifier; |
30 | use oat\tao\model\TaoOntology; |
31 | use oat\taoTests\models\TaoTestOntology; |
32 | use tao_helpers_form_Form as Form; |
33 | use tao_helpers_Uri; |
34 | |
35 | class TranslationFormModifier extends AbstractFormModifier |
36 | { |
37 | private FeatureFlagCheckerInterface $featureFlagChecker; |
38 | private Ontology $ontology; |
39 | |
40 | public function __construct(FeatureFlagCheckerInterface $featureFlagChecker, Ontology $ontology) |
41 | { |
42 | $this->featureFlagChecker = $featureFlagChecker; |
43 | $this->ontology = $ontology; |
44 | } |
45 | |
46 | public function modify(Form $form, array $options = []): void |
47 | { |
48 | if (!$this->featureFlagChecker->isEnabled('FEATURE_FLAG_TRANSLATION_ENABLED')) { |
49 | $form->removeElement(tao_helpers_Uri::encode(TaoTestOntology::PROPERTY_TRANSLATION_COMPLETION)); |
50 | |
51 | return; |
52 | } |
53 | |
54 | $instance = $this->ontology->getResource($form->getValue('uri')); |
55 | |
56 | $translationType = $instance->getOnePropertyValue( |
57 | $this->ontology->getProperty(TaoOntology::PROPERTY_TRANSLATION_TYPE) |
58 | ); |
59 | $translationTypeUri = $translationType instanceof core_kernel_classes_Literal |
60 | ? (string) $translationType |
61 | : ($translationType instanceof core_kernel_classes_Resource ? $translationType->getUri() : null); |
62 | |
63 | if ( |
64 | empty($translationType) |
65 | || $translationTypeUri === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL |
66 | ) { |
67 | $form->removeElement(tao_helpers_Uri::encode(TaoTestOntology::PROPERTY_TRANSLATION_COMPLETION)); |
68 | } |
69 | } |
70 | } |