*/ 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[] = ' '.$answer.""; $html[] = '  '; $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]; } }