Skip to content

Commit

Permalink
Merge pull request #2533 from oat-sa/backport/AUT-3985/test-label
Browse files Browse the repository at this point in the history
Backport Metadata Import/Import fixes
  • Loading branch information
bartlomiejmarszal authored Nov 22, 2024
2 parents 512dab6 + 4212a02 commit 3d2fb16
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions models/classes/class.QtiTestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,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 = $packageLabel ?? $testDefinition->getDocumentComponent()->getTitle();
$testLabel = $packageLabel ?? $this->getTestLabel($reportCtx->testMetadata);

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

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

// 4. Import metadata for the resource (use same mechanics as item resources).
// Metadata will be set as property values.
Expand Down Expand Up @@ -1552,4 +1551,26 @@ private function getMappedProperties(

return [];
}

private function getIdentifierGenerator(): ?IdentifierGeneratorInterface
{
try {
return $this->getPsrContainer()->get(IdentifierGeneratorProxy::class);
} catch (Throwable $exception) {
return null;
}
}

private function getTestLabel(array $testMetadata): string
{
$labelMetadata = array_filter($testMetadata, function ($metadata) {
return in_array(RDFS_LABEL, $metadata->getPath());
});

if (count($labelMetadata) > 1) {
common_Logger::w('Multiple labels found for test. Using the first one.');
}

return reset($labelMetadata)->getValue();
}
}

0 comments on commit 3d2fb16

Please sign in to comment.