From 9d0b320a4b850347d739ac96f4aff228d69a325f Mon Sep 17 00:00:00 2001 From: viktar-dzmitryieu-tao Date: Wed, 18 Dec 2024 16:30:17 +0100 Subject: [PATCH] Revert "feat: Allow downgrade conversion from QTI 3.0 to QTI 2.2" This reverts commit 635760d877ad0cac99e8c0e1bd7dc90c0362c1f7. --- .../classes/Qti/Converter/TestConverter.php | 35 ----------- .../ServiceProvider/QtiServiceProvider.php | 10 +--- models/classes/class.QtiTestService.php | 59 ++++++++----------- .../render/QTI3PackagePreprocessing.php | 51 ---------------- 4 files changed, 24 insertions(+), 131 deletions(-) delete mode 100644 models/classes/Qti/Converter/TestConverter.php delete mode 100644 models/classes/render/QTI3PackagePreprocessing.php diff --git a/models/classes/Qti/Converter/TestConverter.php b/models/classes/Qti/Converter/TestConverter.php deleted file mode 100644 index a2ae12d46..000000000 --- a/models/classes/Qti/Converter/TestConverter.php +++ /dev/null @@ -1,35 +0,0 @@ -set(TestConverter::class) - ->args([ - service(CaseConversionService::class), - ]) - ->public(); } } diff --git a/models/classes/class.QtiTestService.php b/models/classes/class.QtiTestService.php index d9ddd5545..53ca7f396 100644 --- a/models/classes/class.QtiTestService.php +++ b/models/classes/class.QtiTestService.php @@ -1,4 +1,5 @@ verifyItemPermissions($test, $json); $doc = $this->getDoc($test); @@ -268,7 +266,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. @@ -282,7 +280,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(), @@ -308,7 +306,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; } @@ -365,7 +363,7 @@ public function importMultipleTests( ?string $packageLabel = null ) { $testClass = $targetClass; - $report = new Report(Report::TYPE_INFO); + $report = new common_report_Report(common_report_Report::TYPE_INFO); $validPackage = false; $validManifest = false; $testsFound = false; @@ -383,25 +381,24 @@ public function importMultipleTests( // phpcs:enable Generic.Files.LineLength try { - $qtiPackageParser = new PackageParser($file); + $qtiPackageParser = new taoQtiTest_models_classes_PackageParser($file); $qtiPackageParser->validate(); $validPackage = true; } catch (Exception $e) { - $report->add(Report::createError($invalidArchiveMsg)); + $report->add(common_report_Report::createFailure($invalidArchiveMsg)); } // Validate the manifest (well formed XML, valid against the schema). if ($validPackage === true) { $folder = $qtiPackageParser->extract(); + if (is_dir($folder) === false) { - $report->add(Report::createError($invalidArchiveMsg)); + $report->add(common_report_Report::createFailure($invalidArchiveMsg)); } else { - $file = $folder . 'imsmanifest.xml'; - $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($file); + $qtiManifestParser = new taoQtiTest_models_classes_ManifestParser($folder . 'imsmanifest.xml'); $this->propagate($qtiManifestParser); - $this->getManifestConverter()->convert($file, $qtiManifestParser); - // We validate manifest file against QTI 3.0 $qtiManifestParser->validate(); + if ($qtiManifestParser->isValid() === true) { $validManifest = true; @@ -414,10 +411,10 @@ public function importMultipleTests( if ($testsFound !== true) { $report->add( - Report::createError( - // phpcs:disable Generic.Files.LineLength + common_report_Report::createFailure( + // 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 { @@ -580,11 +577,12 @@ protected function importTest( // Create the report that will hold information about the import // of $qtiTestResource in TAO. - $report = new Report(Report::TYPE_INFO); + $report = new common_report_Report(common_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'); @@ -622,8 +620,6 @@ protected function importTest( ) ); } else { - //Convert to QTI 2.2 - $this->getTestConverter()->convert($expectedTestFile); // -- Load the test in a QTISM flavour. $testDefinition = new XmlDocument(); @@ -1083,6 +1079,7 @@ 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; @@ -1436,7 +1433,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; @@ -1604,14 +1601,4 @@ 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 deleted file mode 100644 index eda114cdb..000000000 --- a/models/classes/render/QTI3PackagePreprocessing.php +++ /dev/null @@ -1,51 +0,0 @@ -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(); - } -}