From 7cf77ea7fb5c6d1b9bbcaf1c5637c6f95ca344f3 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 11 Aug 2010 17:01:56 +0200 Subject: [PATCH] Partial fix when trying to import qti exercises see BT#1368 --- main/exercice/answer.class.php | 9 +++++- main/exercice/export/exercise_import.inc.php | 5 ++-- main/exercice/export/qti2/qti2_classes.php | 31 ++++++++++---------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php index b3592277d8..1df188984b 100755 --- a/main/exercice/answer.class.php +++ b/main/exercice/answer.class.php @@ -266,11 +266,18 @@ class Answer * @author Yannick Warnier * @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], diff --git a/main/exercice/export/exercise_import.inc.php b/main/exercice/export/exercise_import.inc.php index 2d88651a36..701c9a4360 100755 --- a/main/exercice/export/exercise_import.inc.php +++ b/main/exercice/export/exercise_import.inc.php @@ -195,7 +195,8 @@ function parse_file($exercisePath, $file, $questionFile) { } //parse XML question file - + $data = str_replace(array('

', '

'), '', $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; diff --git a/main/exercice/export/qti2/qti2_classes.php b/main/exercice/export/qti2/qti2_classes.php index 2d4613c839..009d4ac2b8 100755 --- a/main/exercice/export/qti2/qti2_classes.php +++ b/main/exercice/export/qti2/qti2_classes.php @@ -96,12 +96,13 @@ class ImsAnswerMultipleChoice extends Answer */ function imsExportResponses($questionIdent, $questionStatment) { - $this->answerList = $this->getAnswersList(); + $this->answerList = $this->getAnswersList(true); $out = ' ' . "\n"; $out .= ' ' . $questionStatment . ' '. "\n"; if (is_array($this->answerList)) { - foreach ($this->answerList as $current_answer) - { + foreach ($this->answerList as $current_answer) { + + $out .= ' ' . $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 .= ' '. "\n"; if (is_array($this->answerList)) { - foreach($this->answerList as $current_answer) - { + foreach($this->answerList as $current_answer) { if ($current_answer['correct']) { $out .= ' answer_'. $current_answer['id'] .''. "\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 .= ' ' . "\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 = ' ' . "\n"; $out .= ' ' . "\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 .= ' ' . "\n";