Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| QtiTestExporter | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
| getItemExporter | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| adjustTestXml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| itemContentPostProcessing | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
2 | |||
| getExporterFactory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2024-2025 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoQtiTest\models\export\Formats\Package3p0; |
| 24 | |
| 25 | use core_kernel_classes_Resource as Resource; |
| 26 | use DOMDocument; |
| 27 | use oat\taoQtiItem\model\Export\Qti3Package\ExporterFactory; |
| 28 | use oat\taoQtiTest\models\export\AbstractQtiTestExporter; |
| 29 | use oat\taoQtiTest\models\export\QtiItemExporterInterface; |
| 30 | |
| 31 | class QtiTestExporter extends AbstractQtiTestExporter |
| 32 | { |
| 33 | protected const TEST_RESOURCE_TYPE = 'imsqti_test_xmlv3p0'; |
| 34 | |
| 35 | private const QTI_SCHEMA_NAMESPACE = 'http://www.imsglobal.org/xsd/imsqtiasi_v3p0'; |
| 36 | private const XML_SCHEMA_INSTANCE = 'http://www.w3.org/2001/XMLSchema-instance'; |
| 37 | private const XSI_SCHEMA_LOCATION = 'http://www.imsglobal.org/xsd/imsqtiasi_v3p0'; |
| 38 | // phpcs:ignore Generic.Files.LineLength.TooLong |
| 39 | private const XSI_SCHEMA_LOCATION_XSD = 'https://purl.imsglobal.org/spec/qti/v3p0/schema/xsd/imsqti_asiv3p0_v1p0.xsd'; |
| 40 | |
| 41 | protected function getItemExporter(Resource $item): QtiItemExporterInterface |
| 42 | { |
| 43 | $exporter = new QtiItemExporter($item, $this->getZip(), $this->getManifest()); |
| 44 | $exporter->setTransformationService($this->getExporterFactory()->getTransformationService()); |
| 45 | return $exporter; |
| 46 | } |
| 47 | |
| 48 | protected function adjustTestXml(string $xml): string |
| 49 | { |
| 50 | return $this->itemContentPostProcessing($xml); |
| 51 | } |
| 52 | |
| 53 | protected function itemContentPostProcessing($content): string |
| 54 | { |
| 55 | $transformationService = $this->getExporterFactory()->getTransformationService(); |
| 56 | $dom = new DOMDocument('1.0', 'UTF-8'); |
| 57 | $dom->loadXML($content); |
| 58 | |
| 59 | $newDom = new DOMDocument('1.0', 'UTF-8'); |
| 60 | $newDom->preserveWhiteSpace = false; |
| 61 | $newDom->formatOutput = true; |
| 62 | |
| 63 | $oldRoot = $dom->documentElement; |
| 64 | $newRoot = $newDom->createElement($transformationService->createQtiElementName($oldRoot->nodeName)); |
| 65 | |
| 66 | //QTI3 namespace |
| 67 | $newRoot->setAttribute('xmlns', self::QTI_SCHEMA_NAMESPACE); |
| 68 | $newRoot->setAttribute('xmlns:xsi', self::XML_SCHEMA_INSTANCE); |
| 69 | $newRoot->setAttribute( |
| 70 | 'xsi:schemaLocation', |
| 71 | sprintf('%s %s', self::XSI_SCHEMA_LOCATION, self::XSI_SCHEMA_LOCATION_XSD) |
| 72 | ); |
| 73 | |
| 74 | $transformationService->transformAttributes($oldRoot, $newRoot); |
| 75 | |
| 76 | $newDom->appendChild($newRoot); |
| 77 | |
| 78 | $transformationService->transformChildren($oldRoot, $newRoot, $newDom); |
| 79 | |
| 80 | return $newDom->saveXML(); |
| 81 | } |
| 82 | |
| 83 | private function getExporterFactory(): ExporterFactory |
| 84 | { |
| 85 | return $this->getServiceManager()->getContainer()->get(ExporterFactory::class); |
| 86 | } |
| 87 | } |