Minor - Coding conventions + comments

1.9.x
Yannick Warnier 11 years ago
parent 02d3aa4b23
commit f5578b4c5a
  1. 2
      main/exercice/exercise.class.php
  2. 8
      main/exercice/exercise.lib.php
  3. 85
      main/exercice/fill_blanks.class.php

@ -2480,7 +2480,7 @@ class Exercise
WHERE exe_id = $exeId WHERE exe_id = $exeId
AND question_id= ".intval($questionId); AND question_id= ".intval($questionId);
$resfill = Database::query($queryfill); $resfill = Database::query($queryfill);
$str = Database::result($resfill,0,'answer'); $str = Database::result($resfill, 0, 'answer');
$listStudentResults = FillBlanks::getAnswerInfo($str, true); $listStudentResults = FillBlanks::getAnswerInfo($str, true);
$choice = $listStudentResults['studentanswer']; $choice = $listStudentResults['studentanswer'];

@ -445,7 +445,7 @@ function showQuestion(
list($answer) = explode('::', $answer); list($answer) = explode('::', $answer);
//Correct answer //Correct answers
$correctAnswerList = $listAnswerInformations['tabwords']; $correctAnswerList = $listAnswerInformations['tabwords'];
//Student's answer //Student's answer
@ -455,7 +455,7 @@ function showQuestion(
$studentAnswerList = $arrayStudentAnswer['studentanswer']; $studentAnswerList = $arrayStudentAnswer['studentanswer'];
} }
// If display the question with answer (in page exercice/admin.php) for teacher preview // If the question must be shown with the answer (in page exercice/admin.php) for teacher preview
// set the student-answer to the correct answer // set the student-answer to the correct answer
if ($debug_mark_answer) { if ($debug_mark_answer) {
$studentAnswerList = $correctAnswerList; $studentAnswerList = $correctAnswerList;
@ -473,9 +473,9 @@ function showQuestion(
// replace / with \/ to allow the preg_replace bellow and all the regexp char // replace / with \/ to allow the preg_replace bellow and all the regexp char
$correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp); $correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp);
if (isset($studentAnswerList[$i])) { if (isset($studentAnswerList[$i])) {
// student already start this test and this question // If student already started this test and answered this question,
// fill the blank with his previous answers // fill the blank with his previous answers
// may be "" if student did the question, but not fill the blanks // may be "" if student viewed the question, but did not fill the blanks
$correctItem = $studentAnswerList[$i]; $correctItem = $studentAnswerList[$i];
} }
$attributes["style"] = "width:".$listAnswerInformations["tabinputsize"][$i]."px"; $attributes["style"] = "width:".$listAnswerInformations["tabinputsize"][$i]."px";

@ -284,7 +284,7 @@ class FillBlanks extends Question
* abstract function which creates the form to create / edit the answers of the question * abstract function which creates the form to create / edit the answers of the question
* @param FormValidator $form * @param FormValidator $form
*/ */
function processAnswersCreation($form) public function processAnswersCreation($form)
{ {
global $charset; global $charset;
@ -294,7 +294,7 @@ class FillBlanks extends Question
$answer = api_html_entity_decode($answer, ENT_QUOTES, $charset); $answer = api_html_entity_decode($answer, ENT_QUOTES, $charset);
// remove the :: eventually written by the user // remove the :: eventually written by the user
$answer = str_replace('::','',$answer); $answer = str_replace('::', '', $answer);
// remove starting and ending space and   // remove starting and ending space and  
$answer = api_preg_replace("/\xc2\xa0/", " ", $answer); $answer = api_preg_replace("/\xc2\xa0/", " ", $answer);
@ -307,7 +307,8 @@ class FillBlanks extends Question
$blankEndSeparatorRegexp = self::escapeForRegexp($blankEndSeparator); $blankEndSeparatorRegexp = self::escapeForRegexp($blankEndSeparator);
// remove spaces at the beginning and the end of text in square brackets // remove spaces at the beginning and the end of text in square brackets
$answer = preg_replace_callback("/".$blankStartSeparatorRegexp."[^]]+".$blankEndSeparatorRegexp."/", $answer = preg_replace_callback(
"/".$blankStartSeparatorRegexp."[^]]+".$blankEndSeparatorRegexp."/",
function ($matches) use ($blankStartSeparator, $blankEndSeparator) { function ($matches) use ($blankStartSeparator, $blankEndSeparator) {
$matchingResult = $matches[0]; $matchingResult = $matches[0];
$matchingResult = trim($matchingResult, $blankStartSeparator); $matchingResult = trim($matchingResult, $blankStartSeparator);
@ -318,12 +319,12 @@ class FillBlanks extends Question
$matchingResult = str_replace('/"/', "", $matchingResult); $matchingResult = str_replace('/"/', "", $matchingResult);
return $blankStartSeparator.$matchingResult.$blankEndSeparator; return $blankStartSeparator.$matchingResult.$blankEndSeparator;
}, },
$answer); $answer
);
// get the blanks weightings // get the blanks weightings
$nb = preg_match_all('/'.$blankStartSeparatorRegexp.'[^'.$blankStartSeparatorRegexp.']*'.$blankEndSeparatorRegexp.'/', $answer, $blanks); $nb = preg_match_all('/'.$blankStartSeparatorRegexp.'[^'.$blankStartSeparatorRegexp.']*'.$blankEndSeparatorRegexp.'/', $answer, $blanks);
if(isset($_GET['editQuestion'])) if (isset($_GET['editQuestion'])) {
{
$this -> weighting = 0; $this -> weighting = 0;
} }
@ -344,10 +345,10 @@ class FillBlanks extends Question
D : input width for the word [pen] D : input width for the word [pen]
E : equal @1 if "Allow answers order switches" has been checked, @ otherwise E : equal @1 if "Allow answers order switches" has been checked, @ otherwise
*/ */
if($nb > 0) { if ($nb > 0) {
$answer .= '::'; $answer .= '::';
// weighting // weighting
for($i=0 ; $i < $nb ; ++$i) { for ($i=0; $i < $nb; ++$i) {
// enter the weighting of word $i // enter the weighting of word $i
$answer .= $form->getSubmitValue('weighting['.$i.']'); $answer .= $form->getSubmitValue('weighting['.$i.']');
// not the last word, add "," // not the last word, add ","
@ -360,7 +361,7 @@ class FillBlanks extends Question
// input width // input width
$answer .= ":"; $answer .= ":";
for ($i=0 ; $i < $nb ; ++$i) { for ($i=0; $i < $nb; ++$i) {
// enter the width of input for word $i // enter the width of input for word $i
$answer .= $form->getSubmitValue('sizeofinput['.$i.']'); $answer .= $form->getSubmitValue('sizeofinput['.$i.']');
// not the last word, add "," // not the last word, add ","
@ -399,7 +400,7 @@ class FillBlanks extends Question
* @param null $score * @param null $score
* @return null|string * @return null|string
*/ */
function return_header($feedback_type = null, $counter = null, $score = null) public function return_header($feedback_type = null, $counter = null, $score = null)
{ {
$header = parent::return_header($feedback_type, $counter, $score); $header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class .'"> $header .= '<table class="'.$this->question_table_class .'">
@ -409,7 +410,7 @@ class FillBlanks extends Question
return $header; return $header;
} }
/** /**
* @param $separatorStartRegexp * @param $separatorStartRegexp
* @param $separatorEndRegexp * @param $separatorEndRegexp
* @param $correctItemRegexp * @param $correctItemRegexp
@ -429,33 +430,34 @@ class FillBlanks extends Question
switch (self::getFillTheBlankAnswerType($inTeacherSolution)) { switch (self::getFillTheBlankAnswerType($inTeacherSolution)) {
case self::FILL_THE_BLANK_MENU: case self::FILL_THE_BLANK_MENU:
$selected = ""; $selected = "";
// the blank menu // the blank menu
$optionMenu = ""; $optionMenu = "";
// display a menu from answer separated with | // display a menu from answer separated with |
// if display for student, shuffle the correct answer menu // if display for student, shuffle the correct answer menu
$listMenu = self::getFillTheBlankMenuAnswers($inTeacherSolution, $displayForStudent); $listMenu = self::getFillTheBlankMenuAnswers($inTeacherSolution, $displayForStudent);
$result .= '<select name="choice['.$questionId.'][]">'; $result .= '<select name="choice['.$questionId.'][]">';
for ($k=0; $k < count($listMenu); $k++) { for ($k=0; $k < count($listMenu); $k++) {
$selected = ""; $selected = "";
if ($correctItem == $listMenu[$k]) { if ($correctItem == $listMenu[$k]) {
$selected = " selected=selected "; $selected = " selected=selected ";
}
// if in teacher view, display the first item by default, which is the right answer
if ($k==0 && !$displayForStudent) {
$selected = " selected=selected ";
}
$optionMenu .= '<option '.$selected.' value="'.$listMenu[$k].'">'.$listMenu[$k].'</option>';
} }
if ($selected == "") { // if in teacher view, display the first item by default, which is the right answer
// no good answer have been found... if ($k==0 && !$displayForStudent) {
$selected = " selected=selected "; $selected = " selected=selected ";
} }
$result .= "<option $selected value=''>--</option>"; $optionMenu .= '<option '.$selected.' value="'.$listMenu[$k].'">'.$listMenu[$k].'</option>';
$result .= $optionMenu; }
$result .= '</select>'; if ($selected == "") {
// no good answer have been found...
$selected = " selected=selected ";
}
$result .= "<option $selected value=''>--</option>";
$result .= $optionMenu;
$result .= '</select>';
break; break;
case self::FILL_THE_BLANK_SEVERAL_ANSWER: case self::FILL_THE_BLANK_SEVERAL_ANSWER:
case self::FILL_THE_BLANK_STANDARD: //no break
case self::FILL_THE_BLANK_STANDARD:
default: default:
$result = Display::input('text', "choice[$questionId][]", $correctItem, $attributes); $result = Display::input('text', "choice[$questionId][]", $correctItem, $attributes);
break; break;
@ -465,7 +467,7 @@ class FillBlanks extends Question
/** /**
* Return an array with the differents choice avaliable when the bracket is a menu * Return an array with the different choices available when the answers between bracket show as a menu
* @param $correctAnswer * @param $correctAnswer
* @param $displayForStudent true if we want to shuffle the choices of the menu for students * @param $displayForStudent true if we want to shuffle the choices of the menu for students
* @return array * @return array
@ -482,7 +484,7 @@ class FillBlanks extends Question
/** /**
* Return the array indice of the student answer * Return the array index of the student answer
* @param $correctAnswer the menu Choice1|Choice2|Choice3 * @param $correctAnswer the menu Choice1|Choice2|Choice3
* @param $studentAnswer the student answer must be Choice1 or Choice2 or Choice3 * @param $studentAnswer the student answer must be Choice1 or Choice2 or Choice3
* @return int in the exemple 0 1 or 2 depending of the choice of the student * @return int in the exemple 0 1 or 2 depending of the choice of the student
@ -500,7 +502,7 @@ class FillBlanks extends Question
/** /**
* return the possible answer if bracket is a multiple choice menu * Return the possible answer if the answer between brackets is a multiple choice menu
* @param $correctAnswer * @param $correctAnswer
* @return array * @return array
*/ */
@ -513,8 +515,8 @@ class FillBlanks extends Question
/** /**
* Return true if student answer is right according to the correctAnswer * Return true if student answer is right according to the correctAnswer
* it is not so simple as equality, because of the type of Fill The Blank question * it is not as simple as equality, because of the type of Fill The Blank question
* eg : studentNaswer = 'Un' and correctAnswer = 'Un||1||un' * eg : studentAnswer = 'Un' and correctAnswer = 'Un||1||un'
* @param $studentAnswer the [studentanswer] of the info array of the answer field * @param $studentAnswer the [studentanswer] of the info array of the answer field
* @param $correctAnswer the [tabwords] of the info array of the answer field * @param $correctAnswer the [tabwords] of the info array of the answer field
* @return bool * @return bool
@ -555,7 +557,7 @@ class FillBlanks extends Question
* @param bool $inIsStudentAnswer : true if it is a student answer and not the empty question model * @param bool $inIsStudentAnswer : true if it is a student answer and not the empty question model
* @return array of information about the answer * @return array of information about the answer
*/ */
public static function getAnswerInfo($userAnswer = "", $isStudentAnswer = false) public static function getAnswerInfo($userAnswer = "", $isStudentAnswer = false)
{ {
$listAnswerResults = array(); $listAnswerResults = array();
$listAnswerResults['text'] = ""; $listAnswerResults['text'] = "";
@ -622,8 +624,9 @@ class FillBlanks extends Question
if ($listAnswerResults['wordsCount'] > 0) { if ($listAnswerResults['wordsCount'] > 0) {
$listAnswerResults['tabwordsbracket'] = $listWords[0]; $listAnswerResults['tabwordsbracket'] = $listWords[0];
// remove [ and ] in string // remove [ and ] in string
array_walk($listWords[0],function (&$value, $key, $tabBlankChar) array_walk(
{ $listWords[0],
function (&$value, $key, $tabBlankChar) {
$trimChars = ""; $trimChars = "";
for ($i=0; $i < count($tabBlankChar); $i++) { for ($i=0; $i < count($tabBlankChar); $i++) {
$trimChars .= $tabBlankChar[$i]; $trimChars .= $tabBlankChar[$i];

Loading…
Cancel
Save