Skip to content

Commit

Permalink
Merge branch 'release-48.14.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Nov 11, 2024
2 parents e8dcffb + d5f7ffc commit cf4b996
Show file tree
Hide file tree
Showing 54 changed files with 2,789 additions and 361 deletions.
54 changes: 30 additions & 24 deletions actions/class.Creator.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*/
* 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) 2013-2024 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*/

use oat\taoQtiTest\models\TestCategoryPresetProvider;
use oat\taoQtiTest\models\TestModelService;
Expand Down Expand Up @@ -45,6 +45,11 @@ public function index()
$testUri = $this->getRequestParameter('uri');
$testModel = $this->getServiceManager()->get(TestModelService::SERVICE_ID);

// Add support for translation and side-by-side view
$originResourceUri = $this->getRequestParameter('originResourceUri');
$this->setData('translation', $this->getRequestParameter('translation') ?? "false");
$this->setData('originResourceUri', json_encode($originResourceUri));

$items = $testModel->getItems(new core_kernel_classes_Resource(tao_helpers_Uri::decode($testUri)));
foreach ($items as $item) {
$labels[$item->getUri()] = $item->getLabel();
Expand All @@ -59,6 +64,7 @@ public function index()
$this->setData('categoriesPresets', json_encode($categoriesPresetService->getAvailablePresets($runtimeConfig)));

$this->setData('loadUrl', _url('getTest', null, null, ['uri' => $testUri]));
$this->setData('loadOriginUrl', _url('getTest', null, null, ['uri' => $originResourceUri]));
$this->setData('saveUrl', _url('saveTest', null, null, ['uri' => $testUri]));

if (common_ext_ExtensionsManager::singleton()->isInstalled('taoBlueprints')) {
Expand Down Expand Up @@ -91,9 +97,9 @@ public function index()
$this->setView('creator.tpl');
}

/**
* Get json's test content, the uri of the test must be provided in parameter
*/
/**
* Get json's test content, the uri of the test must be provided in parameter
*/
public function getTest()
{
$test = $this->getCurrentTest();
Expand All @@ -104,11 +110,11 @@ public function getTest()
$this->response = $this->getPsrResponse()->withBody(stream_for($qtiTestService->getJsonTest($test)));
}

/**
* Save a test, test uri and
* The request must use the POST method and contains
* the test uri and a json string that represents the QTI Test in the model parameter.
*/
/**
* Save a test, test uri and
* The request must use the POST method and contains
* the test uri and a json string that represents the QTI Test in the model parameter.
*/
public function saveTest()
{
$saved = false;
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
"oat-sa/lib-test-cat": "2.4.0",
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"qtism/qtism": ">=0.28.3",
"oat-sa/generis": ">=15.36.4",
"oat-sa/tao-core": ">=54.21.0",
"oat-sa/extension-tao-item" : ">=12.1.0",
"oat-sa/extension-tao-itemqti" : ">=30.12.0",
"oat-sa/extension-tao-test" : ">=16.0.0",
"oat-sa/extension-tao-delivery" : ">=15.0.0",
"oat-sa/extension-tao-outcome" : ">=13.0.0",
"oat-sa/generis": ">=15.39.0",
"oat-sa/tao-core": ">=54.23.0",
"oat-sa/extension-tao-item": ">=12.4.0",
"oat-sa/extension-tao-itemqti": ">=30.22.0",
"oat-sa/extension-tao-test": ">=16.3.0",
"oat-sa/extension-tao-delivery": ">=15.0.0",
"oat-sa/extension-tao-outcome": ">=13.0.0",
"league/flysystem": "~1.0",
"slim/slim": "^3.0"
},
Expand Down
17 changes: 12 additions & 5 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,28 @@
*
* Copyright (c) 2013-2019 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* phpcs:disable Generic.Files.LineLength
*/

use oat\tao\model\user\TaoRoles;
use oat\taoQtiTest\model\Container\TestQtiServiceProvider;
use oat\taoQtiTest\models\classes\metadata\MetadataServiceProvider;
// phpcs:disable Generic.Files.LineLength
use oat\taoQtiTest\models\classes\render\CustomInteraction\ServiceProvider\CustomInteractionPostProcessingServiceProvider;
// phpcs:enable Generic.Files.LineLength
use oat\taoQtiTest\models\IdentifierGenerator\ServiceProvider\IdentifierGeneratorServiceProvider;
use oat\taoQtiTest\models\Qti\ServiceProvider\QtiServiceProvider;
use oat\taoQtiTest\models\render\ItemsReferencesServiceProvider;
use oat\taoQtiTest\models\TestSessionState\Container\TestSessionStateServiceProvider;
use oat\taoQtiTest\models\Translation\ServiceProvider\TranslationServiceProvider;
use oat\taoQtiTest\models\UniqueId\ServiceProvider\UniqueIdServiceProvider;
use oat\taoQtiTest\models\xmlEditor\XmlEditorInterface;
use oat\taoQtiTest\scripts\install\RegisterResultTransmissionEventHandlers;
use oat\taoQtiTest\scripts\install\SetupProvider;
use oat\taoQtiTest\scripts\install\CreateTestSessionFilesystem;
use oat\taoQtiTest\scripts\install\DisableBRSinTestAuthoring;
use oat\taoQtiTest\scripts\install\RegisterCreatorServices;
use oat\taoQtiTest\scripts\install\RegisterFrontendPaths;
use oat\taoQtiTest\scripts\install\RegisterQtiCategoryPresetProviders;
use oat\taoQtiTest\scripts\install\RegisterQtiFlysystemManager;
use oat\taoQtiTest\scripts\install\RegisterQtiPackageExporter;
use oat\taoQtiTest\scripts\install\RegisterResultTransmissionEventHandlers;
use oat\taoQtiTest\scripts\install\RegisterSectionPauseService;
use oat\taoQtiTest\scripts\install\RegisterTestCategoryPresetProviderService;
use oat\taoQtiTest\scripts\install\RegisterTestContainer;
Expand All @@ -50,6 +52,7 @@
use oat\taoQtiTest\scripts\install\SetSynchronisationService;
use oat\taoQtiTest\scripts\install\SetupDefaultTemplateConfiguration;
use oat\taoQtiTest\scripts\install\SetupEventListeners;
use oat\taoQtiTest\scripts\install\SetupProvider;
use oat\taoQtiTest\scripts\install\SetUpQueueTasks;
use oat\taoQtiTest\scripts\install\SetupStateOffloadQueue;
use oat\taoQtiTest\scripts\install\SyncChannelInstaller;
Expand Down Expand Up @@ -185,6 +188,10 @@
ItemsReferencesServiceProvider::class,
TestQtiServiceProvider::class,
TestSessionStateServiceProvider::class,
MetadataServiceProvider::class
MetadataServiceProvider::class,
TranslationServiceProvider::class,
UniqueIdServiceProvider::class,
IdentifierGeneratorServiceProvider::class,
QtiServiceProvider::class,
],
];
74 changes: 74 additions & 0 deletions migrations/Version202409111328132261_taoQtiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace oat\taoQtiTest\migrations;

