-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
957 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
model/FeatureFlag/ServiceProvider/FeatureFlagQtiIdentifierServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
model/FeatureFlag/UniqueNumericQtiIdentifierClientConfig.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
model/FeatureFlag/UniqueNumericQtiIdentifierQtiCreator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
model/qti/ServiceProvider/IdentifierGenerationStrategyServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.