From 06b5f5e9e2b324d05f7fa4a1f643ef5f9c5b93e7 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 25 Apr 2017 13:46:07 +0200 Subject: [PATCH] Minor - format code --- main/exercise/export/scorm/scorm_classes.php | 1723 +++++++++--------- main/inc/lib/internationalization.lib.php | 16 +- main/wiki/wiki.inc.php | 14 +- 3 files changed, 877 insertions(+), 876 deletions(-) diff --git a/main/exercise/export/scorm/scorm_classes.php b/main/exercise/export/scorm/scorm_classes.php index 349e895068..b39d526d39 100755 --- a/main/exercise/export/scorm/scorm_classes.php +++ b/main/exercise/export/scorm/scorm_classes.php @@ -20,159 +20,159 @@ class ScormQuestion extends Question { public $js_id; public $answer; - /** - * Returns the HTML + JS flow corresponding to one question - * - * @param int $questionId The question ID - * @param bool $standalone (ie including XML tag, DTD declaration, etc) - * @param int $js_id The JavaScript ID for this question. - * Due to the nature of interactions, we must have a natural sequence for - * questions in the generated JavaScript. - * @param integer $js_id + /** + * Returns the HTML + JS flow corresponding to one question + * + * @param int $questionId The question ID + * @param bool $standalone (ie including XML tag, DTD declaration, etc) + * @param int $js_id The JavaScript ID for this question. + * Due to the nature of interactions, we must have a natural sequence for + * questions in the generated JavaScript. + * @param integer $js_id * @return string|array - */ - public static function export_question($questionId, $standalone = true, $js_id) - { - $question = new ScormQuestion(); - $qst = $question->read($questionId); - if (!$qst) { - return ''; - } - $question->id = $qst->id; - $question->js_id = $js_id; - $question->type = $qst->type; - $question->question = $qst->question; - $question->description = $qst->description; - $question->weighting = $qst->weighting; - $question->position = $qst->position; - $question->picture = $qst->picture; - $assessmentItem = new ScormAssessmentItem($question, $standalone); - - return $assessmentItem->export(); - } - - /** - * Include the correct answer class and create answer - */ - public function setAnswer() - { - switch ($this->type) { - case MCUA: - $this->answer = new ScormAnswerMultipleChoice($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case MCMA: - case GLOBAL_MULTIPLE_ANSWER: - $this->answer = new ScormAnswerMultipleChoice($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case TF: - $this->answer = new ScormAnswerTrueFalse($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case FIB: - $this->answer = new ScormAnswerFillInBlanks($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case MATCHING: - case MATCHING_DRAGGABLE: - case DRAGGABLE: - $this->answer = new ScormAnswerMatching($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case ORAL_EXPRESSION: - case FREE_ANSWER: - $this->answer = new ScormAnswerFree($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case HOT_SPOT: - $this->answer = new ScormAnswerHotspot($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case MULTIPLE_ANSWER_COMBINATION: - $this->answer = new ScormAnswerMultipleChoice($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case HOT_SPOT_ORDER: - $this->answer = new ScormAnswerHotspot($this->id); - $this->answer->questionJSId = $this->js_id; - break; - case HOT_SPOT_DELINEATION: - $this->answer = new ScormAnswerHotspot($this->id); - $this->answer->questionJSId = $this->js_id; - break; - // not supported - case UNIQUE_ANSWER_NO_OPTION: - case MULTIPLE_ANSWER_TRUE_FALSE: - case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: - case UNIQUE_ANSWER_IMAGE: - case CALCULATED_ANSWER: - $this->answer = new ScormAnswerMultipleChoice($this->id); - $this->answer->questionJSId = $this->js_id; - break; - default: - $this->answer = new stdClass(); - $this->answer->questionJSId = $this->js_id; - break; - } - - return true; - } - - function export() - { - $html = $this->getQuestionHTML(); - $js = $this->getQuestionJS(); - - if (is_object($this->answer) && $this->answer instanceof Answer) { - list($js2, $html2) = $this->answer->export(); - $js .= $js2; - $html .= $html2; - } else { - throw new \Exception('Question not supported. Exercise: '.$this->selectTitle()); - } - - return array($js, $html); - } - - function createAnswersForm($form) - { - return true; - } - - function processAnswersCreation($form) - { - return true; - } - - /** - * Returns an HTML-formatted question - */ - function getQuestionHTML() - { + */ + public static function export_question($questionId, $standalone = true, $js_id) + { + $question = new ScormQuestion(); + $qst = $question->read($questionId); + if (!$qst) { + return ''; + } + $question->id = $qst->id; + $question->js_id = $js_id; + $question->type = $qst->type; + $question->question = $qst->question; + $question->description = $qst->description; + $question->weighting = $qst->weighting; + $question->position = $qst->position; + $question->picture = $qst->picture; + $assessmentItem = new ScormAssessmentItem($question, $standalone); + + return $assessmentItem->export(); + } + + /** + * Include the correct answer class and create answer + */ + public function setAnswer() + { + switch ($this->type) { + case MCUA: + $this->answer = new ScormAnswerMultipleChoice($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case MCMA: + case GLOBAL_MULTIPLE_ANSWER: + $this->answer = new ScormAnswerMultipleChoice($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case TF: + $this->answer = new ScormAnswerTrueFalse($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case FIB: + $this->answer = new ScormAnswerFillInBlanks($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case MATCHING: + case MATCHING_DRAGGABLE: + case DRAGGABLE: + $this->answer = new ScormAnswerMatching($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case ORAL_EXPRESSION: + case FREE_ANSWER: + $this->answer = new ScormAnswerFree($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case HOT_SPOT: + $this->answer = new ScormAnswerHotspot($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case MULTIPLE_ANSWER_COMBINATION: + $this->answer = new ScormAnswerMultipleChoice($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case HOT_SPOT_ORDER: + $this->answer = new ScormAnswerHotspot($this->id); + $this->answer->questionJSId = $this->js_id; + break; + case HOT_SPOT_DELINEATION: + $this->answer = new ScormAnswerHotspot($this->id); + $this->answer->questionJSId = $this->js_id; + break; + // not supported + case UNIQUE_ANSWER_NO_OPTION: + case MULTIPLE_ANSWER_TRUE_FALSE: + case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: + case UNIQUE_ANSWER_IMAGE: + case CALCULATED_ANSWER: + $this->answer = new ScormAnswerMultipleChoice($this->id); + $this->answer->questionJSId = $this->js_id; + break; + default: + $this->answer = new stdClass(); + $this->answer->questionJSId = $this->js_id; + break; + } + + return true; + } + + function export() + { + $html = $this->getQuestionHTML(); + $js = $this->getQuestionJS(); + + if (is_object($this->answer) && $this->answer instanceof Answer) { + list($js2, $html2) = $this->answer->export(); + $js .= $js2; + $html .= $html2; + } else { + throw new \Exception('Question not supported. Exercise: '.$this->selectTitle()); + } + + return array($js, $html); + } + + function createAnswersForm($form) + { + return true; + } + + function processAnswersCreation($form) + { + return true; + } + + /** + * Returns an HTML-formatted question + */ + function getQuestionHTML() + { $title = $this->selectTitle(); $description = $this->selectDescription(); - $cols = 2; - $s = ' - - '.$title.' - - - - - '.$description.' - - '; - return $s; - } - - /** - * Return the JavaScript code bound to the question - */ - public function getQuestionJS() - { - $weight = $this->selectWeighting(); - $js = 'questions.push('.$this->js_id.');'."\n"; + $cols = 2; + $s = ' + + '.$title.' + + + + + '.$description.' + + '; + return $s; + } + + /** + * Return the JavaScript code bound to the question + */ + public function getQuestionJS() + { + $weight = $this->selectWeighting(); + $js = 'questions.push('.$this->js_id.');'."\n"; switch ($this->type) { case ORAL_EXPRESSION: @@ -181,7 +181,7 @@ class ScormQuestion extends Question $script .= file_get_contents(api_get_path(LIBRARY_PATH) . 'wami-recorder/gui.js'); $js .= $script;*/ break; - case HOT_SPOT: + case HOT_SPOT: //put the max score to 0 to avoid discounting the points of //non-exported quiz types in the SCORM $weight = 0; @@ -189,8 +189,8 @@ class ScormQuestion extends Question } $js .= 'questions_score_max['.$this->js_id.'] = '.$weight.";"; - return $js; - } + return $js; + } } /** @@ -200,50 +200,50 @@ class ScormQuestion extends Question */ class ScormAnswerMultipleChoice extends Answer { - /** - * Return HTML code for possible answers - */ - function export() - { - $js = ''; - $html = ''; - $type = $this->getQuestionType(); - $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'; - $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'; + /** + * Return HTML code for possible answers + */ + function export() + { + $js = ''; + $html = ''; - - return array($js, $html); - } + $id++; + } + $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp, 0, -1).');'; + $js .= 'questions_types['.$this->questionJSId.'] = \'mcua\';'; + $js .= $jstmpw; + } + $html .= '
'; + $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) { + //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 = ''; + $jstmp = ''; + $jstmpc = ''; foreach ($this->answer as $i => $answer) { - $identifier = 'question_'.$this->questionJSId.'_multiple_'.$i; - $html .= - ' - - - '; - - $jstmp .= $i.','; + $identifier = 'question_'.$this->questionJSId.'_multiple_'.$i; + $html .= + ' + + + '; + + $jstmp .= $i.','; if ($this->correct[$i]) { $jstmpc .= $i.','; } - $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$this->weighting[$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"; + $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 = ''; + $js .= $jstmpw; + } elseif ($type == MULTIPLE_ANSWER_COMBINATION) { + $js = ''; $id = 1; $jstmp = ''; $jstmpc = ''; @@ -251,13 +251,13 @@ class ScormAnswerMultipleChoice extends Answer $identifier = 'question_'.$this->questionJSId.'_exact_'.$i; $html .= ' - - - '; + + + '; $jstmp .= $i.','; if ($this->correct[$i]) { @@ -270,38 +270,38 @@ class ScormAnswerMultipleChoice extends Answer $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp, 0, -1).');'; $js .= 'questions_types['.$this->questionJSId.'] = "exact";'; $js .= $jstmpw; - } else { - $id = 1; - $jstmp = ''; - $jstmpc = ''; + } 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 .= - ' - - - '; - $jstmp .= $i.','; + $identifier_name = 'question_'.$this->questionJSId.'_unique_answer'; + $html .= + ' + + + '; + $jstmp .= $i.','; if ($this->correct[$i]) { $jstmpc .= $i; } - $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$this->weighting[$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 array($js, $html); + } } /** @@ -310,51 +310,51 @@ class ScormAnswerMultipleChoice extends Answer */ class ScormAnswerTrueFalse extends Answer { - /** - * Return the XML flow for the possible answers. - * That's one , containing several - * - * @author Amand Tihon - */ - function export() - { - $js = ''; - $html = ''; - $identifier = 'question_'.$this->questionJSId.'_tf'; - $identifier_true = $identifier.'_true'; - $identifier_false = $identifier.'_false'; - $html .= - ' - - - '; - $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 array($js, $html); - } + /** + * Return the XML flow for the possible answers. + * That's one , containing several + * + * @author Amand Tihon + */ + function export() + { + $js = ''; + $html = ''; + $identifier = 'question_'.$this->questionJSId.'_tf'; + $identifier_true = $identifier.'_true'; + $identifier_false = $identifier.'_false'; + $html .= + ' + + + '; + $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 array($js, $html); + } } /** @@ -363,76 +363,76 @@ class ScormAnswerTrueFalse extends Answer */ class ScormAnswerFillInBlanks extends Answer { - /** - * Export the text with missing words. - * - * As a side effect, it stores two lists in the class : - * the missing words and their respective weightings. - */ - function export() - { - global $charset; - $js = ''; - $html = ''; - // get all enclosed answers - $blankList = array(); - // build replacement - $replacementList = array(); - foreach ($this->answer as $i => $answer) { - $blankList[] = '['.$answer.']'; - } - - // splits text and weightings that are joined with the character '::' - list($answer, $weight) = explode('::', $answer); - $weights = explode(',', $weight); - // because [] is parsed here we follow this procedure: - // 1. find everything between the [ and ] tags - $i = 1; - $jstmp = ''; - $jstmpc = ''; - $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; - $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; - $startlocations = api_strpos($answer, '['); - $endlocations = api_strpos($answer, ']'); - while ($startlocations !== false && $endlocations !== false) { - $texstring = api_substr($answer, $startlocations, ($endlocations - $startlocations) + 1); - $answer = api_substr_replace( + /** + * Export the text with missing words. + * + * As a side effect, it stores two lists in the class : + * the missing words and their respective weightings. + */ + function export() + { + global $charset; + $js = ''; + $html = ''; - $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.api_substr($jstmp, 0, -1).');'."\n"; - $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array('.api_substr($jstmpc, 0, -1).');'."\n"; - $js .= 'questions_types['.$this->questionJSId.'] = \'fib\';'."\n"; - $js .= $jstmpw; - - return array($js, $html); - } + $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$weight_db.";\n"; + $i++; + $startlocations = api_strpos($answer, '['); + $endlocations = api_strpos($answer, ']'); + } + + $html .= ' + +
'; + // get all enclosed answers + $blankList = array(); + // build replacement + $replacementList = array(); + foreach ($this->answer as $i => $answer) { + $blankList[] = '['.$answer.']'; + } + + // splits text and weightings that are joined with the character '::' + list($answer, $weight) = explode('::', $answer); + $weights = explode(',', $weight); + // because [] is parsed here we follow this procedure: + // 1. find everything between the [ and ] tags + $i = 1; + $jstmp = ''; + $jstmpc = ''; + $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n"; + $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n"; + $startlocations = api_strpos($answer, '['); + $endlocations = api_strpos($answer, ']'); + while ($startlocations !== false && $endlocations !== false) { + $texstring = api_substr($answer, $startlocations, ($endlocations - $startlocations) + 1); + $answer = api_substr_replace( $answer, '', $startlocations, ($endlocations - $startlocations) + 1 ); $jstmp .= $i.','; - if (!empty($texstring)) { - $sub = api_substr($texstring, 1, -1); - if (!empty($sub)) { - $jstmpc .= "'".api_htmlentities($sub, ENT_QUOTES, $charset)."',"; - } - } + if (!empty($texstring)) { + $sub = api_substr($texstring, 1, -1); + if (!empty($sub)) { + $jstmpc .= "'".api_htmlentities($sub, ENT_QUOTES, $charset)."',"; + } + } $my_weight = explode('@', $weights[$i - 1]); if (count($my_weight) == 2) { $weight_db = $my_weight[0]; } else { $weight_db = $my_weight[0]; } - $jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$weight_db.";\n"; - $i++; - $startlocations = api_strpos($answer, '['); - $endlocations = api_strpos($answer, ']'); - } - - $html .= ' - -
- '.$answer.' -
+ '.$answer.' +
'; + $js .= 'questions_answers['.$this->questionJSId.'] = new Array('.api_substr($jstmp, 0, -1).');'."\n"; + $js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array('.api_substr($jstmpc, 0, -1).');'."\n"; + $js .= 'questions_types['.$this->questionJSId.'] = \'fib\';'."\n"; + $js .= $jstmpw; + + return array($js, $html); + } } /** @@ -441,65 +441,65 @@ class ScormAnswerFillInBlanks extends Answer */ class ScormAnswerMatching extends Answer { - /** - * Export the question part as a matrix-choice, with only one possible answer per line. - * @author Amand Tihon - */ - 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 = array(); - $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 .= '"; - $s .= ''."\n"; - - return array($js, $html); - } + $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 .= '"; + $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 .= '
'.$cpt2.'. '.$answer."  
'; + // 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 = array(); + $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 .= '"; + $s .= ''; - $s .= ''; + $s .= '"; + $s .= ""; - $jstmpc .= '['.$answerCorrect.','.$cpt2.'],'; + $jstmpc .= '['.$answerCorrect.','.$cpt2.'],'; $my_weight = explode('@', $weight); if (count($my_weight) == 2) { @@ -507,32 +507,33 @@ class ScormAnswerMatching extends Answer } 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 .= '"; - $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 .= '
'.$cpt2.'. '.$answer."    '; + $s .= '  '; if (isset($Select[$cpt2])) { $s .= ''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse']; } else { $s .= ' '; } - $s .= "
 '; - $s .= ''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse']; - $s .= "
 '; + $s .= ''.$Select[$cpt2]['Lettre'].'. '.$Select[$cpt2]['Reponse']; + $s .= "
'."\n"; + + return array($js, $html); + } } /** @@ -541,19 +542,19 @@ class ScormAnswerMatching extends Answer */ class ScormAnswerFree extends Answer { - /** - * Export the text with missing words. - * - * As a side effect, it stores two lists in the class : - * the missing words and their respective weightings. - * - */ - function export() - { - $js = ''; + /** + * Export the text with missing words. + * + * As a side effect, it stores two lists in the class : + * the missing words and their respective weightings. + * + */ + function export() + { + $js = ''; $identifier = 'question_'.$this->questionJSId.'_free'; - // currently the free answers cannot be displayed, so ignore the textarea - $html = ''; + // currently the free answers cannot be displayed, so ignore the textarea + $html = ''; $type = $this->getQuestionType(); if ($type == ORAL_EXPRESSION) { @@ -565,21 +566,21 @@ class ScormAnswerFree extends Answer $layout = $template->get_template('document/record_audio.tpl'); $html .= $template->fetch($layout);*/ - $html = ''.get_lang('ThisItemIsNotExportable').''; + $html = ''.get_lang('ThisItemIsNotExportable').''; return array($js, $html); } $html .= ''; $html .= ''; - $js .= 'questions_answers['.$this->questionJSId.'] = new Array();'; - $js .= 'questions_answers_correct['.$this->questionJSId.'] = "";'; - $js .= 'questions_types['.$this->questionJSId.'] = \'free\';'; - $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = "0";'; - $js .= $jstmpw; - - return array($js, $html); - } + $js .= 'questions_answers['.$this->questionJSId.'] = new Array();'; + $js .= 'questions_answers_correct['.$this->questionJSId.'] = "";'; + $js .= 'questions_types['.$this->questionJSId.'] = \'free\';'; + $jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = "0";'; + $js .= $jstmpw; + + return array($js, $html); + } } /** * This class handles the SCORM export of hotpot questions @@ -587,63 +588,63 @@ class ScormAnswerFree extends Answer */ class ScormAnswerHotspot extends Answer { - /** - * Returns the javascript code that goes with HotSpot exercises - * @return string The JavaScript code - */ - function get_js_header() - { - if ($this->standalone) { - $header = ''; - //because this header closes so many times the '; + //because this header closes so many times the '; - if ($this->standalone) { - return ''; } return ''; - } - - /** - * Start the itemBody - * - */ - function start_body() - { - if ($this->standalone) { - return '
'; - } - - return ''; - } - - /** - * End the itemBody part. - * - */ - function end_body() - { - if ($this->standalone) { - return '
'; - } - - return ''; - } - - /** - * Export the question as a SCORM Item. - * This is a default behaviour, some classes may want to override this. - * @return string|array A string, the XML flow for an Item. - */ - function export() - { - list($js, $html) = $this->question->export(); - if ($this->standalone) { - $res = $this->start_page() - . $this->start_header() - . $this->css() - . $this->start_js() - . $this->common_js() - . $js - . $this->end_js() - . $this->end_header() - . $this->start_body() + } + + /** + * Start the itemBody + * + */ + function start_body() + { + if ($this->standalone) { + return '
'; + } + + return ''; + } + + /** + * End the itemBody part. + * + */ + function end_body() + { + if ($this->standalone) { + return '
'; + } + + return ''; + } + + /** + * Export the question as a SCORM Item. + * This is a default behaviour, some classes may want to override this. + * @return string|array A string, the XML flow for an Item. + */ + function export() + { + list($js, $html) = $this->question->export(); + if ($this->standalone) { + $res = $this->start_page() + . $this->start_header() + . $this->css() + . $this->start_js() + . $this->common_js() + . $js + . $this->end_js() + . $this->end_header() + . $this->start_body() . $html - . $this->end_body() - . $this->end_page(); - return $res; - } else { - return array($js, $html); - } - } + . $this->end_body() + . $this->end_page(); + return $res; + } else { + return array($js, $html); + } + } } /** @@ -923,103 +924,103 @@ class ScormAssessmentItem */ class ScormSection { - public $exercise; - public $standalone; - - /** - * Send a complete exercise in SCORM format, from its ID - * - * @param Exercise $exercise The exercise to export - * @param boolean $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 export_exercise_to_scorm(Exercise $exercise, $standalone = true) - { - $ims = new ScormSection($exercise); - $xml = $ims->export($standalone); - - return $xml; - } - - /** - * Constructor. - * @param Exercise $exe The Exercise instance to export - * @author Amand Tihon - */ - public function __construct($exe) - { - $this->exercise = $exe; - } - - /** - * Start the XML flow. - * - * This opens the block, with correct attributes. - * - */ - function start_page() - { + public $exercise; + public $standalone; + + /** + * Send a complete exercise in SCORM format, from its ID + * + * @param Exercise $exercise The exercise to export + * @param boolean $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 export_exercise_to_scorm(Exercise $exercise, $standalone = true) + { + $ims = new ScormSection($exercise); + $xml = $ims->export($standalone); + + return $xml; + } + + /** + * Constructor. + * @param Exercise $exe The Exercise instance to export + * @author Amand Tihon + */ + public function __construct($exe) + { + $this->exercise = $exe; + } + + /** + * Start the XML flow. + * + * This opens the block, with correct attributes. + * + */ + function start_page() + { $charset = 'UTF-8'; - $head = ''; - - return $head; - } - - /** - * End the XML flow, closing the tag. - * - */ - function end_page() - { - return ''; - } - - /** - * Start document header - */ - function start_header() - { - return ''; - } - - /** - * Print CSS inclusion - */ - private function css() - { - return ''; - } - - /** - * End document header - */ + $head = ''; + + return $head; + } + + /** + * End the XML flow, closing the tag. + * + */ + function end_page() + { + return ''; + } + + /** + * Start document header + */ + function start_header() + { + return ''; + } + + /** + * Print CSS inclusion + */ + private function css() + { + return ''; + } + + /** + * End document header + */ private function end_header() - { - return ''; - } - - /** - * Start the itemBody - * - */ + { + return ''; + } + + /** + * Start the itemBody + * + */ private function start_js() - { - return ''; + } + + /** + * Start the itemBody + * + */ + function start_body() + { + return ''. + '

'.$this->exercise->selectTitle().'

'.$this->exercise->selectDescription()."

". + '
'. + ''; + } + + /** + * End the itemBody part. + * + */ + function end_body() + { + return '

'; + } - /** - * End the itemBody part. - * - */ - function end_js() + /** + * Export the question as a SCORM Item. + * + * This is a default behaviour, some classes may want to override this. + * + * @param $standalone: Boolean stating if it should be exported as a stand-alone question + * @return string string, the XML flow for an Item. + */ + function export() { - return ''; - } - - /** - * Start the itemBody - * - */ - function start_body() - { - return ''. - '

'.$this->exercise->selectTitle().'

'.$this->exercise->selectDescription()."

". - '
'. - ''; - } - - /** - * End the itemBody part. - * - */ - function end_body() - { - return '

'; - } - - /** - * Export the question as a SCORM Item. - * - * This is a default behaviour, some classes may want to override this. - * - * @param $standalone: Boolean stating if it should be exported as a stand-alone question - * @return string string, the XML flow for an Item. - */ - function export() - { - global $charset; - - $head = ''; - if ($this->standalone) { - $head = ''."\n" - . ''."\n"; - } - - list($js, $html) = $this->export_questions(); - $res = $this->start_page() - . $this->start_header() - . $this->css() + global $charset; + + $head = ''; + if ($this->standalone) { + $head = ''."\n" + . ''."\n"; + } + + list($js, $html) = $this->export_questions(); + $res = $this->start_page() + . $this->start_header() + . $this->css() . $this->globalAssets() - . $this->start_js() - . $this->common_js() - . $js - . $this->end_js() - . $this->end_header() - . $this->start_body() - . $html - . $this->end_body() - . $this->end_page(); - - return $res; - } + . $this->start_js() + . $this->common_js() + . $js + . $this->end_js() + . $this->end_header() + . $this->start_body() + . $html + . $this->end_body() + . $this->end_page(); + + return $res; + } /** * @return string @@ -1144,21 +1145,21 @@ class ScormSection return $assets; } - /** - * Export the questions, as a succession of - * @author Amand Tihon - */ - function export_questions() - { - $js = $html = ""; - $js_id = 0; - foreach ($this->exercise->selectQuestionList() as $q) { - list($jstmp, $htmltmp) = ScormQuestion::export_question($q, false, $js_id); - $js .= $jstmp."\n"; - $html .= $htmltmp."\n"; - ++$js_id; - } - - return array($js, $html); - } + /** + * Export the questions, as a succession of + * @author Amand Tihon + */ + function export_questions() + { + $js = $html = ""; + $js_id = 0; + foreach ($this->exercise->selectQuestionList() as $q) { + list($jstmp, $htmltmp) = ScormQuestion::export_question($q, false, $js_id); + $js .= $jstmp."\n"; + $html .= $htmltmp."\n"; + ++$js_id; + } + + return array($js, $html); + } } diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index 0fcd0cb76d..951380cd5c 100755 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -59,11 +59,11 @@ define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER); /** * Returns a translated (localized) string, called by its identificator. - * @param string $variable This is the identificator (name) of the translated string to be retrieved. - * @param string $reserved This parameter has been reserved for future use. - * @param string $language (optional) Language indentificator. If it is omited, the current interface language is assumed. + * @param string $variable This is the identificator (name) of the translated string to be retrieved. + * @param string $reserved This parameter has been reserved for future use. + * @param string $language (optional) Language indentificator. If it is omited, the current interface language is assumed. * - * @return string Returns the requested string in the correspondent language. + * @return string Returns the requested string in the correspondent language. * * @author Roan Embrechts * @author Patrick Cool @@ -99,7 +99,7 @@ function get_lang($variable, $reserved = null, $language = null) { } if (!isset($used_lang_vars)) { - $used_lang_vars = array(); + $used_lang_vars = array(); } // Caching results from some API functions, for speed. @@ -156,10 +156,10 @@ function get_lang($variable, $reserved = null, $language = null) { /** * Gets the current interface language. - * @param bool $purified (optional) When it is true, a purified (refined) + * @param bool $purified (optional) When it is true, a purified (refined) * language value will be returned, for example 'french' instead of 'french_unicode'. * @param bool $setParentLanguageName - * @return string The current language of the interface. + * @return string The current language of the interface. */ function api_get_interface_language( $purified = false, @@ -301,7 +301,7 @@ function api_get_text_direction($language = null) static $text_direction = array(); if (empty($language)) { - $language = api_get_interface_language(); + $language = api_get_interface_language(); } if (!isset($text_direction[$language])) { $text_direction[$language] = in_array( diff --git a/main/wiki/wiki.inc.php b/main/wiki/wiki.inc.php index 450b881892..64cc2785dc 100755 --- a/main/wiki/wiki.inc.php +++ b/main/wiki/wiki.inc.php @@ -221,17 +221,17 @@ class Wiki foreach ($input_array as $key => $value) { //now doubles brackets - if (isset($input_array[$key-1]) && $input_array[$key-1] == '[[' AND - $input_array[$key+1] == ']]' + if (isset($input_array[$key-1]) && + $input_array[$key-1] == '[[' && $input_array[$key+1] == ']]' ) { // now full wikilink if (api_strpos($value, "|") !== false) { - $full_link_array=explode("|", $value); - $link=trim(strip_tags($full_link_array[0])); - $title=trim($full_link_array[1]); + $full_link_array = explode("|", $value); + $link = trim(strip_tags($full_link_array[0])); + $title = trim($full_link_array[1]); } else { - $link=trim(strip_tags($value)); - $title=trim($value); + $link = trim(strip_tags($value)); + $title = trim($value); } //if wikilink is homepage