/** * Parse individual portable element into the given portable model * @param PortableElementModel $model * @param Element $portableElement * @throws \common_Exception * @throws PortableElementInconsistencyModelException */ protected function parsePortableElement(PortableElementModel $model, Element $portableElement) { $typeId = $portableElement->getTypeIdentifier(); $libs = []; $requiredLibFiles = []; //Adjust file resource entries where {QTI_NS}/xxx/yyy is equivalent to {QTI_NS}/xxx/yyy.js foreach ($portableElement->getLibraries() as $lib) { if (preg_match('/^' . $typeId . '.*\\.js$/', $lib) && substr($lib, -3) != '.js') { //filter shared stimulus $requiredLibFiles[] = $lib . '.js'; //amd modules $libs[] = $lib . '.js'; } else { $libs[] = $lib; } } $data = ['typeIdentifier' => $typeId, 'version' => $portableElement->getVersion(), 'label' => $typeId, 'short' => $typeId, 'runtime' => ['hook' => $portableElement->getEntryPoint(), 'libraries' => $libs, 'stylesheets' => $portableElement->getStylesheets(), 'mediaFiles' => $portableElement->getMediaFiles()]]; /** @var PortableElementObject $portableObject */ $portableObject = $model->createDataObject($data); $lastVersionModel = $this->getService()->getPortableElementByIdentifier($portableObject->getModel()->getId(), $portableObject->getTypeIdentifier()); if (!is_null($lastVersionModel) && intval($lastVersionModel->getVersion()) != intVal($portableObject->getVersion())) { //@todo return a user exception to inform user of incompatible pci version found and that an item update is required throw new \common_Exception('Unable to import pci asset because pci is not compatible. ' . 'Current version is ' . $lastVersionModel->getVersion() . ' and imported is ' . $portableObject->getVersion()); } $this->portableObjects[$typeId] = $portableObject; $files = array_merge([$portableObject->getRuntimeKey('hook')], $requiredLibFiles, $portableObject->getRuntimeKey('stylesheets'), $portableObject->getRuntimeKey('mediaFiles')); $this->requiredFiles = array_merge($this->requiredFiles, array_fill_keys($files, $typeId)); }
/** * Load assets from the custom elements (CustomInteraction, PCI, PIC) * @param Element $element the custom element */ private function loadCustomElementAssets(Element $element) { if ($element instanceof PortableCustomInteraction || $element instanceof PortableInfoControl) { $this->addAsset('js', $element->getEntryPoint()); foreach ($element->getLibraries() as $lib) { $this->addAsset('js', $lib); } } //parse and extract assets from markup using XPATH if ($element instanceof CustomInteraction || $element instanceof InfoControl) { $xml = new SimpleXMLElement($element->getMarkup()); foreach ($xml->xpath('//img') as $img) { $this->addAsset('img', (string) $img['src']); } foreach ($xml->xpath('//video') as $video) { $this->addAsset('video', (string) $video['src']); } foreach ($xml->xpath('//audio') as $audio) { $this->addAsset('audio', (string) $audio['src']); } } }
/** * Load assets from the custom elements (CustomInteraction, PCI, PIC) * @param Element $element the custom element */ private function loadCustomElementAssets(Element $element) { $libBasePath = ROOT_PATH . 'taoQtiItem/views/js/portableSharedLibraries'; $libRootUrl = ROOT_URL . 'taoQtiItem/views/js/portableSharedLibraries'; if ($element instanceof PortableCustomInteraction || $element instanceof PortableInfoControl) { $entryPoint = $element->getEntryPoint(); $fileName = substr($entryPoint, -3) != '.js' ? $entryPoint . '.js' : $entryPoint; $this->addAsset('js', $fileName); foreach ($element->getLibraries() as $lib) { if ($this->getGetSharedLibraries() || !ClientLibRegistry::getRegistry()->isRegistered($lib)) { $fileName = substr($lib, -3) != '.js' ? $lib . '.js' : $lib; $this->addAsset('js', $fileName); } } } //parse and extract assets from markup using XPATH if ($element instanceof CustomInteraction || $element instanceof InfoControl) { $xml = new SimpleXMLElement($element->getMarkup()); foreach ($xml->xpath('//img') as $img) { $this->addAsset('img', (string) $img['src']); } foreach ($xml->xpath('//video') as $video) { $this->addAsset('video', (string) $video['src']); } foreach ($xml->xpath('//audio') as $audio) { $this->addAsset('audio', (string) $audio['src']); } } }