Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Assessment Title as Label when no metadata included #2535

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions models/classes/class.QtiTestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ protected function importTest(

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

if ($overwriteTestUri || $overwriteTest) {
$itemsClassLabel = $testLabel;
Expand Down Expand Up @@ -1571,12 +1571,21 @@ private function createTestIdentifier(core_kernel_classes_Resource $test): strin
return str_replace('_', '-', Format::sanitizeIdentifier($identifier));
}

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

if (empty($labelMetadata)) {
if ($testDefinition->getDocumentComponent() === null) {
throw new Exception('No metadata label found for test and no title in the test definition.');
}

common_Logger::w('No metadata label found for test. Using the title from the test definition.');
return $testDefinition->getDocumentComponent()->getTitle();
}

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