Requires composer update to install new serializer.pull/2606/head
parent
2d4b5b8858
commit
9ce5eb789a
@ -0,0 +1,100 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* 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 <amand@alrj.org> |
||||
*/ |
||||
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[] = '<tr class="option_row">'; |
||||
//$html[] = '<td width="40%" valign="top"><b>'.$counter.'</b>. '.$answer."</td>"; |
||||
$html[] = '<td width="40%" valign="top"> '.$answer."</td>"; |
||||
$html[] = '<td width="20%" align="center"> '; |
||||
$html[] = '<select name="'.$identifier.$counter.'" id="'.$identifier.$counter.'">'; |
||||
$html[] = ' <option value="0">--</option>'; |
||||
// fills the list-box |
||||
foreach ($options as $key => $val) { |
||||
$html[] = '<option value="'.$key.'">'.$val['Lettre'].'</option>'; |
||||
} |
||||
|
||||
$html[] = '</select> </td>'; |
||||
$html[] = '<td width="40%" valign="top">'; |
||||
foreach ($options as $key => $val) { |
||||
$html[] = '<b>'.$val['Lettre'].'.</b> '.$val['Reponse'].'<br />'; |
||||
} |
||||
$html[] = '</td></tr>'; |
||||
|
||||
$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 = '<tr><td colspan="2"><table id="question_'.$questionId.'" width="100%">'; |
||||
$htmlResult .= implode("\n", $html); |
||||
$htmlResult .= '</table></td></tr>'."\n"; |
||||
|
||||
return [$js, $htmlResult]; |
||||
} |
||||
} |
||||
@ -0,0 +1,119 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* This class handles the export to SCORM of a multiple choice question |
||||
* (be it single answer or multiple answers). |
||||
* |
||||
* @package chamilo.exercise.scorm |
||||
*/ |
||||
class ScormAnswerMultipleChoice extends Answer |
||||
{ |
||||
/** |
||||
* Return HTML code for possible answers. |
||||
*/ |
||||
public function export() |
||||
{ |
||||
$js = []; |
||||
$type = $this->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[] = |
||||
'<tr> |
||||
<td align="center" width="5%"> |
||||
<input name="'.$identifier.'" id="'.$identifier.'" value="'.$i.'" type="checkbox" /> |
||||
</td> |
||||
<td width="95%"> |
||||
<label for="'.$identifier.'">'.Security::remove_XSS($this->answer[$i]).'</label> |
||||
</td> |
||||
</tr>'; |
||||
|
||||
$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[] = |
||||
'<tr> |
||||
<td align="center" width="5%"> |
||||
<input name="'.$identifier.'" id="'.$identifier.'" value="'.$i.'" type="checkbox" /> |
||||
</td> |
||||
<td width="95%"> |
||||
<label for="'.$identifier.'">'.Security::remove_XSS($this->answer[$i]).'</label> |
||||
</td> |
||||
</tr>'; |
||||
|
||||
$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[] = |
||||
'<tr> |
||||
<td align="center" width="5%"> |
||||
<input name="'.$identifier_name.'" id="'.$identifier.'" value="'.$i.'" type="checkbox"/> |
||||
</td> |
||||
<td width="95%"> |
||||
<label for="'.$identifier.'">'.Security::remove_XSS($this->answer[$i]).'</label> |
||||
</td> |
||||
</tr>'; |
||||
$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 = '<tr><td colspan="2"><table id="question_'.$questionId.'" width="100%">'; |
||||
$htmlResult .= implode("\n", $html); |
||||
$htmlResult .= '</table></td></tr>'; |
||||
|
||||
$js = implode("\n", $js); |
||||
|
||||
return [$js, $htmlResult]; |
||||
} |
||||
} |
||||
@ -0,0 +1,56 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* 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 <response_lid>, containing several <flow_label>. |
||||
* |
||||
* @author Amand Tihon <amand@alrj.org> |
||||
*/ |
||||
public function export() |
||||
{ |
||||
$js = ''; |
||||
$html = '<tr><td colspan="2"><table width="100%">'; |
||||
$identifier = 'question_'.$this->questionJSId.'_tf'; |
||||
$identifier_true = $identifier.'_true'; |
||||
$identifier_false = $identifier.'_false'; |
||||
$html .= |
||||
'<tr> |
||||
<td align="center" width="5%"> |
||||
<input name="'.$identifier_true.'" id="'.$identifier_true.'" value="'.$this->trueGrade.'" type="radio" /> |
||||
</td> |
||||
<td width="95%"> |
||||
<label for="'.$identifier_true.'">'.get_lang('True').'</label> |
||||
</td> |
||||
</tr>'; |
||||
$html .= |
||||
'<tr> |
||||
<td align="center" width="5%"> |
||||
<input name="'.$identifier_false.'" id="'.$identifier_false.'" value="'.$this->falseGrade.'" type="radio" /> |
||||
</td> |
||||
<td width="95%"> |
||||
<label for="'.$identifier_false.'">'.get_lang('False').'</label> |
||||
</td> |
||||
</tr></table></td></tr>'; |
||||
$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]; |
||||
} |
||||
} |
||||
@ -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); |
||||
Loading…
Reference in new issue