Partial fix when trying to import qti exercises see BT#1368

skala
Julio Montoya 16 years ago
parent 5722951421
commit 7cf77ea7fb
  1. 9
      main/exercice/answer.class.php
  2. 5
      main/exercice/export/exercise_import.inc.php
  3. 31
      main/exercice/export/qti2/qti2_classes.php

@ -266,11 +266,18 @@ class Answer
* @author Yannick Warnier <ywarnier@beeznest.org>
* @return array List of answers where each answer is an array of (id, answer, comment, grade) and grade=weighting
*/
function getAnswersList()
function getAnswersList($decode = false)
{
$list = array();
for($i = 1; $i<=$this->nbrAnswers;$i++){
if(!empty($this->answer[$i])){
//Avoid problems when parsing elements with accents
if ($decode) {
$this->answer[$i] = html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding());
$this->comment[$i] = html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding());
}
$list[] = array(
'id'=>$i,
'answer'=>$this->answer[$i],

@ -195,7 +195,8 @@ function parse_file($exercisePath, $file, $questionFile) {
}
//parse XML question file
$data = str_replace(array('<p>', '</p>'), '', $data);
//used global variable start values declaration :
$record_item_body = false;
@ -533,7 +534,7 @@ function elementData($parser, $data) {
if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'])) {
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data);
} else {
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ' ' . trim($data);
$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ''.trim($data);
}
}
break;

@ -96,12 +96,13 @@ class ImsAnswerMultipleChoice extends Answer
*/
function imsExportResponses($questionIdent, $questionStatment)
{
$this->answerList = $this->getAnswersList();
$this->answerList = $this->getAnswersList(true);
$out = ' <choiceInteraction responseIdentifier="' . $questionIdent . '" >' . "\n";
$out .= ' <prompt> ' . $questionStatment . ' </prompt>'. "\n";
if (is_array($this->answerList)) {
foreach ($this->answerList as $current_answer)
{
foreach ($this->answerList as $current_answer) {
$out .= ' <simpleChoice identifier="answer_' . $current_answer['id'] . '" fixed="false">' . $current_answer['answer'];
if (isset($current_answer['comment']) && $current_answer['comment'] != '')
{
@ -120,7 +121,7 @@ class ImsAnswerMultipleChoice extends Answer
*/
function imsExportResponsesDeclaration($questionIdent)
{
$this->answerList = $this->getAnswersList();
$this->answerList = $this->getAnswersList(true);
$type = $this->getQuestionType();
if ($type == MCMA) $cardinality = 'multiple'; else $cardinality = 'single';
@ -130,8 +131,7 @@ class ImsAnswerMultipleChoice extends Answer
$out .= ' <correctResponse>'. "\n";
if (is_array($this->answerList)) {
foreach($this->answerList as $current_answer)
{
foreach($this->answerList as $current_answer) {
if ($current_answer['correct'])
{
$out .= ' <value>answer_'. $current_answer['id'] .'</value>'. "\n";
@ -170,7 +170,7 @@ class ImsAnswerFillInBlanks extends Answer
function imsExportResponses($questionIdent, $questionStatment)
{
global $charset;
$this->answerList = $this->getAnswersList();
$this->answerList = $this->getAnswersList(true);
//switch ($this->type)
//{
@ -179,8 +179,7 @@ class ImsAnswerFillInBlanks extends Answer
$text = '';
$text .= $this->answerText;
if (is_array($this->answerList)) {
foreach ($this->answerList as $key=>$answer)
{
foreach ($this->answerList as $key=>$answer) {
$key = $answer['id'];
$answer = $answer['answer'];
$len = api_strlen($answer);
@ -243,12 +242,12 @@ class ImsAnswerFillInBlanks extends Answer
function imsExportResponsesDeclaration($questionIdent)
{
$this->answerList = $this->getAnswersList();
$this->answerList = $this->getAnswersList(true);
$this->gradeList = $this->getGradesList();
$out = '';
if (is_array($this->answerList)) {
foreach ($this->answerList as $answerKey=>$answer)
{
foreach ($this->answerList as $answerKey=>$answer) {
$answerKey = $answer['id'];
$answer = $answer['answer'];
$out .= ' <responseDeclaration identifier="fill_' . $answerKey . '" cardinality="single" baseType="identifier">' . "\n";
@ -296,7 +295,7 @@ class ImsAnswerMatching extends Answer
*/
function imsExportResponses($questionIdent, $questionStatment)
{
$this->answerList = $this->getAnswersList();
$this->answerList = $this->getAnswersList(true);
$maxAssociation = max(count($this->leftList), count($this->rightList));
$out = "";
@ -341,7 +340,7 @@ class ImsAnswerMatching extends Answer
*/
function imsExportResponsesDeclaration($questionIdent)
{
$this->answerList = $this->getAnswersList();
$this->answerList = $this->getAnswersList(true);
$out = ' <responseDeclaration identifier="' . $questionIdent . '" cardinality="single" baseType="identifier">' . "\n";
$out .= ' <correctResponse>' . "\n";
@ -387,7 +386,7 @@ class ImsAnswerHotspot extends Answer
function imsExportResponses($questionIdent, $questionStatment, $questionDesc='', $questionMedia='')
{
global $charset;
$this->answerList = $this->getAnswersList();
$this->answerList = $this->getAnswersList(true);
$questionMedia = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/'.$questionMedia;
$mimetype = mime_content_type($questionMedia);
if(empty($mimetype)){
@ -446,7 +445,7 @@ class ImsAnswerHotspot extends Answer
function imsExportResponsesDeclaration($questionIdent)
{
$this->answerList = $this->getAnswersList();
$this->answerList = $this->getAnswersList(true);
$this->gradeList = $this->getGradesList();
$out = '';
$out .= ' <responseDeclaration identifier="hotspot_'.$questionIdent.'" cardinality="ordered" baseType="identifier">' . "\n";

Loading…
Cancel
Save