Skip to content

Commit

Permalink
Merge pull request #562 from oat-sa/release-2.14.1
Browse files Browse the repository at this point in the history
Release 2.14.1
  • Loading branch information
llecaque committed Feb 9, 2016
2 parents 7845e4e + 9a64ff8 commit d49b992
Show file tree
Hide file tree
Showing 51 changed files with 1,952 additions and 688 deletions.
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'label' => 'QTI item model',
'description' => 'TAO QTI item model',
'license' => 'GPL-2.0',
'version' => '2.14.0',
'version' => '2.14.1',
'author' => 'Open Assessment Technologies',
'requires' => array(
'taoItems' => '>=2.6'
Expand Down
15 changes: 9 additions & 6 deletions model/QtiItemCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,21 @@ protected function retrieveAssets(core_kernel_classes_Resource $item, $lang, $de
$mediaAsset = $resolver->resolve($assetUrl);
$mediaSource = $mediaAsset->getMediaSource();
$srcPath = $mediaSource->download($mediaAsset->getMediaIdentifier());
$filename = \tao_helpers_File::getSafeFileName(ltrim($mediaAsset->getMediaIdentifier(),'/'), $destination);
$replacement = $mediaAsset->getMediaIdentifier();
if (get_class($mediaSource) !== 'oat\tao\model\media\sourceStrategy\HttpSource') {
$fileInfo = $mediaSource->getFileInfo($mediaAsset->getMediaIdentifier());
$filename = $fileInfo['filePath'];
if($mediaAsset->getMediaIdentifier() !== $fileInfo['uri']){
$replacement = $filename;
if(isset($fileInfo['filePath'])){
$filename = $fileInfo['filePath'];
if($mediaAsset->getMediaIdentifier() !== $fileInfo['uri']){
$replacement = $filename;
}
$destPath = ltrim($filename,'/');
} else {
$destPath = $replacement = basename($srcPath);
}
tao_helpers_File::copy($srcPath,$destination.$destPath,false);

}
$destPath = ltrim($filename,'/');
tao_helpers_File::copy($srcPath,$destination.$destPath,false);
$xml = str_replace($assetUrl, $replacement, $xml);
}
}
Expand Down
48 changes: 23 additions & 25 deletions model/QtiJsonItemCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
use core_kernel_classes_Resource;
use oat\taoQtiItem\model\pack\QtiItemPacker;
use oat\taoQtiItem\model\qti\exception\XIncludeException;
use oat\taoQtiItem\model\qti\Service;
use tao_helpers_File;
use taoItems_models_classes_ItemsService;
use oat\taoQtiItem\model\qti\Parser;
use oat\taoQtiItem\model\qti\Service;

/**
* The QTI Json Item Compiler
Expand All @@ -41,6 +39,12 @@ class QtiJsonItemCompiler extends QtiItemCompiler
{

const ITEM_FILE_NAME = 'item.json';
const VAR_ELT_FILE_NAME = 'variableElements.json';

/**
* @var string json from the item packed
*/
private $itemJson;

/**
* Desploy all the required files into the provided directories
Expand All @@ -58,48 +62,42 @@ protected function deployQtiItem(core_kernel_classes_Resource $item, $language,

$qtiService = Service::singleton();

//create the item.json file in private directory
$itemPacker = new QtiItemPacker();
$itemPack = $itemPacker->packItem($item, $language);
file_put_contents($privateFolder.self::ITEM_FILE_NAME, json_encode($itemPack->JsonSerialize()));

//copy client side resources (javascript loader)
$qtiItemDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir();
$taoDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getDir();
$assetPath = $qtiItemDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR;
$assetLibPath = $taoDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
if (\tao_helpers_Mode::is('production')) {
tao_helpers_File::copy($assetPath . 'qtiLoader.min.js', $publicDirectory . 'qtiLoader.min.js', false);
} else {
tao_helpers_File::copy($assetPath . 'qtiLoader.js', $publicDirectory . 'qtiLoader.js', false);
tao_helpers_File::copy($assetLibPath . 'require.js', $publicDirectory . 'require.js', false);
}

// retrieve the media assets
try {
$qtiItem = $this->retrieveAssets($item, $language, $publicDirectory);

//store variable qti elements data into the private directory
$variableElements = $qtiService->getVariableElements($qtiItem);
$serializedVariableElements = json_encode($variableElements);
file_put_contents($privateFolder . 'variableElements.json', $serializedVariableElements);
$serializedVarElts = json_encode($variableElements);
file_put_contents($privateFolder . self::VAR_ELT_FILE_NAME, $serializedVarElts);

//create the item.json file in private directory
$itemPacker = new QtiItemPacker();
$itemPack = $itemPacker->packQtiItem($item, $language, $qtiItem);
$this->itemJson = $itemPack->JsonSerialize();
//get the filtered data to avoid cheat
$data = $qtiItem->getDataForDelivery();
$this->itemJson['data'] = $data['core'];

file_put_contents($privateFolder . self::ITEM_FILE_NAME, json_encode($this->itemJson));

return new common_report_Report(
common_report_Report::TYPE_SUCCESS, __('Successfully compiled "%s"', $language)
);

} catch (\tao_models_classes_FileNotFoundException $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, __('Unable to retrieve asset "%s"', $e->getFilePath())
);
} catch (XIncludeException $e){
} catch (XIncludeException $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, $e->getUserMessage()
);
} catch (\Exception $e){
} catch (\Exception $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, $e->getMessage()
);
}
}

}
66 changes: 37 additions & 29 deletions model/pack/QtiItemPacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use oat\taoItems\model\pack\ItemPack;
use oat\taoItems\model\pack\ItemPacker;
use oat\taoQtiItem\model\qti\Item;
use oat\taoQtiItem\model\qti\Parser as QtiParser;
use oat\taoQtiItem\model\qti\AssetParser;
use \core_kernel_classes_Resource;
Expand Down Expand Up @@ -67,45 +68,52 @@ public function packItem(core_kernel_classes_Resource $item, $lang = "")

$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);
$content = $this->getItemContent($path);
//load content
$qtiParser = new QtiParser($content);
//validate it
$qtiParser->validate();
if (!$qtiParser->isValid()) {
throw new common_Exception('Invalid QTI content : ' . $qtiParser->displayErrors(false));
}

//validate it
$qtiParser->validate();
if (!$qtiParser->isValid()) {
throw new common_Exception('Invalid QTI content : ' . $qtiParser->displayErrors(false));
}
//parse
$qtiItem = $qtiParser->load();

//parse
$qtiItem = $qtiParser->load();
return $this->packQtiItem($item, $lang, $qtiItem);

//then build the ItemPack from the parsed data
if (!is_null($qtiItem)) {
}

if($this->replaceXinclude){
$resolver = new ItemMediaResolver($item, $lang);
$xincludeLoader = new XIncludeLoader($qtiItem, $resolver);
$xincludeLoader->load(true);
}
/**
* @param core_kernel_classes_Resource $item the item to pack
* @param string $lang
* @param Item $qtiItem
* @return ItemPack $itemPack
* @throws common_Exception
*/
public function packQtiItem($item, $lang, $qtiItem){
//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 = new ItemPack(self::$itemType, $qtiItem->toArray());

$itemPack->setAssetEncoders($this->getAssetEncoders());
$itemPack->setAssetEncoders($this->getAssetEncoders());

$assetParser = new AssetParser($qtiItem, $path);
$assetParser->setDeepParsing($this->isNestedResourcesInclusion());
$assetParser->setGetXinclude(!$this->replaceXinclude);
$path = $this->getPath($item, $lang);
$assetParser = new AssetParser($qtiItem, $path);
$assetParser->setDeepParsing($this->isNestedResourcesInclusion());
$assetParser->setGetXinclude(!$this->replaceXinclude);

foreach ($assetParser->extract($itemPack) as $type => $assets) {
$itemPack->setAssets($type, $assets, $path);
}
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());
}
Expand Down
Loading

0 comments on commit d49b992

Please sign in to comment.