/**
  * Register a new model to the registry
  * 
  * @param PortableElementModel $model
  */
 public function register(PortableElementModel $model)
 {
     $this->set($model->getId(), ['class' => get_class($model)]);
 }
 /**
  * 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));
 }