object; $portableAssetsToExport = []; $service = new PortableElementService(); $service->setServiceLocator(ServiceManager::getServiceManager()); $files = $object->getModel()->getValidator()->getAssets($object, 'runtime'); $baseUrl = $this->qtiItemExporter->buildBasePath() . DIRECTORY_SEPARATOR . $object->getTypeIdentifier(); foreach ($files as $url) { // Skip shared libraries into portable element if (strpos($url, './') !== 0) { \common_Logger::i('Shared libraries skipped : ' . $url); $portableAssetsToExport[$url] = $url; continue; } $stream = $service->getFileStream($object, $url); $replacement = $this->qtiItemExporter->copyAssetFile($stream, $baseUrl, $url, $replacementList); $portableAssetToExport = preg_replace('/^(.\/)(.*)/', $object->getTypeIdentifier() . "/$2", $replacement); $portableAssetsToExport[$url] = $portableAssetToExport; \common_Logger::i('File copied: "' . $url . '" for portable element ' . $object->getTypeIdentifier()); } return $this->portableAssetsToExport = $portableAssetsToExport; } public function getNodeName(){ return 'portableInfoControl'; } public function getTypeIdentifierAttributeName(){ return 'infoControlTypeIdentifier'; } public function getXmlnsName(){ return 'pic'; } public function exportDom(DOMDocument $dom){ // If asset files list is empty for current identifier skip if (empty($this->portableAssetsToExport)){ return; } $xpath = new DOMXPath($dom); // Get all portable element from qti.xml $portableElementNodes = $dom->getElementsByTagName($this->getNodeName()); /** @var PortableElementObject $portableElement */ $portableElement = $this->object; for ($i=0; $i<$portableElementNodes->length; $i++) { /** @var \DOMElement $currentPortableNode */ $currentPortableNode = $portableElementNodes->item($i); //get the local namespace prefix to be used in new node creation $localNs = $currentPortableNode->hasAttribute('xmlns') ? '' : $this->getXmlnsName().':'; //get the portable element type identifier $identifier = $currentPortableNode->getAttribute($this->getTypeIdentifierAttributeName()); if($identifier != $portableElement->getTypeIdentifier()){ continue; } // Add hook and version as attributes if ($portableElement->hasRuntimeKey('hook')) $currentPortableNode->setAttribute('hook', preg_replace('/^(.\/)(.*)/', $portableElement->getTypeIdentifier() . "/$2", $portableElement->getRuntimeKey('hook') ) ); //set version $currentPortableNode->setAttribute('version', $portableElement->getVersion()); // If asset files list is empty for current identifier skip if ( !isset($portableAssetsToExport) || !isset($portableAssetsToExport[$portableElement->getTypeIdentifier()]) ){ continue; } /** @var \DOMElement $resourcesNode */ $resourcesNode = $currentPortableNode->getElementsByTagName('resources')->item(0); $this->removeOldNode($resourcesNode, 'libraries'); $this->removeOldNode($resourcesNode, 'stylesheets'); $this->removeOldNode($resourcesNode, 'mediaFiles'); // Portable libraries $librariesNode = $dom->createElement($localNs . 'libraries'); foreach ($portableElement->getRuntimeKey('libraries') as $library) { $libraryNode = $dom->createElement($localNs . 'lib'); //the exported lib id must be adapted from a href mode to an amd name mode $libraryNode->setAttribute('id', preg_replace('/\.js$/', '', $library)); $librariesNode->appendChild($libraryNode); } if ($librariesNode->hasChildNodes()) { $resourcesNode->appendChild($librariesNode); } // Portable stylesheets $stylesheetsNode = $dom->createElement($localNs . 'stylesheets'); foreach ($portableElement->getRuntimeKey('stylesheets') as $stylesheet) { $stylesheetNode = $dom->createElement($localNs . 'link'); $stylesheetNode->setAttribute('href', $this->getOatPciExportPath($stylesheet)); $stylesheetNode->setAttribute('type', 'text/css'); $info = pathinfo($stylesheet); $stylesheetNode->setAttribute('title', basename($stylesheet, '.' . $info['extension'])); $stylesheetsNode->appendChild($stylesheetNode); } if ($stylesheetsNode->hasChildNodes()) { $resourcesNode->appendChild($stylesheetsNode); } // Portable mediaFiles $mediaFilesNode = $dom->createElement($localNs . 'mediaFiles'); foreach ($portableElement->getRuntimeKey('mediaFiles') as $mediaFile) { $mediaFileNode = $dom->createElement($localNs . 'file'); $mediaFileNode->setAttribute('src', $this->getOatPciExportPath($mediaFile)); $mediaFileNode->setAttribute('type', \tao_helpers_File::getMimeType($this->getOatPciExportPath($mediaFile))); $mediaFilesNode->appendChild($mediaFileNode); } if ($mediaFilesNode->hasChildNodes()) { $resourcesNode->appendChild($mediaFilesNode); } } unset($xpath); } private function getOatPciExportPath($file){ return $this->portableAssetsToExport[preg_replace('/^'.$this->object->getTypeIdentifier().'\//', './', $file)]; } }