Skip to content

Commit

Permalink
Merge branch 'release-30.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jul 12, 2024
2 parents 44ce377 + d3463ae commit 74342b8
Show file tree
Hide file tree
Showing 34 changed files with 957 additions and 44 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ php tao/scripts/taoUpdate.php
### Feature Flags


| Variable | Description | Default value |
|------------------|---------------------------------------------------------------------------|---------------|
| FEATURE_FLAG_FLA | Toggles certain media-interaction options' availability in item authoring | false |
| Variable | Description | Default value |
|---------------------------------------------|---------------------------------------------------------------------------|---------------|
| FEATURE_FLAG_FLA | Toggles certain media-interaction options' availability in item authoring | false |
| FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER | This will replace Item Qti Identifier to 9 digits non editable field | - |
87 changes: 87 additions & 0 deletions helpers/QtiXmlLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoQtiItem\helpers;

use common_ext_ExtensionsManager as ExtensionsManager;
use DOMDocument;
use Exception;
use oat\taoQtiItem\model\qti\exception\QtiModelException;

class QtiXmlLoader
{
private ExtensionsManager $extensionsManager;

/**
* @param ExtensionsManager $extensionsManager
*/
public function __construct(ExtensionsManager $extensionsManager)
{
$this->extensionsManager = $extensionsManager;
}

/**
* Load QTI xml and return DOMDocument instance.
* This is service implementation of oat\taoQtiItem\helpers\Authoring::loadQtiXml
* @throws QtiModelException
*/
public function load(string $xml): DOMDocument
{
$dom = new DOMDocument('1.0', 'UTF-8');
$this->configDomParser($dom);
try {
$dom->loadXML($xml);
} catch (Exception $e) {
throw new QtiModelException('Invalid QTI XML', 0, $e);
}

return $dom;
}

private function getQtiParserConfig(): array
{
return $this->extensionsManager->getExtensionById('taoQtiItem')
->getConfig('XMLParser');
}

private function configDomParser(DOMDocument $dom): void
{
$parserConfig = $this->getQtiParserConfig();
if ($this->parserConfigValid($parserConfig)) {
$dom->formatOutput = $parserConfig['formatOutput'];
$dom->preserveWhiteSpace = $parserConfig['preserveWhiteSpace'];
$dom->validateOnParse = $parserConfig['validateOnParse'];

return;
}

$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$dom->validateOnParse = false;
}

private function parserConfigValid(array $parserConfig): bool
{
return !empty($parserConfig) &&
isset($parserConfig['formatOutput'], $parserConfig['preserveWhiteSpace'], $parserConfig['validateOnParse']);
}
}
6 changes: 5 additions & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
CustomInteractionAssetExtractorAllocatorServiceProvider
};
use oat\taoQtiItem\model\FeatureFlag\ServiceProvider\FeatureFlagFlaServiceProvider;
use oat\taoQtiItem\model\FeatureFlag\ServiceProvider\FeatureFlagQtiIdentifierServiceProvider;
use oat\taoQtiItem\model\qti\metadata\importer\MetaMetadataServiceProvider;
use oat\taoQtiItem\model\qti\ServiceProvider\IdentifierGenerationStrategyServiceProvider;
use oat\taoQtiItem\model\qti\ServiceProvider\ItemIdentifierValidatorServiceProvider;
use oat\taoQtiItem\model\qti\ServiceProvider\MetadataServiceProvider;
use oat\taoQtiItem\scripts\install\AddLabelInjectorForExport;
Expand Down Expand Up @@ -204,6 +206,8 @@
FeatureFlagFlaServiceProvider::class,
ItemIdentifierValidatorServiceProvider::class,
MetadataServiceProvider::class,
MetaMetadataServiceProvider::class
MetaMetadataServiceProvider::class,
IdentifierGenerationStrategyServiceProvider::class,
FeatureFlagQtiIdentifierServiceProvider::class,
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoQtiItem\model\FeatureFlag\ServiceProvider;

use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\featureFlag\FeatureFlagConfigSwitcher;
use oat\taoQtiItem\model\FeatureFlag\UniqueNumericQtiIdentifierClientConfig;
use oat\taoQtiItem\model\FeatureFlag\UniqueNumericQtiIdentifierQtiCreator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

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

class FeatureFlagQtiIdentifierServiceProvider implements ContainerServiceProviderInterface
{
public function __invoke(ContainerConfigurator $configurator): void
{
$services = $configurator->services();

$services
->set(UniqueNumericQtiIdentifierClientConfig::class)
->args(
[
service(FeatureFlagChecker::class),
]
)
->public();

$services
->set(UniqueNumericQtiIdentifierQtiCreator::class)
->args(
[
service(FeatureFlagChecker::class),
]
)
->public();

$services->get(FeatureFlagConfigSwitcher::class)
->call(
'addClientConfigHandler',
[
UniqueNumericQtiIdentifierClientConfig::class,
]
)->call(
'addExtensionConfigHandler',
[
'taoQtiItem',
'qtiCreator',
UniqueNumericQtiIdentifierQtiCreator::class
]
);
}
}
52 changes: 52 additions & 0 deletions model/FeatureFlag/UniqueNumericQtiIdentifierClientConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoQtiItem\model\FeatureFlag;

