diff --git a/models/classes/Qti/Converter/TestConverter.php b/models/classes/Qti/Converter/TestConverter.php new file mode 100644 index 000000000..a2ae12d46 --- /dev/null +++ b/models/classes/Qti/Converter/TestConverter.php @@ -0,0 +1,35 @@ +set(TestConverter::class) + ->args([ + service(CaseConversionService::class), + ]) + ->public(); } } diff --git a/models/classes/class.QtiTestService.php b/models/classes/class.QtiTestService.php index 53ca7f396..d9ddd5545 100644 --- a/models/classes/class.QtiTestService.php +++ b/models/classes/class.QtiTestService.php @@ -1,5 +1,4 @@ verifyItemPermissions($test, $json); $doc = $this->getDoc($test); @@ -266,7 +268,7 @@ public function setItems(core_kernel_classes_Resource $test, array $items) return false; } - /** + /** * Save the QTI test : set the items sequence and some options. * * @param core_kernel_classes_Resource $test A Resource describing a QTI Assessment Test. @@ -280,7 +282,7 @@ public function save(core_kernel_classes_Resource $test, array $items) try { $doc = $this->getDoc($test); $this->setItemsToDoc($doc, $items); - $saved = $this->saveDoc($test, $doc); + $saved = $this->saveDoc($test, $doc); } catch (StorageException $e) { throw new taoQtiTest_models_classes_QtiTestServiceException( "An error occured while dealing with the QTI-XML test: " . $e->getMessage(), @@ -306,7 +308,7 @@ public function getIdentifierFor(XmlDocument $doc, $qtiType) do { $identifier = $this->generateIdentifier($doc, $qtiType, $index); $index++; - } while (! $this->isIdentifierUnique($components, $identifier)); + } while (!$this->isIdentifierUnique($components, $identifier)); return $identifier; } @@ -363,7 +365,7 @@ public function importMultipleTests( ?string $packageLabel = null ) { $testClass = $targetClass; - $report = new common_report_Report(common_report_Report::TYPE_INFO); + $report = new Report(Report::TYPE_INFO); $validPackage = false; $validManifest = false; $testsFound = false; @@ -381,24 +383,25 @@ public function importMultipleTests( // phpcs:enable Generic.Files.LineLength try { - $qtiPackageParser = new taoQtiTest_models_classes_PackageParser($file); + $qtiPackageParser = new PackageParser($file); $qtiPackageParser->validate(); $validPackage = true; } catch (Exception $e) { - $report->add(common_report_Report::createFailure($invalidArchiveMsg)); + $report->add(Report::createError($invalidArchiveMsg)); } // Validate the manifest (well formed XML, valid against the schema). if ($validPackage === true) { $folder = $qtiPackageParser->extract(); - if (is_dir($folder) === false) { - $report->add(common_report_Report::createFailure($invalidArchiveMsg)); + $report->add(Report::createError($invalidArchiveMsg)); } else { - $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml'); + $file = $folder . 'imsmanifest.xml'; + $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($file); $this->propagate($qtiManifestParser); + $this->getManifestConverter()->convert($file, $qtiManifestParser); + // We validate manifest file against QTI 3.0 $qtiManifestParser->validate(); - if ($qtiManifestParser->isValid() === true) { $validManifest = true; @@ -411,10 +414,10 @@ public function importMultipleTests( if ($testsFound !== true) { $report->add( - common_report_Report::createFailure( - // phpcs:disable Generic.Files.LineLength + Report::createError( + // phpcs:disable Generic.Files.LineLength __("Package is valid but no tests were found. Make sure that it contains valid QTI tests.") - // phpcs:enable Generic.Files.LineLength + // phpcs:enable Generic.Files.LineLength ) ); } else { @@ -577,12 +580,11 @@ protected function importTest( // Create the report that will hold information about the import // of $qtiTestResource in TAO. - $report = new common_report_Report(common_report_Report::TYPE_INFO); + $report = new Report(Report::TYPE_INFO); // Load and validate the manifest $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml'); $this->propagate($qtiManifestParser); - $qtiManifestParser->validate(); $domManifest = new DOMDocument('1.0', 'UTF-8'); $domManifest->load($folder . 'imsmanifest.xml'); @@ -620,6 +622,8 @@ protected function importTest( ) ); } else { + //Convert to QTI 2.2 + $this->getTestConverter()->convert($expectedTestFile); // -- Load the test in a QTISM flavour. $testDefinition = new XmlDocument(); @@ -1079,7 +1083,6 @@ public function getTestFile(core_kernel_classes_Resource $test) */ public function getDoc(core_kernel_classes_Resource $test) { - $doc = new XmlDocument('2.1'); $doc->loadFromString($this->getQtiTestFile($test)->read()); return $doc; @@ -1433,7 +1436,7 @@ public function getQtiTestTemplateFileAsString() */ protected function getMetadataImporter() { - if (! $this->metadataImporter) { + if (!$this->metadataImporter) { $this->metadataImporter = $this->getServiceLocator()->get(MetadataService::SERVICE_ID)->getImporter(); } return $this->metadataImporter; @@ -1601,4 +1604,14 @@ private function getTestLabel(array $testMetadata, XmlDocument $testDefinition): return reset($labelMetadata)->getValue(); } + + private function getManifestConverter(): ManifestConverter + { + return $this->getPsrContainer()->get(ManifestConverter::class); + } + + private function getTestConverter(): TestConverter + { + return $this->getPsrContainer()->get(TestConverter::class); + } } diff --git a/models/classes/render/QTI3PackagePreprocessing.php b/models/classes/render/QTI3PackagePreprocessing.php new file mode 100644 index 000000000..eda114cdb --- /dev/null +++ b/models/classes/render/QTI3PackagePreprocessing.php @@ -0,0 +1,51 @@ +read(); + $this->getZip()->open(); + $content = str_replace( + 'http://www.imsglobal.org/xsd/imsqtiasi_v3p0', + 'http://www.imsglobal.org/xsd/imscp_v1p1', + $content + ); + + $file->write($content); + + return new Report(Report::TYPE_INFO, 'QTI3 package preprocessing done'); + } + + private function getZip(): ZipArchive + { + return new ZipArchive(); + } +} diff --git a/views/js/controller/creator/templates/itemref-props.tpl b/views/js/controller/creator/templates/itemref-props.tpl index 24d490642..e82f9f32c 100644 --- a/views/js/controller/creator/templates/itemref-props.tpl +++ b/views/js/controller/creator/templates/itemref-props.tpl @@ -135,10 +135,10 @@
-
+
-
+
-
+
-
+