コード例 #1
0
 /**
  * Overriden export from QTI items.
  *
  * @param array $options An array of options.
  * @see taoItems_models_classes_ItemExporter::export()
  */
 public function export($options = array())
 {
     $asApip = isset($options['apip']) && $options['apip'] === true;
     $lang = \common_session_SessionManager::getSession()->getDataLanguage();
     $basePath = $this->buildBasePath();
     $dataFile = (string) $this->getItemModel()->getOnePropertyValue(new core_kernel_classes_Property(TAO_ITEM_MODEL_DATAFILE_PROPERTY));
     $content = $this->getItemService()->getItemContent($this->getItem());
     $resolver = new ItemMediaResolver($this->getItem(), $lang);
     // get the local resources and add them
     foreach ($this->getAssets($this->getItem(), $lang) as $assetUrl) {
         $mediaAsset = $resolver->resolve($assetUrl);
         $mediaSource = $mediaAsset->getMediaSource();
         if (get_class($mediaSource) !== 'oat\\tao\\model\\media\\sourceStrategy\\HttpSource') {
             $srcPath = $mediaSource->download($mediaAsset->getMediaIdentifier());
             $fileInfo = $mediaSource->getFileInfo($mediaAsset->getMediaIdentifier());
             $filename = $fileInfo['filePath'];
             $replacement = $mediaAsset->getMediaIdentifier();
             if ($mediaAsset->getMediaIdentifier() !== $fileInfo['uri']) {
                 $replacement = $filename;
             }
             $destPath = ltrim($filename, '/');
             if (file_exists($srcPath)) {
                 $this->addFile($srcPath, $basePath . '/' . $destPath);
                 $content = str_replace($assetUrl, $replacement, $content);
             } else {
                 throw new \Exception('Missing resource ' . $srcPath);
             }
         }
     }
     if ($asApip === true) {
         // 1. let's merge qti.xml and apip.xml.
         // 2. retrieve apip related assets.
         $apipService = ApipService::singleton();
         $apipContentDoc = $apipService->getApipAccessibilityContent($this->getItem());
         if ($apipContentDoc === null) {
             \common_Logger::i("No APIP accessibility content found for item '" . $this->getItem()->getUri() . "', default inserted.");
             $apipContentDoc = $apipService->getDefaultApipAccessibilityContent($this->getItem());
         }
         $qtiItemDoc = new DOMDocument('1.0', 'UTF-8');
         $qtiItemDoc->formatOutput = true;
         $qtiItemDoc->loadXML($content);
         // Let's merge QTI and APIP Accessibility!
         Apip::mergeApipAccessibility($qtiItemDoc, $apipContentDoc);
         $content = $qtiItemDoc->saveXML();
         $fileHrefElts = $qtiItemDoc->getElementsByTagName('fileHref');
         for ($i = 0; $i < $fileHrefElts->length; $i++) {
             $fileHrefElt = $fileHrefElts->item($i);
             $destPath = $basePath . '/' . $fileHrefElt->nodeValue;
             $sourcePath = $this->getItemLocation() . $fileHrefElt->nodeValue;
             $this->addFile($sourcePath, $destPath);
         }
     }
     // add xml file
     $this->getZip()->addFromString($basePath . '/' . $dataFile, $content);
 }
コード例 #2
0
 private function storeApip($qtiFile, $rdfItem)
 {
     $originalDoc = new DOMDocument('1.0', 'UTF-8');
     $originalDoc->load($qtiFile);
     $apipService = ApipService::singleton();
     $apipService->storeApipAccessibilityContent($rdfItem, $originalDoc);
 }