diff --git a/main/exercice/export/qti2/qti2_classes.php b/main/exercice/export/qti2/qti2_classes.php
index f947d87ee2..52e2c5b50f 100755
--- a/main/exercice/export/qti2/qti2_classes.php
+++ b/main/exercice/export/qti2/qti2_classes.php
@@ -90,17 +90,17 @@ class ImsAnswerMultipleChoice extends Answer
$this->answerList = $this->getAnswersList();
$out = ' ' . "\n";
$out .= ' ' . $questionStatment . ' '. "\n";
-
- foreach ($this->answerList as $current_answer)
- {
- $out .= ' ' . $current_answer['answer'];
- if (isset($current_answer['comment']) && $current_answer['comment'] != '')
- {
- $out .= '' . $current_answer['comment'] . '';
- }
- $out .= ''. "\n";
- }
-
+ if (is_array($this->answerList)) {
+ foreach ($this->answerList as $current_answer)
+ {
+ $out .= ' ' . $current_answer['answer'];
+ if (isset($current_answer['comment']) && $current_answer['comment'] != '')
+ {
+ $out .= '' . $current_answer['comment'] . '';
+ }
+ $out .= ''. "\n";
+ }
+ }
$out .= ' '. "\n";
return $out;
}
@@ -120,27 +120,29 @@ class ImsAnswerMultipleChoice extends Answer
//Match the correct answers
$out .= ' '. "\n";
-
- foreach($this->answerList as $current_answer)
- {
- if ($current_answer['correct'])
- {
- $out .= ' answer_'. $current_answer['id'] .''. "\n";
- }
- }
+ if (is_array($this->answerList)) {
+ foreach($this->answerList as $current_answer)
+ {
+ if ($current_answer['correct'])
+ {
+ $out .= ' answer_'. $current_answer['id'] .''. "\n";
+ }
+ }
+ }
$out .= ' '. "\n";
//Add the grading
$out .= ' '. "\n";
-
- foreach($this->answerList as $current_answer)
- {
- if (isset($current_answer['grade']))
- {
- $out .= ' '. "\n";
- }
- }
+ if (is_array($this->answerList)) {
+ foreach($this->answerList as $current_answer)
+ {
+ if (isset($current_answer['grade']))
+ {
+ $out .= ' '. "\n";
+ }
+ }
+ }
$out .= ' '. "\n";
$out .= ' '. "\n";
@@ -167,14 +169,15 @@ class ImsAnswerFillInBlanks extends Answer
// {
$text = '';
$text .= $this->answerText;
-
- foreach ($this->answerList as $key=>$answer)
- {
- $key = $answer['id'];
- $answer = $answer['answer'];
- $len = strlen($answer);
- $text = str_replace('['.$answer.']','', $text);
- }
+ if (is_array($this->answerList)) {
+ foreach ($this->answerList as $key=>$answer)
+ {
+ $key = $answer['id'];
+ $answer = $answer['answer'];
+ $len = strlen($answer);
+ $text = str_replace('['.$answer.']','', $text);
+ }
+ }
$out = $text;
// }
// break;
@@ -234,43 +237,44 @@ class ImsAnswerFillInBlanks extends Answer
$this->answerList = $this->getAnswersList();
$this->gradeList = $this->getGradesList();
$out = '';
-
- foreach ($this->answerList as $answerKey=>$answer)
- {
- $answerKey = $answer['id'];
- $answer = $answer['answer'];
- $out .= ' ' . "\n";
- $out .= ' '. "\n";
-
- //if ($this->type==TEXTFIELD_FILL)
- //{
- $out .= ' '.$answer.''. "\n";
- //}
- /*
- else
- {
- //find correct answer key to apply in manifest and output it
-
- foreach ($this->answerList as $choiceKey=>$correctAnswer)
- {
- if ($correctAnswer==$answer)
- {
- $out .= ' choice_c_'.$answerKey.'_'.$choiceKey.''. "\n";
- }
- }
- }
- */
- $out .= ' '. "\n";
-
- if (isset($this->gradeList[$answerKey]))
- {
- $out .= ' '. "\n";
- $out .= ' '. "\n";
- $out .= ' '. "\n";
- }
-
- $out .= ' '. "\n";
- }
+ if (is_array($this->answerList)) {
+ foreach ($this->answerList as $answerKey=>$answer)
+ {
+ $answerKey = $answer['id'];
+ $answer = $answer['answer'];
+ $out .= ' ' . "\n";
+ $out .= ' '. "\n";
+
+ //if ($this->type==TEXTFIELD_FILL)
+ //{
+ $out .= ' '.$answer.''. "\n";
+ //}
+ /*
+ else
+ {
+ //find correct answer key to apply in manifest and output it
+
+ foreach ($this->answerList as $choiceKey=>$correctAnswer)
+ {
+ if ($correctAnswer==$answer)
+ {
+ $out .= ' choice_c_'.$answerKey.'_'.$choiceKey.''. "\n";
+ }
+ }
+ }
+ */
+ $out .= ' '. "\n";
+
+ if (isset($this->gradeList[$answerKey]))
+ {
+ $out .= ' '. "\n";
+ $out .= ' '. "\n";
+ $out .= ' '. "\n";
+ }
+
+ $out .= ' '. "\n";
+ }
+ }
return $out;
}
@@ -294,12 +298,13 @@ class ImsAnswerMatching extends Answer
//add left column
$out .= ' '. "\n";
-
- foreach ($this->leftList as $leftKey=>$leftElement)
- {
- $out .= ' '. $leftElement['answer'] .''. "\n";
- }
-
+ if (is_array($this->leftList)) {
+ foreach ($this->leftList as $leftKey=>$leftElement)
+ {
+ $out .= ' '. $leftElement['answer'] .''. "\n";
+ }
+ }
+
$out .= ' '. "\n";
//add right column
@@ -308,12 +313,13 @@ class ImsAnswerMatching extends Answer
$i = 0;
- foreach($this->rightList as $rightKey=>$rightElement)
- {
- $out .= ' '. $rightElement['answer'] .''. "\n";
- $i++;
- }
-
+ if (is_array($this->rightList)) {
+ foreach($this->rightList as $rightKey=>$rightElement)
+ {
+ $out .= ' '. $rightElement['answer'] .''. "\n";
+ $i++;
+ }
+ }
$out .= ' '. "\n";
$out .= ''. "\n";
@@ -331,26 +337,29 @@ class ImsAnswerMatching extends Answer
$out .= ' ' . "\n";
$gradeArray = array();
-
- foreach ($this->leftList as $leftKey=>$leftElement)
- {
- $i=0;
- foreach ($this->rightList as $rightKey=>$rightElement)
- {
- if( ($leftElement['match'] == $rightElement['code']))
- {
- $out .= ' left_' . $leftKey . ' right_'.$i.''. "\n";
-
- $gradeArray['left_' . $leftKey . ' right_'.$i] = $leftElement['grade'];
- }
- $i++;
- }
- }
+ if (is_array($this->leftList)) {
+ foreach ($this->leftList as $leftKey=>$leftElement)
+ {
+ $i=0;
+ foreach ($this->rightList as $rightKey=>$rightElement)
+ {
+ if( ($leftElement['match'] == $rightElement['code']))
+ {
+ $out .= ' left_' . $leftKey . ' right_'.$i.''. "\n";
+
+ $gradeArray['left_' . $leftKey . ' right_'.$i] = $leftElement['grade'];
+ }
+ $i++;
+ }
+ }
+ }
$out .= ' '. "\n";
$out .= ' ' . "\n";
- foreach ($gradeArray as $gradeKey=>$grade)
- {
- $out .= ' ' . "\n";
+ if (is_array($gradeArray)) {
+ foreach ($gradeArray as $gradeKey=>$grade)
+ {
+ $out .= ' ' . "\n";
+ }
}
$out .= ' ' . "\n";
$out .= ' '. "\n";
@@ -380,37 +389,39 @@ class ImsAnswerHotspot extends Answer
$text .= ' '."\n";
$text .= ' '.$questionDesc.''."\n";
$text .= ' '."\n";
- foreach ($this->answerList as $key=>$answer)
- {
- $key = $answer['id'];
- $answerTxt = $answer['answer'];
- $len = strlen($answerTxt);
- //coords are transformed according to QTIv2 rules here: http://www.imsproject.org/question/qtiv2p1pd/imsqti_infov2p1pd.html#element10663
- $coords = '';
- $type = 'default';
- switch($answer['hotspot_type']){
- case 'square':
- $type = 'rect';
- $res = array();
- $coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/',$answer['hotspot_coord'],$res);
- $coords = $res[1].','.$res[2].','.((int)$res[1]+(int)$res[3]).",".((int)$res[2]+(int)$res[4]);
- break;
- case 'circle':
- $type = 'circle';
- $res = array();
- $coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/',$answer['hotspot_coord'],$res);
- $coords = $res[1].','.$res[2].','.sqrt(pow(($res[1]-$res[3]),2)+pow(($res[2]-$res[4])));
- break;
- case 'poly':
- $type = 'poly';
- $coords = str_replace(array(';','|'),array(',',','),$answer['hotspot_coord']);
- break;
- case 'delineation' :
- $type = 'delineation';
- $coords = str_replace(array(';','|'),array(',',','),$answer['hotspot_coord']);
- break;
- }
- $text .= ' '."\n";
+ if (is_array($this->answerList)) {
+ foreach ($this->answerList as $key=>$answer)
+ {
+ $key = $answer['id'];
+ $answerTxt = $answer['answer'];
+ $len = strlen($answerTxt);
+ //coords are transformed according to QTIv2 rules here: http://www.imsproject.org/question/qtiv2p1pd/imsqti_infov2p1pd.html#element10663
+ $coords = '';
+ $type = 'default';
+ switch($answer['hotspot_type']){
+ case 'square':
+ $type = 'rect';
+ $res = array();
+ $coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/',$answer['hotspot_coord'],$res);
+ $coords = $res[1].','.$res[2].','.((int)$res[1]+(int)$res[3]).",".((int)$res[2]+(int)$res[4]);
+ break;
+ case 'circle':
+ $type = 'circle';
+ $res = array();
+ $coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/',$answer['hotspot_coord'],$res);
+ $coords = $res[1].','.$res[2].','.sqrt(pow(($res[1]-$res[3]),2)+pow(($res[2]-$res[4])));
+ break;
+ case 'poly':
+ $type = 'poly';
+ $coords = str_replace(array(';','|'),array(',',','),$answer['hotspot_coord']);
+ break;
+ case 'delineation' :
+ $type = 'delineation';
+ $coords = str_replace(array(';','|'),array(',',','),$answer['hotspot_coord']);
+ break;
+ }
+ $text .= ' '."\n";
+ }
}
$text .= ' '."\n";
$out = $text;
@@ -431,14 +442,16 @@ class ImsAnswerHotspot extends Answer
$out = '';
$out .= ' ' . "\n";
$out .= ' '. "\n";
-
- foreach ($this->answerList as $answerKey=>$answer)
- {
- $answerKey = $answer['id'];
- $answer = $answer['answer'];
- $out .= ' '.$answerKey.''. "\n";
-
- }
+
+ if (is_array($this->answerList)) {
+ foreach ($this->answerList as $answerKey=>$answer)
+ {
+ $answerKey = $answer['id'];
+ $answer = $answer['answer'];
+ $out .= ' '.$answerKey.''. "\n";
+
+ }
+ }
$out .= ' '. "\n";
$out .= ' '. "\n";