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

feat: place imported assets to correct class #2409

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
32 changes: 19 additions & 13 deletions models/classes/class.QtiTestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class taoQtiTest_models_classes_QtiTestService extends TestService
public const XML_TEST_PART = 'testPart';
public const XML_ASSESSMENT_SECTION = 'assessmentSection';
public const XML_ASSESSMENT_ITEM_REF = 'assessmentItemRef';

private const IN_PROGRESS_LABEL = 'in progress';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think LABEL_IN_PROGESS is better, because then you would just add another LABEL_ and everything would be in same code block

Copy link
Contributor Author

@pnal pnal Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text for the label when status is in progress: 'in progress' status label IN_PROGRESS_LABEL
For me sounds more clear than: label for 'in progress' status - more context dropped


/**
* @var MetadataImporter Service to manage Lom metadata during package import
*/
Expand Down Expand Up @@ -518,7 +521,7 @@ public function clearRelatedResources(common_report_Report $report): void
/**
* Import a QTI Test and its dependent Items into the TAO Platform.
*
* @param core_kernel_classes_Class $targetClass The RDFS Class where Ontology resources must be created.
* @param core_kernel_classes_Class $testClass The RDFS Class where Ontology resources must be created.
* @param oat\taoQtiItem\model\qti\Resource $qtiTestResource The QTI Test Resource representing the IMS QTI Test to
* be imported.
* @param taoQtiTest_models_classes_ManifestParser $manifestParser The parser used to retrieve the IMS Manifest.
Expand All @@ -528,7 +531,7 @@ public function clearRelatedResources(common_report_Report $report): void
* @return common_report_Report A report about how the importation behaved.
*/
protected function importTest(
core_kernel_classes_Class $targetClass,
core_kernel_classes_Class $testClass,
Resource $qtiTestResource,
taoQtiTest_models_classes_ManifestParser $manifestParser,
$folder,
Expand All @@ -538,12 +541,11 @@ protected function importTest(
) {
/** @var ImportService $itemImportService */
$itemImportService = $this->getServiceLocator()->get(ImportService::SERVICE_ID);
$testClass = $targetClass;
$qtiTestResourceIdentifier = $qtiTestResource->getIdentifier();

// Create an RDFS resource in the knowledge base that will hold
// the information about the imported QTI Test.
$testResource = $this->createInstance($testClass, 'in progress');
$testResource = $this->createInstance($testClass, self::IN_PROGRESS_LABEL);
$qtiTestModelResource = $this->getResource(self::INSTANCE_TEST_MODEL_QTI);
$modelProperty = $this->getProperty(TestService::PROPERTY_TEST_TESTMODEL);
$testResource->editPropertyValues($modelProperty, $qtiTestModelResource);
Expand All @@ -557,7 +559,7 @@ protected function importTest(
$report = new common_report_Report(common_report_Report::TYPE_INFO);

// The class where the items that belong to the test will be imported.
$itemClass = $this->getClass($itemClassUri ?: TaoOntology::CLASS_URI_ITEM);
$itemParentClass = $this->getClass($itemClassUri ?: TaoOntology::CLASS_URI_ITEM);

// Load and validate the manifest
$qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml');
Expand Down Expand Up @@ -608,9 +610,9 @@ 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();

if ($overwriteTest) {
$testLabel = $testDefinition->getDocumentComponent()->getTitle();
$itemsClassLabel = $testLabel;
/** @var oat\taoQtiItem\model\qti\metadata\simple\SimpleMetadataValue $m */
foreach ($reportCtx->testMetadata as $singleMetadata) {
Expand All @@ -619,11 +621,15 @@ protected function importTest(
}
}

$this->deleteTestsFromClassByLabel($testLabel, $itemsClassLabel, $testClass, $itemClass);
$this->deleteTestsFromClassByLabel($testLabel, $itemsClassLabel, $testClass, $itemParentClass);
}

$targetClass = $itemClass->createSubClass($testResource->getLabel());
$reportCtx->itemClass = $targetClass;
$targetItemClass = $itemParentClass->createSubClass(self::IN_PROGRESS_LABEL);

// add real label without saving (to not pass it separately to item importer)
$targetItemClass->label = $testLabel;

$reportCtx->itemClass = $targetItemClass;
// -- Load all items related to test.
$itemError = false;

Expand Down Expand Up @@ -682,7 +688,7 @@ protected function importTest(
$itemReport = $itemImportService->importQtiItem(
$folder,
$qtiDependency,
$targetClass,
$targetItemClass,
$sharedFiles,
$dependencies['dependencies'],
$metadataValues,
Expand Down Expand Up @@ -769,7 +775,7 @@ protected function importTest(

// 3. Give meaningful names to resources.
$testResource->setLabel($testDefinition->getDocumentComponent()->getTitle());
$targetClass->setLabel($testDefinition->getDocumentComponent()->getTitle());
$targetItemClass->setLabel($testDefinition->getDocumentComponent()->getTitle());

// 4. Import metadata for the resource (use same mechanics as item resources).
// Metadata will be set as property values.
Expand All @@ -778,8 +784,8 @@ protected function importTest(
// 5. if $targetClass does not contain any instances
// (because everything resolved by class lookups),
// Just delete it.
if ($targetClass->countInstances() == 0) {
$targetClass->delete();
if ($targetItemClass->countInstances() == 0) {
$targetItemClass->delete();
}
}
} else {
Expand Down
Loading