/** * Save the content of test from a QTI Document * @param core_kernel_classes_Resource $test * @param qtism\data\storage\xml\XmlDocument $doc * @return boolean true if saved * @throws taoQtiTest_models_classes_QtiTestServiceException */ private function saveDoc(core_kernel_classes_Resource $test, XmlDocument $doc) { $saved = false; if (!is_null($test) && !is_null($doc)) { $file = $this->getTestFile($test); if (!is_null($file)) { $testPath = $file->getAbsolutePath(); try { // Search for the test.xml file in the test content directory. $files = tao_helpers_File::scandir($testPath, array('recursive' => true, 'absolute' => true, 'only' => tao_helpers_File::$FILE)); $dirContent = array(); foreach ($files as $f) { $pathinfo = pathinfo($f); if ($pathinfo['filename'] . '.' . $pathinfo['extension'] === TAOQTITEST_FILENAME) { $dirContent[] = $f; } } if (count($dirContent) === 0) { throw new Exception('No QTI-XML test file found.'); } else { if (count($dirContent) > 1) { throw new Exception('Multiple QTI-XML test file found.'); } } $finalPath = current($dirContent); $doc->save($finalPath); $saved = true; } catch (Exception $e) { throw new taoQtiTest_models_classes_QtiTestServiceException("An error occured while writing QTI-XML test '{$testPath}': " . $e->getMessage(), taoQtiTest_models_classes_QtiTestServiceException::ITEM_WRITE_ERROR); } } } return $saved; }
/** * Export the Test definition itself and its related media. * * @param array $itemIdentifiers An array of identifiers that were assigned to exported items into the IMS Manifest. */ protected function exportTest(array $itemIdentifiers) { // Serialize the test definition somewhere and add // it to the archive. $tmpPath = tempnam('/tmp', 'tao'); $this->getTestDocument()->save($tmpPath); $testPath = $this->getTestService()->getTestContent($this->getItem())->getAbsolutePath(); // Add the test definition in the archive. $testBasePath = 'tests/' . tao_helpers_Uri::getUniqueId($this->getItem()->getUri()) . '/'; $extraPath = trim(str_replace(array($testPath, TAOQTITEST_FILENAME), '', $this->getTestService()->getDocPath($this->getItem())), DIRECTORY_SEPARATOR); $testHref = $testBasePath . (empty($extraPath) === false ? $extraPath . '/' : '') . 'test.xml'; common_Logger::t('TEST DEFINITION AT: ' . $testHref); $this->addFile($tmpPath, $testHref); $this->referenceTest($testHref, $itemIdentifiers); $files = tao_helpers_File::scandir($testPath, array('recursive' => true, 'absolute' => true)); foreach ($files as $f) { // Only add dependency files... if (is_dir($f) === false && strpos($f, TAOQTITEST_FILENAME) === false) { // Add the file to the archive. $fileHref = $testBasePath . ltrim(str_replace($testPath, '', $f), '/'); common_Logger::t('AUXILIARY FILE AT: ' . $fileHref); $this->getZip()->addFile($f, $fileHref); $this->referenceAuxiliaryFile($fileHref); } } }
/** * Copy the test resources (e.g. images) that will be availabe at delivery time * in the public compilation directory. * */ protected function copyPublicResources() { $compiledDocDir = $this->getPrivateDirectory()->getPath(); $publicCompiledDocDir = $this->getPublicDirectory()->getPath(); foreach (tao_helpers_File::scandir($compiledDocDir, array('recursive' => true, 'only' => tao_helpers_File::$FILE, 'absolute' => true)) as $file) { $mime = tao_helpers_File::getMimeType($file, true); $pathinfo = pathinfo($file); // Exclude CSS files because already copied when dealing with rubric blocks. if (in_array($mime, self::getPublicMimeTypes()) === true && $pathinfo['extension'] !== 'php') { $file = str_replace($compiledDocDir, '', $file); common_Logger::t("Copying public resource '{$file}'..."); taoQtiTest_helpers_Utils::storeQtiResource($publicCompiledDocDir, $file, $compiledDocDir); } } }