/**
  * packItem implementation for QTI
  * @inheritdoc
  * @see {@link ItemPacker}
  * @throws InvalidArgumentException
  * @throws common_Exception
  */
 public function packItem(core_kernel_classes_Resource $item, $lang = "")
 {
     $itemPack = null;
     $path = $this->getPath($item, $lang);
     $content = $this->getItemContent($path);
     //use the QtiParser to transform the QTI XML into an assoc array representation
     try {
         //load content
         $qtiParser = new QtiParser($content);
         //validate it
         $qtiParser->validate();
         if (!$qtiParser->isValid()) {
             throw new common_Exception('Invalid QTI content : ' . $qtiParser->displayErrors(false));
         }
         //parse
         $qtiItem = $qtiParser->load();
         //then build the ItemPack from the parsed data
         if (!is_null($qtiItem)) {
             $itemPack = new ItemPack(self::$itemType, $qtiItem->toArray());
             $itemPack->setAssetEncoders($this->getAssetEncoders());
             $assetParser = new AssetParser($qtiItem, $path);
             $assetParser->setDeepParsing($this->isNestedResourcesInclusion());
             foreach ($assetParser->extract($itemPack) as $type => $assets) {
                 $itemPack->setAssets($type, $assets, $path);
             }
         }
     } catch (common_Exception $e) {
         throw new common_Exception('Unable to pack item ' . $item->getUri() . ' : ' . $e->getMessage());
     }
     return $itemPack;
 }
 /**
  * @param core_kernel_classes_Resource $item the item to pack
  * @param string $lang
  * @param Item $qtiItem
  * @param \oat\oatbox\filesystem\Directory $directory
  * @return ItemPack $itemPack
  * @throws common_Exception
  */
 public function packQtiItem($item, $lang, $qtiItem, Directory $directory)
 {
     //use the QtiParser to transform the QTI XML into an assoc array representation
     try {
         //build the ItemPack from the parsed data
         if ($this->replaceXinclude) {
             $resolver = new ItemMediaResolver($item, $lang);
             $xincludeLoader = new XIncludeLoader($qtiItem, $resolver);
             $xincludeLoader->load(true);
         }
         $itemPack = new ItemPack(self::$itemType, $qtiItem->toArray());
         $itemPack->setAssetEncoders($this->getAssetEncoders());
         $assetParser = new AssetParser($qtiItem, $directory);
         $assetParser->setDeepParsing($this->isNestedResourcesInclusion());
         $assetParser->setGetXinclude(!$this->replaceXinclude);
         $storageDirectory = new \tao_models_classes_service_StorageDirectory($item->getUri(), $directory->getFileSystemId(), $directory->getPrefix() . '/' . $lang);
         $storageDirectory->setServiceLocator($directory->getServiceLocator());
         foreach ($assetParser->extract($itemPack) as $type => $assets) {
             $resolver = new ItemMediaResolver($item, $lang);
             foreach ($assets as &$asset) {
                 $mediaAsset = $resolver->resolve($asset);
                 $mediaSource = $mediaAsset->getMediaSource();
                 $asset = $mediaSource->getBaseName($mediaAsset->getMediaIdentifier());
             }
             $itemPack->setAssets($type, $assets, $storageDirectory);
         }
     } catch (common_Exception $e) {
         throw new common_Exception('Unable to pack item ' . $item->getUri() . ' : ' . $e->getMessage());
     }
     return $itemPack;
 }