Minor - format code, update docs

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 72a15d3bf4
commit 672635f566
  1. 32
      main/exercise/exercise.class.php
  2. 5
      main/exercise/matching.class.php
  3. 21
      main/inc/lib/exercise_show_functions.lib.php

@ -7039,7 +7039,6 @@ class Exercise
} }
$i = 1; $i = 1;
$select_items[0]['id'] = 0; $select_items[0]['id'] = 0;
$select_items[0]['letter'] = '--'; $select_items[0]['letter'] = '--';
$select_items[0]['answer'] = ''; $select_items[0]['answer'] = '';
@ -7056,7 +7055,13 @@ class Exercise
if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) { if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) {
$toolBar = 'TestFreeAnswerStrict'; $toolBar = 'TestFreeAnswerStrict';
} }
$form->addElement('html_editor', "choice[".$questionId."]", null, array('id' => "choice[".$questionId."]"), array('ToolbarSet' => $toolBar)); $form->addElement(
'html_editor',
"choice[".$questionId."]",
null,
array('id' => "choice[".$questionId."]"),
array('ToolbarSet' => $toolBar)
);
$form->setDefaults(array("choice[".$questionId."]" => $content)); $form->setDefaults(array("choice[".$questionId."]" => $content));
$s .= $form->returnForm(); $s .= $form->returnForm();
} elseif ($answerType == ORAL_EXPRESSION) { } elseif ($answerType == ORAL_EXPRESSION) {
@ -7091,13 +7096,12 @@ class Exercise
array('ToolbarSet' => 'TestFreeAnswer') array('ToolbarSet' => 'TestFreeAnswer')
); );
//$form->setDefaults(array("choice[".$questionId."]" => $content)); //$form->setDefaults(array("choice[".$questionId."]" => $content));
$s .= $form->return_form(); $s .= $form->returnForm();
} }
// Now navigate through the possible answers, using the max number of // Now navigate through the possible answers, using the max number of
// answers for the question as a limiter // answers for the question as a limiter
$lines_count = 1; // a counter for matching-type answers $lines_count = 1; // a counter for matching-type answers
if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
$header = Display::tag('th', get_lang('Options')); $header = Display::tag('th', get_lang('Options'));
foreach ($objQuestionTmp->options as $item) { foreach ($objQuestionTmp->options as $item) {
@ -7133,8 +7137,6 @@ class Exercise
$answer = $objAnswerTmp->selectAnswer($answerId); $answer = $objAnswerTmp->selectAnswer($answerId);
$answerCorrect = $objAnswerTmp->isCorrect($answerId); $answerCorrect = $objAnswerTmp->isCorrect($answerId);
$comment = $objAnswerTmp->selectComment($answerId); $comment = $objAnswerTmp->selectComment($answerId);
//$numAnswer = $objAnswerTmp->selectAutoId($answerId);
$numAnswer = $answerId; $numAnswer = $answerId;
$attributes = array(); $attributes = array();
@ -7183,7 +7185,6 @@ class Exercise
} else { } else {
$s .= $answer_input; $s .= $answer_input;
} }
} elseif (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_TRUE_FALSE, GLOBAL_MULTIPLE_ANSWER))) { } elseif (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_TRUE_FALSE, GLOBAL_MULTIPLE_ANSWER))) {
$input_id = 'choice-'.$questionId.'-'.$answerId; $input_id = 'choice-'.$questionId.'-'.$answerId;
$answer = Security::remove_XSS($answer); $answer = Security::remove_XSS($answer);
@ -7203,7 +7204,6 @@ class Exercise
if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
$s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />'; $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />';
$answer_input = '<label class="checkbox">'; $answer_input = '<label class="checkbox">';
$answer_input .= Display::input('checkbox', 'choice['.$questionId.']['.$numAnswer.']', $numAnswer, $attributes); $answer_input .= Display::input('checkbox', 'choice['.$questionId.']['.$numAnswer.']', $numAnswer, $attributes);
$answer_input .= $answer; $answer_input .= $answer;
@ -7221,7 +7221,6 @@ class Exercise
$s .= $answer_input; $s .= $answer_input;
} }
} elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
$my_choice = array(); $my_choice = array();
if (!empty($user_choice_array)) { if (!empty($user_choice_array)) {
foreach ($user_choice_array as $item) { foreach ($user_choice_array as $item) {
@ -7333,11 +7332,10 @@ class Exercise
$s.='</tr>'; $s.='</tr>';
} elseif ($answerType == FILL_IN_BLANKS) { } elseif ($answerType == FILL_IN_BLANKS) {
list($answer) = explode('::', $answer); list($answer) = explode('::', $answer);
// Correct answer // Correct answer
api_preg_match_all('/\[[^]]+\]/', $answer, $correct_answer_list); api_preg_match_all('/\[[^]]+\]/', $answer, $correct_answer_list);
//Student's answezr // Student's answer
if (isset($user_choice[0]['answer'])) { if (isset($user_choice[0]['answer'])) {
api_preg_match_all('/\[[^]]+\]/', $user_choice[0]['answer'], $student_answer_list); api_preg_match_all('/\[[^]]+\]/', $user_choice[0]['answer'], $student_answer_list);
$student_answer_list = $student_answer_list[0]; $student_answer_list = $student_answer_list[0];
@ -7386,12 +7384,12 @@ class Exercise
$s .= '<tr><td width="45%">'; $s .= '<tr><td width="45%">';
$parsed_answer = $answer; $parsed_answer = $answer;
$windowId = $questionId.'_'.$lines_count; $windowId = $questionId.'_'.$lines_count;
//left part questions // Left part questions
$s .= ' <div id="window_'.$windowId.'" class="window window_left_question window'.$questionId.'_question"> $s .= ' <div id="window_'.$windowId.'" class="window window_left_question window'.$questionId.'_question">
<b>'.$lines_count.'</b>.&nbsp'.$parsed_answer.' <b>'.$lines_count.'</b>.&nbsp'.$parsed_answer.'
</div> </div>
</td>'; </td>';
// middle part (matches selects) // Middle part (matches selects)
$s .= '<td width="10%" align="center">&nbsp;&nbsp;'; $s .= '<td width="10%" align="center">&nbsp;&nbsp;';
$s .= '<div style="display:block">'; $s .= '<div style="display:block">';
$s .= '<select id="window_'.$windowId.'_select" name="choice['.$questionId.']['.$numAnswer.']">'; $s .= '<select id="window_'.$windowId.'_select" name="choice['.$questionId.']['.$numAnswer.']">';
@ -7408,7 +7406,9 @@ class Exercise
$selectedValue = $val['id']; $selectedValue = $val['id'];
} }
} }
if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) { if (isset($user_choice[$matching_correct_answer]) &&
$val['id'] == $user_choice[$matching_correct_answer]['answer']
) {
$selected = 'selected="selected"'; $selected = 'selected="selected"';
$selectedValue = $val['id']; $selectedValue = $val['id'];
} }
@ -7431,7 +7431,6 @@ class Exercise
</script>'; </script>';
} }
$s .= '</select></div></td>'; $s .= '</select></div></td>';
$s.='<td width="45%" valign="top" >'; $s.='<td width="45%" valign="top" >';
if (isset($select_items[$lines_count])) { if (isset($select_items[$lines_count])) {
$s.= '<div id="window_'.$windowId.'_answer" class="window window_right_question"> $s.= '<div id="window_'.$windowId.'_answer" class="window window_right_question">
@ -7546,7 +7545,6 @@ class Exercise
if ($answerType == DRAGGABLE) { if ($answerType == DRAGGABLE) {
$s .= '</ul><div class="clear"></div>'; $s .= '</ul><div class="clear"></div>';
$counterAnswer = 1; $counterAnswer = 1;
foreach ($objAnswerTmp->answer as $answerId => $answer_item) { foreach ($objAnswerTmp->answer as $answerId => $answer_item) {
$answerCorrect = $objAnswerTmp->isCorrect($answerId); $answerCorrect = $objAnswerTmp->isCorrect($answerId);
@ -7566,10 +7564,8 @@ class Exercise
// destruction of the Answer object // destruction of the Answer object
unset($objAnswerTmp); unset($objAnswerTmp);
// destruction of the Question object // destruction of the Question object
unset($objQuestionTmp); unset($objQuestionTmp);
$html .= $s; $html .= $s;
return $html; return $html;
} elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) {

@ -141,7 +141,6 @@ class Matching extends Question
); );
$form->addHtml('<tr>'); $form->addHtml('<tr>');
$form->addHtml("<td>$i</td>"); $form->addHtml("<td>$i</td>");
$form->addText("answer[$i]", null); $form->addText("answer[$i]", null);
@ -151,6 +150,7 @@ class Matching extends Question
$matches, $matches,
['id' => 'matches_'.$i] ['id' => 'matches_'.$i]
); );
$form->addText( $form->addText(
"weighting[$i]", "weighting[$i]",
null, null,
@ -163,7 +163,6 @@ class Matching extends Question
$form->addHtml('</tbody></table>'); $form->addHtml('</tbody></table>');
$group = array(); $group = array();
$form->addGroup($group); $form->addGroup($group);
// DISPLAY OPTIONS // DISPLAY OPTIONS
@ -286,6 +285,8 @@ class Matching extends Question
* Check if a answer is correct * Check if a answer is correct
* @param int $position * @param int $position
* @param int $answer * @param int $answer
* @param int $questionId
*
* @return bool * @return bool
*/ */
public static function isCorrect($position, $answer, $questionId) public static function isCorrect($position, $answer, $questionId)

@ -269,14 +269,17 @@ class ExerciseShowFunctions
/** /**
* Display the answers to a multiple choice question * Display the answers to a multiple choice question
* @param int $feedback_type Feedback type * @param int $feedback_type Feedback type
* @param integer Answer type * @param int $answerType Answer type
* @param integer Student choice * @param int $studentChoice Student choice
* @param string Textual answer * @param string $answer Textual answer
* @param string Comment on answer * @param string $answerComment Comment on answer
* @param string Correct answer comment * @param string $answerCorrect Correct answer comment
* @param integer Exercise ID * @param int $id Exercise ID
* @param integer Question ID * @param int $questionId Question ID
* @param boolean Whether to show the answer comment or not * @param boolean $ans Whether to show the answer comment or not
* @param bool $resultsDisabled
* @param bool $showTotalScoreAndUserChoices
*
* @return void * @return void
*/ */
public static function display_unique_or_multiple_answer( public static function display_unique_or_multiple_answer(
@ -292,7 +295,6 @@ class ExerciseShowFunctions
$resultsDisabled, $resultsDisabled,
$showTotalScoreAndUserChoices $showTotalScoreAndUserChoices
) { ) {
$hide_expected_answer = false; $hide_expected_answer = false;
if ($feedback_type == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) { if ($feedback_type == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) {
$hide_expected_answer = true; $hide_expected_answer = true;
@ -309,7 +311,6 @@ class ExerciseShowFunctions
$icon = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox'; $icon = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
$icon .= $studentChoice?'_on':'_off'; $icon .= $studentChoice?'_on':'_off';
$icon .= '.gif'; $icon .= '.gif';
$iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox'; $iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
$iconAnswer .= $answerCorrect?'_on':'_off'; $iconAnswer .= $answerCorrect?'_on':'_off';
$iconAnswer .= '.gif'; $iconAnswer .= '.gif';

Loading…
Cancel
Save