diff --git a/composer.json b/composer.json
index efaf82a656..cc26ea0dbb 100755
--- a/composer.json
+++ b/composer.json
@@ -51,6 +51,7 @@
"symfony/validator": "~2.8",
"symfony/filesystem": "~2.8",
"symfony/security": "~2.8",
+ "symfony/serializer": "~3.0",
"doctrine/data-fixtures": "~1.0@dev",
"knplabs/gaufrette": "~0.3",
"gedmo/doctrine-extensions": "~2.3",
diff --git a/main/exercise/answer.class.php b/main/exercise/answer.class.php
index 30e6e98fb0..55b1b1b8a6 100755
--- a/main/exercise/answer.class.php
+++ b/main/exercise/answer.class.php
@@ -483,7 +483,7 @@ class Answer
}
$row = Database::fetch_array($res);
- return $row['type'];
+ return (int) $row['type'];
}
/**
diff --git a/main/exercise/export/scorm/ScormAnswerMatching.php b/main/exercise/export/scorm/ScormAnswerMatching.php
new file mode 100644
index 0000000000..3211901f11
--- /dev/null
+++ b/main/exercise/export/scorm/ScormAnswerMatching.php
@@ -0,0 +1,100 @@
+
+ */
+ public function export()
+ {
+ $js = '';
+ // prepare list of right proposition to allow
+ // - easiest display
+ // - easiest randomisation if needed one day
+ // (here I use array_values to change array keys from $code1 $code2 ... to 0 1 ...)
+ // get max length of displayed array
+ $nbrAnswers = $this->selectNbrAnswers();
+ $counter = 1;
+ $questionId = $this->questionJSId;
+ $jstmpw = 'questions_answers_ponderation['.$questionId.'] = new Array();'."\n";
+ $jstmpw .= 'questions_answers_ponderation['.$questionId.'][0] = 0;'."\n";
+
+ // Options (A, B, C, ...) that will be put into the list-box
+ $options = [];
+ $letter = 'A';
+ for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
+ $answerCorrect = $this->isCorrect($answerId);
+ $answer = $this->selectAnswer($answerId);
+ $realAnswerId = $this->selectAutoId($answerId);
+ if (!$answerCorrect) {
+ $options[$realAnswerId]['Lettre'] = $letter;
+ // answers that will be shown at the right side
+ $options[$realAnswerId]['Reponse'] = $answer;
+ $letter++;
+ }
+ }
+
+ $html = [];
+ $jstmp = '';
+ $jstmpc = '';
+
+ // Answers
+ for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
+ $identifier = 'question_'.$questionId.'_matching_';
+ $answer = $this->selectAnswer($answerId);
+ $answerCorrect = $this->isCorrect($answerId);
+ $weight = $this->selectWeighting($answerId);
+ $jstmp .= $answerId.',';
+
+ if ($answerCorrect) {
+ $html[] = '
';
+ //$html[] = ''.$counter.' . '.$answer." ";
+ $html[] = ' '.$answer." ";
+ $html[] = ' ';
+ $html[] = '';
+ $html[] = ' -- ';
+ // fills the list-box
+ foreach ($options as $key => $val) {
+ $html[] = ''.$val['Lettre'].' ';
+ }
+
+ $html[] = ' ';
+ $html[] = '';
+ foreach ($options as $key => $val) {
+ $html[] = ''.$val['Lettre'].'. '.$val['Reponse'].' ';
+ }
+ $html[] = ' ';
+
+ $jstmpc .= '['.$answerCorrect.','.$counter.'],';
+
+ $myWeight = explode('@', $weight);
+ if (count($myWeight) == 2) {
+ $weight = $myWeight[0];
+ } else {
+ $weight = $myWeight[0];
+ }
+ $jstmpw .= 'questions_answers_ponderation['.$questionId.']['.$counter.'] = '.$weight.";\n";
+ $counter++;
+ }
+ }
+
+ $js .= 'questions_answers['.$questionId.'] = new Array('.substr($jstmp, 0, -1).');'."\n";
+ $js .= 'questions_answers_correct['.$questionId.'] = new Array('.substr($jstmpc, 0, -1).');'."\n";
+ $js .= 'questions_types['.$questionId.'] = \'matching\';'."\n";
+ $js .= $jstmpw;
+
+ $htmlResult = '';
+ $htmlResult .= implode("\n", $html);
+ $htmlResult .= '
'."\n";
+
+ return [$js, $htmlResult];
+ }
+}
diff --git a/main/exercise/export/scorm/ScormAnswerMultipleChoice.php b/main/exercise/export/scorm/ScormAnswerMultipleChoice.php
new file mode 100644
index 0000000000..adba70cfaa
--- /dev/null
+++ b/main/exercise/export/scorm/ScormAnswerMultipleChoice.php
@@ -0,0 +1,119 @@
+getQuestionType();
+ $questionId = $this->questionJSId;
+ $jstmpw = 'questions_answers_ponderation['.$questionId.'] = new Array();';
+ $jstmpw .= 'questions_answers_ponderation['.$questionId.'][0] = 0;';
+ $jstmpw .= 'questions_answers_correct['.$questionId.'] = new Array();';
+ $html = [];
+
+ //not sure if we are going to export also the MULTIPLE_ANSWER_COMBINATION to SCORM
+ //if ($type == MCMA || $type == MULTIPLE_ANSWER_COMBINATION ) {
+ if ($type == MCMA) {
+ $id = 1;
+ $jstmp = '';
+ $jstmpc = '';
+ foreach ($this->answer as $i => $answer) {
+ $identifier = 'question_'.$questionId.'_multiple_'.$i;
+ $html[] =
+ '
+
+
+
+
+ '.Security::remove_XSS($this->answer[$i]).'
+
+ ';
+
+ $jstmp .= $i.',';
+ if ($this->correct[$i]) {
+ $jstmpc .= $i.',';
+ }
+ $jstmpw .= 'questions_answers_ponderation['.$questionId.']['.$i.'] = '.$this->weighting[$i].";";
+ $jstmpw .= 'questions_answers_correct['.$questionId.']['.$i.'] = '.$this->correct[$i].';';
+ $id++;
+ }
+ $js[] = 'questions_answers['.$questionId.'] = new Array('.substr($jstmp, 0, -1).');'."\n";
+ $js[] = 'questions_types['.$questionId.'] = \'mcma\';'."\n";
+ $js[] = $jstmpw;
+ } elseif ($type == MULTIPLE_ANSWER_COMBINATION) {
+ $js = '';
+ $id = 1;
+ $jstmp = '';
+ $jstmpc = '';
+ foreach ($this->answer as $i => $answer) {
+ $identifier = 'question_'.$questionId.'_exact_'.$i;
+ $html[] =
+ '
+
+
+
+
+ '.Security::remove_XSS($this->answer[$i]).'
+
+ ';
+
+ $jstmp .= $i.',';
+ if ($this->correct[$i]) {
+ $jstmpc .= $i.',';
+ }
+ $jstmpw .= 'questions_answers_ponderation['.$questionId.']['.$i.'] = '.$this->weighting[$i].';';
+ $jstmpw .= 'questions_answers_correct['.$questionId.']['.$i.'] = '.$this->correct[$i].';';
+ $id++;
+ }
+ $js[] = 'questions_answers['.$questionId.'] = new Array('.substr($jstmp, 0, -1).');';
+ $js[] = 'questions_types['.$questionId.'] = "exact";';
+ $js[] = $jstmpw;
+ } else {
+ $id = 1;
+ $jstmp = '';
+ $jstmpc = '';
+ foreach ($this->answer as $i => $answer) {
+ $identifier = 'question_'.$questionId.'_unique_'.$i;
+ $identifier_name = 'question_'.$questionId.'_unique_answer';
+ $html[] =
+ '
+
+
+
+
+ '.Security::remove_XSS($this->answer[$i]).'
+
+ ';
+ $jstmp .= $i.',';
+ if ($this->correct[$i]) {
+ $jstmpc .= $i;
+ }
+ $jstmpw .= 'questions_answers_ponderation['.$questionId.']['.$i.'] = '.$this->weighting[$i].';';
+ $jstmpw .= 'questions_answers_correct['.$questionId.']['.$i.'] = '.$this->correct[$i].';';
+ $id++;
+ }
+ $js[] = 'questions_answers['.$questionId.'] = new Array('.substr($jstmp, 0, -1).');';
+ $js[] = 'questions_types['.$questionId.'] = \'mcua\';';
+ $js[] = $jstmpw;
+ }
+
+ $htmlResult = '';
+ $htmlResult .= implode("\n", $html);
+ $htmlResult .= '
';
+
+ $js = implode("\n", $js);
+
+ return [$js, $htmlResult];
+ }
+}
diff --git a/main/exercise/export/scorm/ScormAnswerTrueFalse.php b/main/exercise/export/scorm/ScormAnswerTrueFalse.php
new file mode 100644
index 0000000000..5c92da6970
--- /dev/null
+++ b/main/exercise/export/scorm/ScormAnswerTrueFalse.php
@@ -0,0 +1,56 @@
+, containing several .
+ *
+ * @author Amand Tihon
+ */
+ public function export()
+ {
+ $js = '';
+ $html = ' ';
+ $js .= 'questions_answers['.$this->questionJSId.'] = new Array(\'true\',\'false\');'."\n";
+ $js .= 'questions_types['.$this->questionJSId.'] = \'tf\';'."\n";
+ if ($this->response === 'TRUE') {
+ $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array(\'true\');'."\n";
+ } else {
+ $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array(\'false\');'."\n";
+ }
+ $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n";
+ $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n";
+ $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = '.$this->weighting[1].";\n";
+ $js .= $jstmpw;
+
+ return [$js, $html];
+ }
+}
\ No newline at end of file
diff --git a/main/exercise/export/scorm/ScormAssessmentItem.php b/main/exercise/export/scorm/ScormAssessmentItem.php
index 3847167472..6ad67ac0f5 100644
--- a/main/exercise/export/scorm/ScormAssessmentItem.php
+++ b/main/exercise/export/scorm/ScormAssessmentItem.php
@@ -3,7 +3,7 @@
/**
* A SCORM item. It corresponds to a single question.
- * This class allows export from Dokeos SCORM 1.2 format of a single question.
+ * This class allows export from Chamilo SCORM 1.2 format of a single question.
* It is not usable as-is, but must be subclassed, to support different kinds of questions.
*
* Every start_*() and corresponding end_*(), as well as export_*() methods return a string.
@@ -17,19 +17,17 @@ class ScormAssessmentItem
public $question;
public $question_ident;
public $answer;
- public $standalone;
/**
* Constructor.
*
* @param ScormQuestion $question the Question object we want to export
*/
- public function __construct($question, $standalone = false)
+ public function __construct($question)
{
$this->question = $question;
$this->question->setAnswer();
- $this->questionIdent = "QST_".$question->id;
- $this->standalone = $standalone;
+ $this->questionIdent = 'QST_'.$question->id;
}
/**
@@ -40,11 +38,11 @@ class ScormAssessmentItem
public function start_page()
{
$head = '';
- if ($this->standalone) {
+ /*if ($this->standalone) {
$charset = 'UTF-8';
$head = '';
$head .= '';
- }
+ }*/
return $head;
}
@@ -54,9 +52,9 @@ class ScormAssessmentItem
*/
public function end_page()
{
- if ($this->standalone) {
+ /*if ($this->standalone) {
return '';
- }
+ }*/
return '';
}
@@ -66,9 +64,9 @@ class ScormAssessmentItem
*/
public function start_header()
{
- if ($this->standalone) {
+ /*if ($this->standalone) {
return '';
- }
+ }*/
return '';
}
@@ -79,16 +77,16 @@ class ScormAssessmentItem
public function css()
{
$css = '';
- if ($this->standalone) {
- $css = ''."\n";
- $css .= '';
- }
+// if ($this->standalone) {
+// $css = ''."\n";
+// $css .= '';
+// }
return $css;
}
@@ -98,9 +96,9 @@ class ScormAssessmentItem
*/
public function end_header()
{
- if ($this->standalone) {
- return '';
- }
+// if ($this->standalone) {
+// return '';
+// }
return '';
}
@@ -111,75 +109,21 @@ class ScormAssessmentItem
public function start_js()
{
$js = '';
- if ($this->standalone) {
- return '';
- }
+ }*/
return '';
}
@@ -189,9 +133,9 @@ class ScormAssessmentItem
*/
public function start_body()
{
- if ($this->standalone) {
+ /*if ($this->standalone) {
return '';
- }
+ }*/
return '';
}
@@ -217,7 +161,7 @@ class ScormAssessmentItem
public function export()
{
list($js, $html) = $this->question->export();
- if ($this->standalone) {
+ /*if ($this->standalone) {
$res = $this->start_page()
.$this->start_header()
.$this->css()
@@ -234,6 +178,7 @@ class ScormAssessmentItem
return $res;
} else {
return [$js, $html];
- }
+ }*/
+ return [$js, $html];
}
}
diff --git a/main/exercise/export/scorm/ScormSection.php b/main/exercise/export/scorm/ScormExercise.php
similarity index 50%
rename from main/exercise/export/scorm/ScormSection.php
rename to main/exercise/export/scorm/ScormExercise.php
index b697ea4609..ce53b87927 100644
--- a/main/exercise/export/scorm/ScormSection.php
+++ b/main/exercise/export/scorm/ScormExercise.php
@@ -1,6 +1,11 @@
containing several - .
@@ -11,42 +16,26 @@
* - max_attempts
* - show_answer
* - anonymous_attempts
+ * @author Julio Montoya
+ * @author Amand Tihon
*
* @package chamilo.exercise.scorm
*/
-class ScormSection
+class ScormExercise
{
public $exercise;
public $standalone;
/**
- * Constructor.
- *
- * @param Exercise $exe The Exercise instance to export
+ * ScormExercise constructor.
*
- * @author Amand Tihon
+ * @param Exercise $exe
+ * @param bool $standalone
*/
- public function __construct($exe)
+ public function __construct($exe, $standalone)
{
$this->exercise = $exe;
- }
-
- /**
- * Send a complete exercise in SCORM format, from its ID.
- *
- * @param Exercise $exercise The exercise to export
- * @param bool $standalone wether it should include XML tag and DTD line
- *
- * @return string XML as a string, or an empty string if there's no exercise with given ID
- */
- public static function exportExerciseToScorm(
- Exercise $exercise,
- $standalone = true
- ) {
- $ims = new ScormSection($exercise);
- $xml = $ims->export($standalone);
-
- return $xml;
+ $this->standalone = $standalone;
}
/**
@@ -54,7 +43,7 @@ class ScormSection
*
* This opens the - block, with correct attributes.
*/
- public function start_page()
+ public function startPage()
{
$charset = 'UTF-8';
$head = '';
@@ -83,57 +72,7 @@ class ScormSection
*/
public function common_js()
{
- $js = file_get_contents('../inc/lib/javascript/hotspot/js/hotspot.js');
-
- $js .= 'var questions = new Array();'."\n";
- $js .= 'var questions_answers = new Array();'."\n";
- $js .= 'var questions_answers_correct = new Array();'."\n";
- $js .= 'var questions_types = new Array();'."\n";
- $js .= "\n".
- '/**
- * Assigns any event handler to any element
- * @param object Element on which the event is added
- * @param string Name of event
- * @param string Function to trigger on event
- * @param boolean Capture the event and prevent
- */
- function addEvent(elm, evType, fn, useCapture)
- { //by Scott Andrew
- if(elm.addEventListener){
- elm.addEventListener(evType, fn, useCapture);
- return true;
- } else if(elm.attachEvent) {
- var r = elm.attachEvent(\'on\' + evType, fn);
- return r;
- } else {
- elm[\'on\' + evType] = fn;
- }
- }
- /**
- * Adds the event listener
- */
- function addListeners(e) {
- loadPage();
- /*
- var my_form = document.getElementById(\'dokeos_scorm_form\');
- addEvent(my_form,\'submit\',checkAnswers,false);
- */
- var my_button = document.getElementById(\'dokeos_scorm_submit\');
- addEvent(my_button,\'click\',doQuit,false);
- addEvent(my_button,\'click\',disableButton,false);
- //addEvent(my_button,\'click\',checkAnswers,false);
- //addEvent(my_button,\'change\',checkAnswers,false);
- addEvent(window,\'unload\',unloadPage,false);
- }
- /** Disables the submit button on SCORM result submission **/
- function disableButton() {
- var mybtn = document.getElementById(\'dokeos_scorm_submit\');
- mybtn.setAttribute(\'disabled\',\'disabled\');
- }
- '."\n";
-
- $js .= '';
- $js .= 'addEvent(window,\'load\',addListeners,false);'."\n";
+ $js = file_get_contents(api_get_path(SYS_CODE_PATH).'exercise/export/scorm/common.js');
return $js."\n";
}
@@ -153,7 +92,7 @@ class ScormSection
{
return ''.
'
'.$this->exercise->selectTitle().' '.$this->exercise->selectDescription()."
".
- '';
+ $button = ' ';
+
+ return ' '.$button.'';
}
/**
@@ -178,14 +124,14 @@ class ScormSection
{
global $charset;
- $head = '';
+ /*$head = '';
if ($this->standalone) {
$head = ''."\n"
.''."\n";
- }
+ }*/
- list($js, $html) = $this->export_questions();
- $res = $this->start_page()
+ list($js, $html) = $this->exportQuestions();
+ $res = $this->startPage()
.$this->start_header()
.$this->css()
.$this->globalAssets()
@@ -207,15 +153,30 @@ class ScormSection
*
* @author Amand Tihon
*/
- public function export_questions()
+ public function exportQuestions()
{
$js = $html = '';
- $js_id = 0;
+
+ $encoders = array(new JsonEncoder());
+ $normalizers = array(new ObjectNormalizer());
+
+ $em = Database::getManager();
+ // Export cquiz
+ /** @var CQuiz $exercise */
+ $exercise = $em->find('ChamiloCourseBundle:CQuiz', $this->exercise->iId);
+ $exercise->setDescription('');
+ $exercise->setTextWhenFinished('');
+
+ $serializer = new Serializer($normalizers, $encoders);
+ $jsonContent = $serializer->serialize($exercise, 'json');
+ $js .= "var exerciseInfo = JSON.parse('".$jsonContent."');\n";
+
+ $counter = 0;
foreach ($this->exercise->selectQuestionList() as $q) {
- list($jstmp, $htmltmp) = ScormQuestion::export_question($q, false, $js_id);
+ list($jstmp, $htmltmp) = ScormQuestion::exportQuestion($q, $counter);
$js .= $jstmp."\n";
$html .= $htmltmp."\n";
- $js_id++;
+ $counter++;
}
return [$js, $html];
@@ -250,8 +211,8 @@ class ScormSection
*/
private function globalAssets()
{
- $assets = '';
- $assets .= '';
+ $assets = ''."\n";
+ $assets .= ''."\n";
$assets .= ' ';
return $assets;
diff --git a/main/exercise/export/scorm/ScormQuestion.php b/main/exercise/export/scorm/ScormQuestion.php
index b912bef158..86bc415b8f 100644
--- a/main/exercise/export/scorm/ScormQuestion.php
+++ b/main/exercise/export/scorm/ScormQuestion.php
@@ -32,9 +32,8 @@ class ScormQuestion extends Question
*
* @return string|array
*/
- public static function export_question(
+ public static function exportQuestion(
$questionId,
- $standalone = true,
$js_id
) {
$question = new ScormQuestion();
@@ -50,7 +49,7 @@ class ScormQuestion extends Question
$question->weighting = $qst->weighting;
$question->position = $qst->position;
$question->picture = $qst->picture;
- $assessmentItem = new ScormAssessmentItem($question, $standalone);
+ $assessmentItem = new ScormAssessmentItem($question);
return $assessmentItem->export();
}
@@ -188,7 +187,14 @@ class ScormQuestion extends Question
public function getQuestionJS()
{
$weight = $this->selectWeighting();
- $js = 'questions.push('.$this->js_id.');'."\n";
+ $js = '
+ questions.push('.$this->js_id.');
+ $(document).ready(function() {
+ if (exerciseInfo.randomAnswers == true) {
+ $("#question_'.$this->js_id.'").shuffleRows();
+ }
+ });';
+ $js .= "\n";
switch ($this->type) {
case ORAL_EXPRESSION:
diff --git a/main/exercise/export/scorm/common.js b/main/exercise/export/scorm/common.js
new file mode 100644
index 0000000000..7d8cb88461
--- /dev/null
+++ b/main/exercise/export/scorm/common.js
@@ -0,0 +1,25 @@
+var questions = new Array();
+var questions_answers = new Array();
+var questions_answers_correct = new Array();
+var questions_types = new Array();
+var questions_score_max = new Array();
+var questions_answers_ponderation = new Array();
+
+/**
+ * Adds the event listener
+ */
+function addListeners(e) {
+ loadPage();
+ var myButton = document.getElementById('chamilo_scorm_submit');
+ addEvent(myButton, 'click', doQuit, false);
+ addEvent(myButton, 'click', disableButton, false);
+ addEvent(window, 'unload', unloadPage, false);
+}
+
+/** Disables the submit button on SCORM result submission **/
+function disableButton() {
+ var mybtn = document.getElementById('chamilo_scorm_submit');
+ mybtn.setAttribute('disabled', 'disabled');
+}
+
+addEvent(window,'load', addListeners, false);
\ No newline at end of file
diff --git a/main/exercise/export/scorm/scorm_classes.php b/main/exercise/export/scorm/scorm_classes.php
index 676de10a70..379cb887f8 100755
--- a/main/exercise/export/scorm/scorm_classes.php
+++ b/main/exercise/export/scorm/scorm_classes.php
@@ -1,171 +1,6 @@
';
- $type = $this->getQuestionType();
- $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();';
- $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;';
- $jstmpw .= 'questions_answers_correct['.$this->questionJSId.'] = new Array();';
-
- //not sure if we are going to export also the MULTIPLE_ANSWER_COMBINATION to SCORM
- //if ($type == MCMA || $type == MULTIPLE_ANSWER_COMBINATION ) {
- if ($type == MCMA) {
- $id = 1;
- $jstmp = '';
- $jstmpc = '';
- foreach ($this->answer as $i => $answer) {
- $identifier = 'question_'.$this->questionJSId.'_multiple_'.$i;
- $html .=
- '
-
-
-
-
- '.Security::remove_XSS($this->answer[$i]).'
-
- ';
-
- $jstmp .= $i.',';
- if ($this->correct[$i]) {
- $jstmpc .= $i.',';
- }
- $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$this->weighting[$i].";";
- $jstmpw .= 'questions_answers_correct['.$this->questionJSId.']['.$i.'] = '.$this->correct[$i].';';
- $id++;
- }
- $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp, 0, -1).');'."\n";
- $js .= 'questions_types['.$this->questionJSId.'] = \'mcma\';'."\n";
- $js .= $jstmpw;
- } elseif ($type == MULTIPLE_ANSWER_COMBINATION) {
- $js = '';
- $id = 1;
- $jstmp = '';
- $jstmpc = '';
- foreach ($this->answer as $i => $answer) {
- $identifier = 'question_'.$this->questionJSId.'_exact_'.$i;
- $html .=
- '
-
-
-
-
- '.Security::remove_XSS($this->answer[$i]).'
-
- ';
-
- $jstmp .= $i.',';
- if ($this->correct[$i]) {
- $jstmpc .= $i.',';
- }
- $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$this->weighting[$i].";";
- $jstmpw .= 'questions_answers_correct['.$this->questionJSId.']['.$i.'] = '.$this->correct[$i].";";
- $id++;
- }
- $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp, 0, -1).');';
- $js .= 'questions_types['.$this->questionJSId.'] = "exact";';
- $js .= $jstmpw;
- } else {
- $id = 1;
- $jstmp = '';
- $jstmpc = '';
- foreach ($this->answer as $i => $answer) {
- $identifier = 'question_'.$this->questionJSId.'_unique_'.$i;
- $identifier_name = 'question_'.$this->questionJSId.'_unique_answer';
- $html .=
- '
-
-
-
-
- '.Security::remove_XSS($this->answer[$i]).'
-
- ';
- $jstmp .= $i.',';
- if ($this->correct[$i]) {
- $jstmpc .= $i;
- }
- $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$this->weighting[$i].";";
- $jstmpw .= 'questions_answers_correct['.$this->questionJSId.']['.$i.'] = '.$this->correct[$i].';';
- $id++;
- }
- $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp, 0, -1).');';
- $js .= 'questions_types['.$this->questionJSId.'] = \'mcua\';';
- $js .= $jstmpw;
- }
- $html .= '
';
-
- return [$js, $html];
- }
-}
-
-/**
- * This class handles the SCORM export of true/false questions.
- *
- * @package chamilo.exercise.scorm
- */
-class ScormAnswerTrueFalse extends Answer
-{
- /**
- * Return the XML flow for the possible answers.
- * That's one , containing several .
- *
- * @author Amand Tihon
- */
- public function export()
- {
- $js = '';
- $html = ' ';
- $js .= 'questions_answers['.$this->questionJSId.'] = new Array(\'true\',\'false\');'."\n";
- $js .= 'questions_types['.$this->questionJSId.'] = \'tf\';'."\n";
- if ($this->response === 'TRUE') {
- $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array(\'true\');'."\n";
- } else {
- $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array(\'false\');'."\n";
- }
- $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n";
- $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n";
- $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = '.$this->weighting[1].";\n";
- $js .= $jstmpw;
-
- return [$js, $html];
- }
-}
-
/**
* This class handles the SCORM export of fill-in-the-blanks questions.
*
@@ -243,107 +78,6 @@ class ScormAnswerFillInBlanks extends Answer
}
}
-/**
- * This class handles the SCORM export of matching questions.
- *
- * @package chamilo.exercise.scorm
- */
-class ScormAnswerMatching extends Answer
-{
- /**
- * Export the question part as a matrix-choice, with only one possible answer per line.
- *
- * @author Amand Tihon
- */
- public function export()
- {
- $js = '';
- $html = '';
- // prepare list of right proposition to allow
- // - easiest display
- // - easiest randomisation if needed one day
- // (here I use array_values to change array keys from $code1 $code2 ... to 0 1 ...)
- // get max length of displayed array
-
- $nbrAnswers = $this->selectNbrAnswers();
- $cpt1 = 'A';
- $cpt2 = 1;
- $Select = [];
- $qId = $this->questionJSId;
- $s = '';
- $jstmp = '';
- $jstmpc = '';
- $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n";
- $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n";
-
- for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
- $identifier = 'question_'.$qId.'_matching_';
- $answer = $this->selectAnswer($answerId);
- $answerCorrect = $this->isCorrect($answerId);
- $weight = $this->selectWeighting($answerId);
- $jstmp .= $answerId.',';
-
- if (!$answerCorrect) {
- // options (A, B, C, ...) that will be put into the list-box
- $Select[$answerId]['Lettre'] = $cpt1;
- // answers that will be shown at the right side
- $Select[$answerId]['Reponse'] = $answer;
- $cpt1++;
- } else {
- $s .= '';
- $s .= ''.$cpt2.' . '.$answer." ";
- $s .= ' ';
- $s .= ' -- ';
- // fills the list-box
- foreach ($Select as $key => $val) {
- $s .= ''.$val['Lettre'].' ';
- } // end foreach()
-
- $s .= ' ';
- $s .= '';
- if (isset($Select[$cpt2])) {
- $s .= ''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse'];
- } else {
- $s .= ' ';
- }
- $s .= " ";
-
- $jstmpc .= '['.$answerCorrect.','.$cpt2.'],';
-
- $my_weight = explode('@', $weight);
- if (count($my_weight) == 2) {
- $weight = $my_weight[0];
- } else {
- $weight = $my_weight[0];
- }
- $jstmpw .= 'questions_answers_ponderation['.$qId.']['.$cpt2.'] = '.$weight.";\n";
- $cpt2++;
-
- // if the left side of the "matching" has been completely shown
- if ($answerId == $nbrAnswers) {
- // if there remain answers to be shown on the right side
- while (isset($Select[$cpt2])) {
- $s .= '';
- $s .= ' ';
- $s .= '';
- $s .= ''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse'];
- $s .= " ";
- $cpt2++;
- }
- // end while()
- } // end if()
- }
- }
- $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp, 0, -1).');'."\n";
- $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array('.substr($jstmpc, 0, -1).');'."\n";
- $js .= 'questions_types['.$this->questionJSId.'] = \'matching\';'."\n";
- $js .= $jstmpw;
- $html .= $s;
- $html .= '
'."\n";
-
- return [$js, $html];
- }
-}
/**
* This class handles the SCORM export of free-answer questions.
@@ -406,10 +140,11 @@ class ScormAnswerHotspot extends Answer
*/
public function get_js_header()
{
+ $header = '';
+
if ($this->standalone) {
- $header = '';
//because this header closes so many times the