Format code, rename wrong variables, remove unused parameters

pull/2487/head
jmontoyaa 8 years ago
parent 4b9573e4d9
commit ee8a6b7582
  1. 50
      main/exercise/fill_blanks.class.php
  2. 49
      main/inc/lib/exercise.lib.php

@ -481,22 +481,16 @@ class FillBlanks extends Question
}
/**
* @param string $separatorStartRegexp
* @param string $separatorEndRegexp
* @param string $correctItemRegexp
* @param integer $questionId
* @param $correctItem
* @param $attributes
* @param int $questionId
* @param string $correctItem
* @param array $attributes
* @param string $answer
* @param $listAnswersInfo
* @param array $listAnswersInfo
* @param boolean $displayForStudent
* @param integer $inBlankNumber
* @param int $inBlankNumber
* @return string
*/
public static function getFillTheBlankHtml(
$separatorStartRegexp,
$separatorEndRegexp,
$correctItemRegexp,
$questionId,
$correctItem,
$attributes,
@ -518,7 +512,7 @@ class FillBlanks extends Question
$listMenu = self::getFillTheBlankMenuAnswers($inTeacherSolution, $displayForStudent);
$result .= '<select name="choice['.$questionId.'][]">';
for ($k=0; $k < count($listMenu); $k++) {
$selected = "";
$selected = '';
if ($correctItem == $listMenu[$k]) {
$selected = " selected=selected ";
}
@ -528,7 +522,7 @@ class FillBlanks extends Question
}
$optionMenu .= '<option '.$selected.' value="'.$listMenu[$k].'">'.$listMenu[$k].'</option>';
}
if ($selected == "") {
if ($selected == '') {
// no good answer have been found...
$selected = " selected=selected ";
}
@ -540,7 +534,12 @@ class FillBlanks extends Question
//no break
case self::FILL_THE_BLANK_STANDARD:
default:
$result = Display::input('text', "choice[$questionId][]", $correctItem, $attributes);
$result = Display::input(
'text',
"choice[$questionId][]",
$correctItem,
$attributes
);
break;
}
@ -557,19 +556,12 @@ class FillBlanks extends Question
*/
public static function getFillTheBlankMenuAnswers($correctAnswer, $displayForStudent)
{
// if $inDisplayForStudent, then shuffle the result array
/*$items = explode('|', $correctAnswer);
if ($displayForStudent) {
shuffle($items);
}
return $items;*/
$listChoises = api_preg_split("/\|/", $correctAnswer);
$list = api_preg_split("/\|/", $correctAnswer);
if ($displayForStudent) {
shuffle($listChoises);
shuffle($list);
}
return $listChoises;
return $list;
}
/**
@ -800,7 +792,7 @@ class FillBlanks extends Question
* @param $studentsIdList
* @param string $startDate
* @param string $endDate
* @param bool $useLastAnswerredAttempt
* @param bool $useLastAnsweredAttempt
* @return array
* (
* [student_id] => Array
@ -817,7 +809,7 @@ class FillBlanks extends Question
$studentsIdList,
$startDate,
$endDate,
$useLastAnswerredAttempt = true
$useLastAnsweredAttempt = true
) {
$tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
@ -878,7 +870,7 @@ class FillBlanks extends Question
}
} else {
// student didn't answer this bracket
if ($useLastAnswerredAttempt) {
if ($useLastAnsweredAttempt) {
// if we take into account the last answered attempt
if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
$tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered
@ -928,7 +920,7 @@ class FillBlanks extends Question
$separatorStart = $listWithStudentAnswer['blankseparatorstart'];
$separatorEnd = $listWithStudentAnswer['blankseparatorend'];
// lets rebuild the sentence with [correct answer][student answer][answer is correct]
$result = "";
$result = '';
for ($i=0; $i < count($listWithStudentAnswer['commonwords']) - 1; $i++) {
$result .= $listWithStudentAnswer['commonwords'][$i];
$result .= $listWithStudentAnswer['tabwordsbracket'][$i];
@ -1247,12 +1239,10 @@ class FillBlanks extends Question
$answerInfo = FillBlanks::getAnswerInfo($answerText, true);
$correctAnswerList = $answerInfo['tabwords'];
$studentAnswer = $answerInfo['studentanswer'];
$isCorrect = true;
foreach ($correctAnswerList as $i => $correctAnswer) {
$isGoodStudentAnswer = FillBlanks::isGoodStudentAnswer($studentAnswer[$i], $correctAnswer);
$isCorrect = $isCorrect && $isGoodStudentAnswer;
}

@ -560,13 +560,11 @@ class ExerciseLib
// display the question, with field empty, for student to fill it,
// or filled to display the answer in the Question preview of the exercise/admin.php page
$displayForStudent = true;
$listAnswerInformations = FillBlanks::getAnswerInfo($answer);
$separatorStartRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorstart']);
$separatorEndRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorend']);
$listAnswerInfo = FillBlanks::getAnswerInfo($answer);
list($answer) = explode('::', $answer);
// Correct answers
$correctAnswerList = $listAnswerInformations['tabwords'];
$correctAnswerList = $listAnswerInfo['tabwords'];
// Student's answer
$studentAnswerList = array();
@ -583,70 +581,51 @@ class ExerciseLib
}
if (!empty($correctAnswerList) && !empty($studentAnswerList)) {
$answer = "";
for ($i = 0; $i < count($listAnswerInformations["commonwords"]) - 1; $i++) {
$answer = '';
for ($i = 0; $i < count($listAnswerInfo['commonwords']) - 1; $i++) {
// display the common word
$answer .= $listAnswerInformations["commonwords"][$i];
$answer .= $listAnswerInfo['commonwords'][$i];
// display the blank word
$correctItem = $listAnswerInformations["tabwords"][$i];
$correctItemRegexp = $correctItem;
// replace / with \/ to allow the preg_replace bellow and all the regexp char
$correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp);
$correctItem = $listAnswerInfo['tabwords'][$i];
if (isset($studentAnswerList[$i])) {
// If student already started this test and answered this question,
// fill the blank with his previous answers
// may be "" if student viewed the question, but did not fill the blanks
$correctItem = $studentAnswerList[$i];
}
$attributes["style"] = "width:" . $listAnswerInformations["tabinputsize"][$i] . "px";
$attributes['style'] = "width:" . $listAnswerInfo['tabinputsize'][$i] . "px";
$answer .= FillBlanks::getFillTheBlankHtml(
$separatorStartRegexp,
$separatorEndRegexp,
$correctItemRegexp,
$questionId,
$correctItem,
$attributes,
$answer,
$listAnswerInformations,
$listAnswerInfo,
$displayForStudent,
$i
);
}
// display the last common word
$answer .= $listAnswerInformations["commonwords"][$i];
$answer .= $listAnswerInfo['commonwords'][$i];
} else {
// display empty [input] with the right width for student to fill it
$separatorStartRegexp = FillBlanks::escapeForRegexp(
$listAnswerInformations['blankseparatorstart']
);
$separatorEndRegexp = FillBlanks::escapeForRegexp(
$listAnswerInformations['blankseparatorend']
);
$answer = '';
for ($i = 0; $i < count($listAnswerInformations["commonwords"]) - 1; $i++) {
for ($i = 0; $i < count($listAnswerInfo['commonwords']) - 1; $i++) {
// display the common words
$answer .= $listAnswerInformations["commonwords"][$i];
$answer .= $listAnswerInfo['commonwords'][$i];
// display the blank word
$attributes["style"] = "width:" . $listAnswerInformations["tabinputsize"][$i] . "px";
$correctItem = $listAnswerInformations["tabwords"][$i];
$correctItemRegexp = $correctItem;
// replace / with \/ to allow the preg_replace bellow and all the regexp char
$correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp);
$attributes["style"] = "width:" . $listAnswerInfo['tabinputsize'][$i] . "px";
$answer .= FillBlanks::getFillTheBlankHtml(
$separatorStartRegexp,
$separatorEndRegexp,
$correctItemRegexp,
$questionId,
'',
$attributes,
$answer,
$listAnswerInformations,
$listAnswerInfo,
$displayForStudent,
$i
);
}
// display the last common word
$answer .= $listAnswerInformations["commonwords"][$i];
$answer .= $listAnswerInfo['commonwords'][$i];
}
$s .= $answer;
break;

Loading…
Cancel
Save