use Doctrine\DBAL\Schema\Schema;
use oat\oatbox\event\EventManager;
use oat\tao\model\resources\Event\InstanceCopiedEvent;
use oat\tao\scripts\tools\migrations\AbstractMigration;
use oat\taoQtiTest\models\classes\event\TestImportedEvent;
use oat\taoQtiTest\models\UniqueId\Listener\TestCreationListener;
use oat\taoTests\models\event\TestCreatedEvent;
use oat\taoTests\models\event\TestDuplicatedEvent;

/**
* phpcs:disable Squiz.Classes.ValidClassName
*/
final class Version202409111328132261_taoQtiTest extends AbstractMigration
{
public function getDescription(): string
{
return 'Add new listener to populate translation properties';
}

public function up(Schema $schema): void
{
/** @var EventManager $eventManager */
$eventManager = $this->getServiceManager()->get(EventManager::SERVICE_ID);

$eventManager->attach(
TestCreatedEvent::class,
[TestCreationListener::class, 'populateUniqueId']
);
$eventManager->attach(
TestDuplicatedEvent::class,
[TestCreationListener::class, 'populateUniqueId']
);
$eventManager->attach(
TestImportedEvent::class,
[TestCreationListener::class, 'populateUniqueId']
);
$eventManager->attach(
InstanceCopiedEvent::class,
[TestCreationListener::class, 'populateUniqueId']
);

$this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager);
}

