From ae7660443f817906ff29d2179095ccd4f30cf6da Mon Sep 17 00:00:00 2001 From: Nikita Pimenov Date: Tue, 3 Oct 2023 18:29:50 +0400 Subject: [PATCH 1/2] feat: place imported assets to correct class --- models/classes/class.QtiTestService.php | 32 +++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/models/classes/class.QtiTestService.php b/models/classes/class.QtiTestService.php index 990e9fdfc..1a91dac19 100644 --- a/models/classes/class.QtiTestService.php +++ b/models/classes/class.QtiTestService.php @@ -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'; + /** * @var MetadataImporter Service to manage Lom metadata during package import */ @@ -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. @@ -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, @@ -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); @@ -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); + $itemRootClass = $this->getClass($itemClassUri ?: TaoOntology::CLASS_URI_ITEM); // Load and validate the manifest $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml'); @@ -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) { @@ -619,11 +621,15 @@ protected function importTest( } } - $this->deleteTestsFromClassByLabel($testLabel, $itemsClassLabel, $testClass, $itemClass); + $this->deleteTestsFromClassByLabel($testLabel, $itemsClassLabel, $testClass, $itemRootClass); } - $targetClass = $itemClass->createSubClass($testResource->getLabel()); - $reportCtx->itemClass = $targetClass; + $targetItemClass = $itemRootClass->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; @@ -682,7 +688,7 @@ protected function importTest( $itemReport = $itemImportService->importQtiItem( $folder, $qtiDependency, - $targetClass, + $targetItemClass, $sharedFiles, $dependencies['dependencies'], $metadataValues, @@ -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. @@ -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 { From 5021010ad69afeed4d0010d2c4986bc29a52d4b8 Mon Sep 17 00:00:00 2001 From: Nikita Pimenov Date: Wed, 4 Oct 2023 15:08:38 +0400 Subject: [PATCH 2/2] refactor: variable name --- models/classes/class.QtiTestService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/classes/class.QtiTestService.php b/models/classes/class.QtiTestService.php index 1a91dac19..a3d6339a4 100644 --- a/models/classes/class.QtiTestService.php +++ b/models/classes/class.QtiTestService.php @@ -559,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. - $itemRootClass = $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'); @@ -621,10 +621,10 @@ protected function importTest( } } - $this->deleteTestsFromClassByLabel($testLabel, $itemsClassLabel, $testClass, $itemRootClass); + $this->deleteTestsFromClassByLabel($testLabel, $itemsClassLabel, $testClass, $itemParentClass); } - $targetItemClass = $itemRootClass->createSubClass(self::IN_PROGRESS_LABEL); + $targetItemClass = $itemParentClass->createSubClass(self::IN_PROGRESS_LABEL); // add real label without saving (to not pass it separately to item importer) $targetItemClass->label = $testLabel;