Skip to content

Commit

Permalink
chore: add custom packageLabel param
Browse files Browse the repository at this point in the history
  • Loading branch information
shpran committed Aug 8, 2024
1 parent b1e7ae0 commit d50a809
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
24 changes: 22 additions & 2 deletions actions/class.RestQtiTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class taoQtiTest_actions_RestQtiTests extends AbstractRestQti

private const SUBCLASS_LABEL = 'subclassLabel';
private const OVERWRITE_TEST_URI = 'overwriteTestUri';
private const PACKAGE_LABEL = 'packageLabel';

/**
* @throws common_exception_NotImplemented
Expand Down Expand Up @@ -109,7 +110,8 @@ public function import()
$this->isItemMustBeOverwrittenEnabled(),
$this->isOverwriteTest(),
$this->getItemClassUri(),
$this->getOverwriteTestUri()
$this->getOverwriteTestUri(),
$this->getPackageLabel()
);

if ($report->getType() === common_report_Report::TYPE_SUCCESS) {
Expand Down Expand Up @@ -198,7 +200,8 @@ public function importDeferred()
$this->isItemMustBeOverwrittenEnabled(),
$this->isOverwriteTest(),
$this->getItemClassUri(),
$this->getOverwriteTestUri()
$this->getOverwriteTestUri(),
$this->getPackageLabel()
);

$result = [
Expand Down Expand Up @@ -352,6 +355,23 @@ private function getOverwriteTestUri(): ?string
return $overwriteTestUri;
}

/**
* @return string|null
* @throws common_exception_RestApi
*/
private function getPackageLabel(): ?string
{
$packageLabel = $this->getPostParameter(self::PACKAGE_LABEL);

if ($packageLabel !== null && !is_string($packageLabel)) {
throw new common_exception_RestApi(
sprintf('%s parameter should be string', self::PACKAGE_LABEL)
);
}

return $packageLabel;
}

/**
* Get class instance to import test
*
Expand Down
6 changes: 4 additions & 2 deletions models/classes/class.CrudQtiTestsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function importQtiTest(
$itemMustBeOverwritten = false,
bool $overwriteTest = false,
?string $itemClassUri = null,
?string $overwriteTestUri = null
?string $overwriteTestUri = null,
?string $packageLabel = null
) {
try {
//The zip extraction is a long process that can exceed the 30s timeout
Expand Down Expand Up @@ -98,7 +99,8 @@ public function importQtiTest(
$overwriteTest,
$itemClassUri,
[],
$overwriteTestUri
$overwriteTestUri,
$packageLabel
);
helpers_TimeOutHelper::reset();

Expand Down
16 changes: 10 additions & 6 deletions models/classes/class.QtiTestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ public function importMultipleTests(
bool $overwriteTest = false,
?string $itemClassUri = null,
array $form = [],
?string $overwriteTestUri = null
?string $overwriteTestUri = null,
?string $packageLabel = null
) {
$testClass = $targetClass;
$report = new common_report_Report(common_report_Report::TYPE_INFO);
Expand Down Expand Up @@ -427,7 +428,8 @@ public function importMultipleTests(
$overwriteTest,
$itemClassUri,
!empty($form[TestImportForm::METADATA_FORM_ELEMENT_NAME]) ?? false,
$overwriteTestUri
$overwriteTestUri,
$packageLabel
);
$report->add($importTestReport);

Expand Down Expand Up @@ -549,7 +551,8 @@ protected function importTest(
bool $overwriteTest = false,
?string $itemClassUri = null,
bool $importMetadata = false,
?string $overwriteTestUri = null
?string $overwriteTestUri = null,
?string $packageLabel = null
) {
/** @var ImportService $itemImportService */
$itemImportService = $this->getServiceLocator()->get(ImportService::SERVICE_ID);
Expand Down Expand Up @@ -623,7 +626,7 @@ protected function importTest(

// If any, assessmentSectionRefs will be resolved and included as part of the main test definition.
$testDefinition->includeAssessmentSectionRefs(true);
$testLabel = $testDefinition->getDocumentComponent()->getTitle();
$testLabel = $packageLabel ?? $testDefinition->getDocumentComponent()->getTitle();

if ($overwriteTestUri || $overwriteTest) {
$itemsClassLabel = $testLabel;
Expand Down Expand Up @@ -801,8 +804,9 @@ protected function importTest(
$this->importTestAuxiliaryFiles($testContent, $qtiTestResource, $folder, $report);

// 3. Give meaningful names to resources.
$testResource->setLabel($testDefinition->getDocumentComponent()->getTitle());
$targetItemClass->setLabel($reportCtx->itemClass->getLabel());
$definitionTitle = $testDefinition->getDocumentComponent()->getTitle();
$testResource->setLabel($packageLabel ?? $definitionTitle);
$targetItemClass->setLabel($packageLabel ?? $definitionTitle);

// 4. Import metadata for the resource (use same mechanics as item resources).
// Metadata will be set as property values.
Expand Down
7 changes: 5 additions & 2 deletions models/classes/import/QtiTestImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class QtiTestImporter extends AbstractTestImporter
* @param bool $overwriteTest
* @param string|null $itemClassUri
* @param string|null $overwriteTestUri
* @param string|null $packageLabel
* @return common_report_Report
*/
public function import(
Expand All @@ -57,7 +58,8 @@ public function import(
$itemMustBeOverwritten = false,
bool $overwriteTest = false,
?string $itemClassUri = null,
?string $overwriteTestUri = null
?string $overwriteTestUri = null,
?string $packageLabel = null
) {
return taoQtiTest_models_classes_CrudQtiTestsService::singleton()->importQtiTest(
$file,
Expand All @@ -68,7 +70,8 @@ public function import(
$itemMustBeOverwritten,
$overwriteTest,
$itemClassUri,
$overwriteTestUri
$overwriteTestUri,
$packageLabel
);
}
}
6 changes: 5 additions & 1 deletion models/classes/tasks/ImportQtiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ImportQtiTest extends AbstractTaskAction implements \JsonSerializable
*/
public const PARAM_OVERWRITE_TEST = 'overwrite_test';
public const PARAM_OVERWRITE_TEST_URI = 'overwrite_test_uri';
public const PARAM_PACKAGE_LABEL = 'package_label';

protected $service;

Expand Down Expand Up @@ -95,6 +96,7 @@ public function __invoke($params)
$params[self::PARAM_OVERWRITE_TEST] ?? false,
$params[self::PARAM_ITEM_CLASS_URI] ?? false,
$params[self::PARAM_OVERWRITE_TEST_URI] ?? null,
$params[self::PARAM_PACKAGE_LABEL] ?? null,
);

return $report;
Expand Down Expand Up @@ -128,7 +130,8 @@ public static function createTask(
$itemMustBeOverwritten = false,
bool $overwriteTest = false,
?string $itemClassUri = null,
?string $overwriteTestUri = null
?string $overwriteTestUri = null,
?string $packageLabel = null
) {
$action = new self();
$action->setServiceLocator(ServiceManager::getServiceManager());
Expand All @@ -150,6 +153,7 @@ public static function createTask(
self::PARAM_OVERWRITE_TEST => $overwriteTest,
self::PARAM_ITEM_CLASS_URI => $itemClassUri,
self::PARAM_OVERWRITE_TEST_URI => $overwriteTestUri,
self::PARAM_PACKAGE_LABEL => $packageLabel,
],
__('Import QTI TEST into "%s"', $class->getLabel())
);
Expand Down

0 comments on commit d50a809

Please sign in to comment.