public function down(Schema $schema): void
{
/** @var EventManager $eventManager */
$eventManager = $this->getServiceManager()->get(EventManager::SERVICE_ID);

$eventManager->detach(
TestCreatedEvent::class,
[TestCreationListener::class, 'populateUniqueId']
);
$eventManager->detach(
TestDuplicatedEvent::class,
[TestCreationListener::class, 'populateUniqueId']
);
$eventManager->detach(
TestImportedEvent::class,
[TestCreationListener::class, 'populateUniqueId']
);
$eventManager->detach(
InstanceCopiedEvent::class,
[TestCreationListener::class, 'populateUniqueId']
);
$this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace oat\taoQtiTest\models\IdentifierGenerator\Generator;

use core_kernel_classes_Resource;
use InvalidArgumentException;
use oat\generis\model\data\Ontology;
use oat\tao\model\IdentifierGenerator\Generator\IdentifierGeneratorInterface;
use qtism\common\utils\Format;

class QtiIdentifierGenerator implements IdentifierGeneratorInterface
{
private Ontology $ontology;

public function __construct(Ontology $ontology)
{
$this->ontology = $ontology;
}

public function generate(array $options = []): string
{
$resource = $this->getResource($options);
$label = $resource->getLabel();

$identifier = null;

if (preg_match('/^\d/', $label)) {
$identifier = 't_' . $label;
}

return str_replace('_', '-', Format::sanitizeIdentifier($identifier));
}

private function getResource(array $options): core_kernel_classes_Resource
{
if (isset($options[self::OPTION_RESOURCE_ID]) && is_string($options[self::OPTION_RESOURCE_ID])) {
return $this->ontology->getResource($options[self::OPTION_RESOURCE_ID]);
}

if (
isset($options[self::OPTION_RESOURCE])
&& $options[self::OPTION_RESOURCE] instanceof core_kernel_classes_Resource
) {
return $options[self::OPTION_RESOURCE];
}

throw new InvalidArgumentException(
'Test QTI Identifier generation failure: resource is required'
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace oat\taoQtiTest\models\IdentifierGenerator\ServiceProvider;

use oat\generis\model\data\Ontology;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\tao\model\IdentifierGenerator\Generator\IdentifierGeneratorProxy;
use oat\tao\model\TaoOntology;
use oat\taoQtiTest\models\IdentifierGenerator\Generator\QtiIdentifierGenerator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

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

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

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

$services
->get(IdentifierGeneratorProxy::class)
->call(
'addIdentifierGenerator',
[
service(QtiIdentifierGenerator::class),
TaoOntology::CLASS_URI_TEST,
]
);
}
}
50 changes: 50 additions & 0 deletions models/classes/Qti/Identifier/Service/QtiIdentifierSetter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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\taoQtiTest\models\Qti\Identifier\Service;

use oat\tao\model\Translation\Service\AbstractQtiIdentifierSetter;
use Psr\Log\LoggerInterface;
use taoQtiTest_models_classes_QtiTestService;

class QtiIdentifierSetter extends AbstractQtiIdentifierSetter
{
private taoQtiTest_models_classes_QtiTestService $qtiTestService;

public function __construct(taoQtiTest_models_classes_QtiTestService $qtiTestService, LoggerInterface $logger)
{
parent::__construct($logger);

$this->qtiTestService = $qtiTestService;
}

protected function applyIdentifier(array $options): void
{
$test = $this->getResource($options);
$jsonTest = $this->qtiTestService->getJsonTest($test);

$decodedTest = json_decode($jsonTest, true, 512, JSON_THROW_ON_ERROR);
$decodedTest['identifier'] = $this->getIdentifier($options);

$this->qtiTestService->saveJsonTest($test, json_encode($decodedTest));
}
}
Loading

0 comments on commit cf4b996

Please sign in to comment.