Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| XmlEditor | |
100.00% |
17 / 17 |
|
100.00% |
6 / 6 |
10 | |
100.00% |
1 / 1 |
| getTestXml | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| saveStringTest | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| isLocked | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 | |||
| getTestService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFeatureFlagChecker | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUserSettingsService | |
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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoQtiTest\models\xmlEditor; |
| 24 | |
| 25 | use core_kernel_classes_Resource; |
| 26 | use oat\generis\model\GenerisRdf; |
| 27 | use oat\oatbox\service\ConfigurableService; |
| 28 | use oat\tao\model\featureFlag\FeatureFlagChecker; |
| 29 | use oat\tao\model\featureFlag\FeatureFlagCheckerInterface; |
| 30 | use oat\tao\model\user\implementation\UserSettingsService; |
| 31 | use oat\tao\model\user\UserSettingsInterface; |
| 32 | use oat\tao\model\user\UserSettingsServiceInterface; |
| 33 | use qtism\data\storage\xml\XmlDocument; |
| 34 | use taoQtiTest_models_classes_QtiTestService; |
| 35 | |
| 36 | class XmlEditor extends ConfigurableService implements XmlEditorInterface |
| 37 | { |
| 38 | private const FEATURE_FLAG_XML_EDITOR_ENABLED = 'FEATURE_FLAG_XML_EDITOR_ENABLED'; |
| 39 | /** @var @deprecated */ |
| 40 | private const LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED = 'XML_EDITOR_ENABLED'; |
| 41 | |
| 42 | /** |
| 43 | * {@inheritdoc} |
| 44 | */ |
| 45 | public function getTestXml(core_kernel_classes_Resource $test): string |
| 46 | { |
| 47 | return $this->getTestService()->getDoc($test)->saveToString(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * {@inheritdoc} |
| 52 | */ |
| 53 | public function saveStringTest(core_kernel_classes_Resource $test, string $testString): bool |
| 54 | { |
| 55 | $doc = new XmlDocument(); |
| 56 | $doc->loadFromString($testString, true); |
| 57 | $converter = new \taoQtiTest_models_classes_QtiTestConverter($doc); |
| 58 | |
| 59 | return $this->getTestService()->saveJsonTest($test, $converter->toJson()); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * {@inheritdoc} |
| 64 | */ |
| 65 | public function isLocked(): bool |
| 66 | { |
| 67 | $userSettings = $this->getUserSettingsService()->getCurrentUserSettings(); |
| 68 | |
| 69 | if ( |
| 70 | $userSettings->getSetting( |
| 71 | UserSettingsInterface::INTERFACE_MODE |
| 72 | ) === GenerisRdf::PROPERTY_USER_INTERFACE_MODE_SIMPLE |
| 73 | ) { |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | if ( |
| 78 | $this->getFeatureFlagChecker()->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED) |
| 79 | || $this->getFeatureFlagChecker()->isEnabled(self::LEGACY_FEATURE_FLAG_XML_EDITOR_ENABLED) |
| 80 | ) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | return $this->hasOption('is_locked') ? (bool)$this->getOption('is_locked') : true; |
| 85 | } |
| 86 | |
| 87 | private function getTestService(): taoQtiTest_models_classes_QtiTestService |
| 88 | { |
| 89 | return $this->getServiceManager()->getContainer()->get(taoQtiTest_models_classes_QtiTestService::class); |
| 90 | } |
| 91 | |
| 92 | private function getFeatureFlagChecker(): FeatureFlagCheckerInterface |
| 93 | { |
| 94 | return $this->getServiceManager()->getContainer()->get(FeatureFlagChecker::class); |
| 95 | } |
| 96 | |
| 97 | public function getUserSettingsService(): UserSettingsServiceInterface |
| 98 | { |
| 99 | return $this->getServiceManager()->getContainer()->get(UserSettingsService::class); |
| 100 | } |
| 101 | } |