protected function getTemplateQtiVariables()
 {
     $variables = parent::getTemplateQtiVariables();
     $variables['typeIdentifier'] = $this->typeIdentifier;
     $variables['markup'] = $this->markup;
     return $variables;
 }
 public function toArray($filterVariableContent = false, &$filtered = array())
 {
     $data = parent::toArray($filterVariableContent, $filtered);
     if ($filterVariableContent) {
         $filtered[$this->getSerial()] = $data;
         $data = array('serial' => $data['serial'], 'qtiClass' => $data['qtiClass']);
     }
     return $data;
 }
Esempio n. 3
0
 public function toArray($filterVariableContent = false, &$filtered = array())
 {
     $data = parent::toArray($filterVariableContent, $filtered);
     if (!is_null($this->alt)) {
         if ($this->alt instanceof Object) {
             $data['_alt'] = $this->alt->toArray($filterVariableContent, $filtered);
         } else {
             $data['_alt'] = (string) $this->alt;
         }
     }
     return $data;
 }
Esempio n. 4
0
 /**
  * Get the variables for the qti template rendering
  * 
  * @return array
  */
 protected function getTemplateQtiVariables()
 {
     $variables = parent::getTemplateQtiVariables();
     $tag = static::$qtiTagName;
     //search existing mathML ns declaration:
     $ns = $this->getXIncludeNamespace();
     if (empty($ns)) {
         //add one!
         $relatedItem = $this->getRelatedItem();
         if (!is_null($relatedItem)) {
             $ns = 'xi';
             $relatedItem->addNamespace($ns, 'http://www.w3.org/2001/XInclude');
         }
     }
     if (!empty($ns)) {
         //proceed to ns addition:
         $tag = $ns . ':' . $tag;
     }
     $variables['tag'] = $tag;
     return $variables;
 }
Esempio n. 5
0
 public function replaceElement(Element $oldElement, Element $newElement)
 {
     $body = str_replace($oldElement->getPlaceholder(), $newElement->getPlaceholder(), $this->body, $count);
     if ($count === 0) {
         throw new QtiModelException('cannot find the element to be replaced');
     } else {
         if ($count > 1) {
             throw new QtiModelException('multiple placeholder found for the element to be replaced');
         }
     }
     $this->removeElement($oldElement);
     $this->setElement($newElement, $body);
 }
 /**
  * Load assets from the custom elements (CustomInteraction, PCI, PIC)
  * @param Element $element the custom element
  */
 private function loadCustomElementAssets(Element $element)
 {
     if ($this->getGetCustomElementDefinition()) {
         if ($element instanceof PortableCustomInteraction) {
             $this->assets['PCI'][$element->getTypeIdentifier()] = $element;
         }
         if ($element instanceof PortableInfoControl) {
             $this->assets['PIC'][$element->getTypeIdentifier()] = $element;
         }
     }
     $xmls = array();
     if ($element instanceof PortableCustomInteraction || $element instanceof PortableInfoControl) {
         //some portable elements contains htmlentitied markup in their properties...
         $xmls = $this->getXmlProperties($element->getProperties());
     }
     //parse and extract assets from markup using XPATH
     if ($element instanceof CustomInteraction || $element instanceof InfoControl) {
         // http://php.net/manual/fr/simplexmlelement.xpath.php#116622
         $sanitizedMarkup = str_replace('xmlns=', 'ns=', $element->getMarkup());
         $xmls[] = new SimpleXMLElement($sanitizedMarkup);
         $this->loadCustomElementPropertiesAssets($element->getProperties());
         /** @var SimpleXMLElement $xml */
         foreach ($xmls as $xml) {
             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']);
             }
         }
     }
 }
 /**
  * Short description of method __construct
  *
  * @access public
  * @author Sam, <*****@*****.**>
  * @param  string body
  * @return mixed
  */
 public function __construct($body = '', Item $relatedItem = null, $serial = '')
 {
     parent::__construct(array(), $relatedItem, $serial);
     $this->body = $body;
 }
Esempio n. 8
0
 public function __construct($attributes = array(), Item $relatedItem = null, $serial = '')
 {
     parent::__construct($attributes, $relatedItem, $serial);
     $this->body = new ContainerStatic('', $relatedItem);
 }
 /**
  * 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']);
         }
     }
 }
 public function getAttributeValues($filterNull = true)
 {
     $returnValue = array('identifier' => $this->getIdentifier());
     $returnValue = array_merge($returnValue, parent::getAttributeValues($filterNull));
     return $returnValue;
 }
 protected function replaceNode(DOMElement $node, Element $element)
 {
     $placeholder = $this->data->createTextNode($element->getPlaceholder());
     $node->parentNode->replaceChild($placeholder, $node);
 }
 public function toArray($filterVariableContent = false, &$filtered = array())
 {
     $data = parent::toArray($filterVariableContent, $filtered);
     $data['choices'] = array();
     foreach ($this->getChoices() as $choice) {
         $data['choices'][$choice->getSerial()] = $choice->toArray($filterVariableContent, $filtered);
     }
     return $data;
 }
 public function toArray($filterVariableContent = false, &$filtered = array())
 {
     $data = parent::toArray($filterVariableContent, $filtered);
     $data['choices'] = $this->getArraySerializedElementCollection($this->getChoices(), $filterVariableContent, $filtered);
     return $data;
 }
 /**
  * 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)
 {
     $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']);
         }
     }
 }