Skip to content

Commit

Permalink
Merge pull request #659 from oat-sa/release-2.23.0
Browse files Browse the repository at this point in the history
Release 2.23.0
  • Loading branch information
llecaque committed Apr 25, 2016
2 parents 4324800 + 9e419a1 commit 47f2dd2
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 14 deletions.
6 changes: 6 additions & 0 deletions config/default/simpleExporter.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
'callback' => 'getNumberOfChoices'
)
),
'responseIdentifier' => array (
'extractor' => 'QtiExtractor',
'parameters' => array (
'callback' => 'getResponseIdentifier',
)
),
'BR' => array (
'extractor' => 'QtiExtractor',
'parameters' => array (
Expand Down
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.22.0',
'version' => '2.23.0',
'author' => 'Open Assessment Technologies',
'requires' => array(
'taoItems' => '>=2.13',
Expand Down
47 changes: 38 additions & 9 deletions model/flyExporter/extractor/QtiExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,12 @@ protected function extractInteractions()
$interaction['responseIdentifier'] = $interactionNode->item($i)->getAttribute('responseIdentifier');
$rightAnswer = $this->xpath->query('./qti:responseDeclaration[@identifier="' . $interaction['responseIdentifier'] . '"]');
if ($rightAnswer->length > 0) {
$answers = trim($rightAnswer->item(0)->textContent);
$answers = $rightAnswer->item(0)->textContent;
if (!empty($answers)) {
foreach(explode(PHP_EOL, $answers) as $answer) {
$interaction['responses'][] = trim($answer);
if (trim($answer)!=='') {
$interaction['responses'][] = $answer;
}
}
}
}
Expand All @@ -284,7 +286,8 @@ protected function extractInteractions()
if (!empty($choiceNode) && $choiceNode->length > 0) {
for($j=0 ; $j < $choiceNode->length ; $j++) {
$identifier = $choiceNode->item($j)->getAttribute('identifier');
$value = preg_replace('/\s+/', '', $choiceNode->item($j)->nodeValue);
$value = $this->sanitizeNodeToValue($this->dom->saveHtml($choiceNode->item($j)));

//Image
if ($value==='') {
$imgNode = $this->xpath->query('./qti:img/@src', $choiceNode->item($j));
Expand All @@ -302,6 +305,22 @@ protected function extractInteractions()
return $this;
}

/**
* Remove first and last xml tag from string
* Transform variable to string value
*
* @param $value
* @return string
*/
protected function sanitizeNodeToValue($value)
{
$first = strpos($value, '>')+1;
$last = strrpos($value, '<')-$first;
$value = substr($value, $first, $last);
$value = str_replace('"', "'", $value);
return trim($value);
}

/**
* Callback to retrieve right answers
* Find $responses & resolve identifier with $choices
Expand All @@ -314,7 +333,7 @@ public function getRightAnswer($interaction, $params)
$return = [];
if (isset($interaction['responses'])) {
foreach ($interaction['responses'] as $response) {
$allResponses = explode(' ', $response);
$allResponses = explode(' ', trim($response));
$returnResponse = [];

foreach ($allResponses as $partialResponse) {
Expand All @@ -325,7 +344,9 @@ public function getRightAnswer($interaction, $params)
$returnResponse[] = $partialResponse;
}
}
$return[] = implode(' ', $returnResponse);
if (!empty($returnResponse)) {
$return[] = implode(' - ', $returnResponse);
}
}
}
if (isset($params['delimiter'])) {
Expand Down Expand Up @@ -364,16 +385,13 @@ public function getChoices($interaction)
if (isset($interaction['choices'])) {
$i = 1;
foreach ($interaction['choices'] as $identifier => $choice) {
\common_Logger::d($interaction['type']);
\common_Logger::d($choice);

if (!$choice!=='') {
$return['choice_' . $i] = $choice;
} else {
$return['choice_' . $i] = $identifier;
}
\common_Logger::d($return['choice_' . $i]);
\common_Logger::d('--------- ');

$i++;
}
if ($this->headerChoice > count($return)) {
Expand Down Expand Up @@ -404,6 +422,17 @@ public function getInteractionType($interaction)
}
}

/**
* Callback to retrieve interaction response identifier
*
* @param $interaction
* @return mixed
*/
public function getResponseIdentifier($interaction)
{
return $interaction['responseIdentifier'];
}

/**
* Get human readable declaration class
* @return string
Expand Down
13 changes: 9 additions & 4 deletions model/flyExporter/simpleExporter/ItemExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class ItemExporter extends ConfigurableService implements SimpleExporter
*/
const CSV_DELIMITER = ',';

/**
* Defautl csv enclosure
*/
const CSV_ENCLOSURE = '"';

/**
* Default property delimiter
*/
Expand Down Expand Up @@ -236,13 +241,13 @@ protected function save(array $data)

$output = $contents = [];

$contents[] = implode(self::CSV_DELIMITER, $this->headers);
$contents[] = self::CSV_ENCLOSURE . implode(self::CSV_ENCLOSURE . self::CSV_DELIMITER . self::CSV_ENCLOSURE, $this->headers) . self::CSV_ENCLOSURE;

foreach ($data as $item) {
foreach ($item as $line) {
foreach ($this->headers as $index => $value) {
if (isset($line[$value]) && $line[$value]!=='') {
$output[$value] = '"' . $line[$value] . '"';
$output[$value] = self::CSV_ENCLOSURE . (string) $line[$value] . self::CSV_ENCLOSURE;
unset($line[$value]);
} else {
$output[$value] = '';
Expand All @@ -251,7 +256,7 @@ protected function save(array $data)
$contents[] = implode(self::CSV_DELIMITER, array_merge($output, $line));
}
}
$this->filesystem->update($this->filelocation, implode("\n", $contents));
$this->filesystem->update($this->filelocation, chr(239) . chr(187) . chr(191) . implode("\n", $contents));
}

/**
Expand All @@ -271,7 +276,7 @@ protected function handleFile($filename)
$this->filesystem->delete($filename);
}

if ($resource = fopen('temp', 'w')===false) {
if (($resource = fopen('temp', 'w'))===false) {
throw new \Exception('Unable to create csv file.');
}

Expand Down
21 changes: 21 additions & 0 deletions scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace oat\taoQtiItem\scripts\update;

use oat\oatbox\service\ConfigurableService;
use oat\taoQtiItem\install\scripts\addValidationSettings;
use oat\taoQtiItem\install\scripts\createExportDirectory;
use oat\taoQtiItem\model\flyExporter\extractor\OntologyExtractor;
Expand Down Expand Up @@ -318,6 +319,26 @@ public function update($initialVersion){
}

$this->skip('2.20.0', '2.22.0');

if ($this->isVersion('2.22.0')) {
$simpleExporter = $this->getServiceManager()->get(SimpleExporter::SERVICE_ID);
$columns = $simpleExporter->getOption('columns');
$responseIdentifier['responseIdentifier'] = array (
'extractor' => 'QtiExtractor',
'parameters' => array (
'callback' => 'getResponseIdentifier',
)
);

$offset = array_search('BR', array_keys($columns));
$columns = array_slice($columns, 0, $offset, true) + $responseIdentifier + array_slice($columns, $offset, NULL, true);

$simpleExporter->setOption('columns', $columns);
$simpleExporter->setServiceManager($this->getServiceManager());
$this->getServiceManager()->register(SimpleExporter::SERVICE_ID, $simpleExporter);

$this->setVersion('2.23.0');
}
}

}

0 comments on commit 47f2dd2

Please sign in to comment.