use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\featureFlag\FeatureFlagConfigHandlerInterface;

class UniqueNumericQtiIdentifierClientConfig implements FeatureFlagConfigHandlerInterface
{
public const QTI_ID_PATTERN = '/^[^\t\n\r]*$/';
public function __construct(FeatureFlagCheckerInterface $featureFlagChecker)
{
$this->featureFlagChecker = $featureFlagChecker;
}
public function __invoke(array $configs): array
{
if ($this->isEnabled()) {
$configs['taoQtiItem/qtiCreator/widgets/helpers/qtiIdentifier']['qtiIdPattern'] = self::QTI_ID_PATTERN;
$configs['taoQtiItem/qtiCreator/widgets/helpers/qtiIdentifier']['invalidQtiIdMessage'] =
'The QTI identifier must be a 9-digit number.';
$configs['taoQtiItem/qtiCreator/widgets/helpers/qtiIdentifier']['isDisabled'] = true;
}

return $configs;
}

private function isEnabled(): bool
{
return $this->featureFlagChecker
->isEnabled('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER');
}
}
51 changes: 51 additions & 0 deletions model/FeatureFlag/UniqueNumericQtiIdentifierQtiCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoQtiItem\model\FeatureFlag;

use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\featureFlag\FeatureFlagConfigHandlerInterface;

class UniqueNumericQtiIdentifierQtiCreator implements FeatureFlagConfigHandlerInterface
{
private FeatureFlagCheckerInterface $featureFlagChecker;

public function __construct(FeatureFlagCheckerInterface $featureFlagChecker)
{
$this->featureFlagChecker = $featureFlagChecker;
}

public function __invoke(array $configs): array
{
if ($this->isEnabled()) {
$configs['identifierGenerationStrategy'] = 'uniqueNumeric';
}

return $configs;
}

private function isEnabled(): bool
{
return $this->featureFlagChecker
->isEnabled('FEATURE_FLAG_UNIQUE_NUMERIC_QTI_IDENTIFIER');
}
}
12 changes: 12 additions & 0 deletions model/qti/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use oat\taoQtiItem\model\qti\metadata\MetadataGuardianResource;
use oat\taoQtiItem\model\qti\metadata\MetadataService;
use oat\taoQtiItem\model\qti\metadata\ontology\MappedMetadataInjector;
use oat\taoQtiItem\model\qti\parser\UniqueNumericQtiIdentifierReplacer;
use oat\taoQtiItem\model\qti\parser\ValidationException;
use oat\taoQtiItem\model\event\ItemImported;
use qtism\data\QtiComponentCollection;
Expand Down Expand Up @@ -187,6 +188,7 @@ protected function createRdfItem(core_kernel_classes_Class $itemClass, Item $qti
protected function createQtiItemModel($qtiFile, $validate = true)
{
$qtiXml = Authoring::sanitizeQtiXml($qtiFile);
$qtiXml = $this->replaceUniqueNumericQtiIdentifier($qtiXml);
//validate the file to import
$qtiParser = new Parser($qtiXml);

Expand Down Expand Up @@ -952,4 +954,14 @@ private function getMetaMetadataImportMapper(): MetaMetadataImportMapper
{
return $this->getServiceManager()->getContainer()->get(MetaMetadataImportMapper::class);
}

private function getUniqueNumericQtiIdentifierReplacer(): UniqueNumericQtiIdentifierReplacer
{
return $this->getServiceManager()->getContainer()->get(UniqueNumericQtiIdentifierReplacer::class);
}

private function replaceUniqueNumericQtiIdentifier(string $qtiXml): string
{
return $this->getUniqueNumericQtiIdentifierReplacer()->replace($qtiXml);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoQtiItem\model\qti\ServiceProvider;

use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use common_ext_ExtensionsManager as ExtensionsManager;
use oat\taoQtiItem\helpers\QtiXmlLoader;
use oat\taoQtiItem\model\qti\identifierGenerator\IdentifierGenerator;
use oat\taoQtiItem\model\qti\identifierGenerator\UniqueNumericQtiIdentifierGenerator;
use oat\taoQtiItem\model\qti\parser\UniqueNumericQtiIdentifierReplacer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

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

class IdentifierGenerationStrategyServiceProvider implements ContainerServiceProviderInterface
{
public function __invoke(ContainerConfigurator $configurator): void
{
$services = $configurator->services();

$services->set(QtiXmlLoader::class, QtiXmlLoader::class)
->args([
service(ExtensionsManager::SERVICE_ID)
]);

$services->set(IdentifierGenerator::class, UniqueNumericQtiIdentifierGenerator::class)
->public();

$services->set(UniqueNumericQtiIdentifierReplacer::class, UniqueNumericQtiIdentifierReplacer::class)
->args([
service(FeatureFlagChecker::class),
service(QtiXmlLoader::class),
service(IdentifierGenerator::class)
])
->public();
}
}
Loading

0 comments on commit 74342b8

Please sign in to comment.