Skip to content

Commit

Permalink
fix: feature flag for xml editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Makar Sichevoi committed Nov 8, 2023
1 parent a4d1d43 commit 6932cbc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion actions/class.XmlEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ public function edit(): void
*/
private function getXmlEditorService(): XmlEditorInterface
{
return $this->getServiceLocator()->get(XmlEditorInterface::SERVICE_ID);
return $this->getServiceLocator()->getContainer()->get(XmlEditorInterface::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@

use oat\taoQtiTest\models\xmlEditor\XmlEditor;

return new XmlEditor([
XmlEditor::OPTION_XML_EDITOR_LOCK => true
]);
return [XmlEditor::OPTION_XML_EDITOR_LOCK => true];
19 changes: 17 additions & 2 deletions model/Container/TestQtiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@

namespace oat\taoQtiTest\model\Container;

use common_ext_ExtensionsManager;
use oat\generis\model\data\Ontology;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\oatbox\event\EventManager;
use oat\oatbox\log\LoggerService;
use oat\taoQtiItem\model\qti\Service;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\taoQtiTest\model\Domain\Model\ItemResponseRepositoryInterface;
use oat\taoQtiTest\model\Domain\Model\QtiTestRepositoryInterface;
use oat\taoQtiTest\model\Domain\Model\ToolsStateRepositoryInterface;
use oat\taoQtiTest\model\Infrastructure\QtiItemResponseRepository;
use oat\taoQtiTest\model\Infrastructure\QtiToolsStateRepository;
use oat\taoQtiTest\model\Infrastructure\QtiTestRepository;
use oat\taoQtiTest\model\Infrastructure\QtiToolsStateRepository;
use oat\taoQtiTest\model\Service\ExitTestService;
use oat\taoQtiTest\model\Service\ListItemsService;
use oat\taoQtiTest\model\Service\MoveService;
Expand All @@ -44,7 +45,10 @@
use oat\taoQtiTest\model\Service\TimeoutService;
use oat\taoQtiTest\models\runner\QtiRunnerService;
use oat\taoQtiTest\models\TestModelService;
use oat\taoQtiTest\models\xmlEditor\XmlEditor;
use oat\taoQtiTest\models\xmlEditor\XmlEditorInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use taoQtiTest_models_classes_QtiTestService;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

Expand Down Expand Up @@ -156,5 +160,16 @@ public function __invoke(ContainerConfigurator $configurator): void
service(TestModelService::SERVICE_ID),
]
);

$services
->set(XmlEditorInterface::class, XmlEditor::class)
->public()
->args(
[
service(common_ext_ExtensionsManager::SERVICE_ID),
service(taoQtiTest_models_classes_QtiTestService::class),
service(FeatureFlagChecker::class),
]
);
}
}
46 changes: 29 additions & 17 deletions models/classes/xmlEditor/XmlEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,43 @@

namespace oat\taoQtiTest\models\xmlEditor;

use oat\oatbox\service\ConfigurableService;
use common_ext_ExtensionsManager;
use core_kernel_classes_Resource;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use qtism\data\storage\xml\XmlDocument;
use taoQtiTest_models_classes_QtiTestService;
use core_kernel_classes_Resource;

class XmlEditor extends ConfigurableService implements XmlEditorInterface
class XmlEditor implements XmlEditorInterface
{
private const FEATURE_FLAG_XML_EDITOR_ENABLED = 'FEATURE_FLAG_XML_EDITOR_ENABLED';
private const CONFIG = 'xmlEditor';

/** @var taoQtiTest_models_classes_QtiTestService */
private taoQtiTest_models_classes_QtiTestService $qtiTestService;

/** @var FeatureFlagChecker */
private FeatureFlagChecker $featureFlagChecker;

private array $options = [];

public function __construct(
common_ext_ExtensionsManager $extensionsManager,
taoQtiTest_models_classes_QtiTestService $qtiTestService,
FeatureFlagChecker $featureFlagChecker
) {
$this->options = $extensionsManager
->getExtensionById('taoQtiTest')
->getConfig(self::CONFIG);
$this->qtiTestService = $qtiTestService;
$this->featureFlagChecker = $featureFlagChecker;
}

/**
* {@inheritdoc}
*/
public function getTestXml(core_kernel_classes_Resource $test): string
{
return $this->getTestService()->getDoc($test)->saveToString();
return $this->qtiTestService->getDoc($test)->saveToString();
}

/**
Expand All @@ -48,28 +70,18 @@ public function saveStringTest(core_kernel_classes_Resource $test, string $testS
$doc->loadFromString($testString, true);
$converter = new \taoQtiTest_models_classes_QtiTestConverter($doc);

return $this->getTestService()->saveJsonTest($test, $converter->toJson());
return $this->qtiTestService->saveJsonTest($test, $converter->toJson());
}

/**
* {@inheritdoc}
*/
public function isLocked(): bool
{
if ($this->getFeatureFlagChecker()->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED)) {
if ($this->featureFlagChecker->isEnabled(self::FEATURE_FLAG_XML_EDITOR_ENABLED)) {
return false;
}

return $this->hasOption('is_locked') ? (bool)$this->getOption('is_locked') : true;
}

private function getTestService(): taoQtiTest_models_classes_QtiTestService
{
return $this->getServiceLocator()->get(taoQtiTest_models_classes_QtiTestService::class);
}

private function getFeatureFlagChecker(): FeatureFlagChecker
{
return $this->getServiceManager()->getContainer()->get(FeatureFlagChecker::class);
return isset($this->options['is_locked']) ? (bool)$this->options['is_locked'] : true;
}
}
1 change: 0 additions & 1 deletion models/classes/xmlEditor/XmlEditorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

interface XmlEditorInterface
{
public const SERVICE_ID = 'taoQtiTest/XmlEditor';
public const XML_EDITOR_ROLE = 'http://www.tao.lu/Ontologies/generis.rdf#TestXMLEditor';
public const OPTION_XML_EDITOR_LOCK = 'is_locked';

Expand Down

0 comments on commit 6932cbc

Please sign in to comment.