|
@@ -2599,85 +2599,253 @@ class Exercise
|
|
|
}
|
|
|
break;
|
|
|
case FILL_IN_BLANKS:
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $listCorrectAnswers = FillBlanks::getAnswerInfo($answer);
|
|
|
- $switchableAnswerSet = $listCorrectAnswers["switchable"];
|
|
|
- $answerWeighting = $listCorrectAnswers["tabweighting"];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ $str = '';
|
|
|
if ($from_database) {
|
|
|
$sql = "SELECT answer
|
|
|
- FROM $TBL_TRACK_ATTEMPT
|
|
|
- WHERE
|
|
|
- exe_id = $exeId AND
|
|
|
- question_id= ".intval($questionId);
|
|
|
+ FROM $TBL_TRACK_ATTEMPT
|
|
|
+ WHERE
|
|
|
+ exe_id = $exeId AND
|
|
|
+ question_id= ".intval($questionId);
|
|
|
$result = Database::query($sql);
|
|
|
$str = Database::result($result, 0, 'answer');
|
|
|
-
|
|
|
- $listStudentResults = FillBlanks::getAnswerInfo($str, true);
|
|
|
- $choice = $listStudentResults['studentanswer'];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (!$switchableAnswerSet) {
|
|
|
-
|
|
|
- for ($i=0; $i < count($listCorrectAnswers['tabwords']); $i++) {
|
|
|
- $studentAnswer = isset($choice[$i]) ? trim($choice[$i]) : '';
|
|
|
+ if ($saved_results == false && strpos($str, 'font color') !== false) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $pre_array = explode('::', $answer);
|
|
|
+
|
|
|
+
|
|
|
+ $last = count($pre_array) - 1;
|
|
|
+ $is_set_switchable = explode('@', $pre_array[$last]);
|
|
|
+ $switchable_answer_set = false;
|
|
|
+ if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) {
|
|
|
+ $switchable_answer_set = true;
|
|
|
+ }
|
|
|
+ $answer = '';
|
|
|
+ for ($k = 0; $k < $last; $k++) {
|
|
|
+ $answer .= $pre_array[$k];
|
|
|
+ }
|
|
|
+
|
|
|
+ $answerWeighting = explode(',', $is_set_switchable[0]);
|
|
|
+
|
|
|
+ $temp = $answer;
|
|
|
+ $answer = '';
|
|
|
+ $j = 0;
|
|
|
+
|
|
|
+ $user_tags = $correct_tags = $real_text = array();
|
|
|
+
|
|
|
+ while (1) {
|
|
|
+
|
|
|
+ if (($pos = api_strpos($temp, '[')) === false) {
|
|
|
+
|
|
|
+ $answer = $temp;
|
|
|
+ $real_text[] = $answer;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $real_text[] = api_substr($temp, 0, $pos +1);
|
|
|
+ $answer .= api_substr($temp, 0, $pos +1);
|
|
|
+
|
|
|
+ $temp = api_substr($temp, $pos +1);
|
|
|
+
|
|
|
+ if (($pos = api_strpos($temp, ']')) === false) {
|
|
|
+
|
|
|
+ $answer .= $temp;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if ($from_database) {
|
|
|
+ $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
|
|
|
+ WHERE
|
|
|
+ exe_id = '".$exeId."' AND
|
|
|
+ question_id= ".intval($questionId)."";
|
|
|
+ $resfill = Database::query($queryfill);
|
|
|
+ $str = Database::result($resfill, 0, 'answer');
|
|
|
+ api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
|
|
|
+ $str = str_replace('\r\n', '', $str);
|
|
|
+
|
|
|
+ $choice = $arr[1];
|
|
|
+ if (isset($choice[$j])) {
|
|
|
+ $tmp = api_strrpos($choice[$j], ' / ');
|
|
|
+ $choice[$j] = api_substr($choice[$j], 0, $tmp);
|
|
|
+ $choice[$j] = trim($choice[$j]);
|
|
|
+
|
|
|
+ $choice[$j] = stripslashes($choice[$j]);
|
|
|
+ } else {
|
|
|
+ $choice[$j] = null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $choice[$j] = api_htmlentities(trim($choice[$j]));
|
|
|
+ }
|
|
|
+
|
|
|
+ $user_tags[] = $choice[$j];
|
|
|
+
|
|
|
+ $correct_tags[] = api_substr($temp, 0, $pos);
|
|
|
+ $j++;
|
|
|
+ $temp = api_substr($temp, $pos +1);
|
|
|
+ }
|
|
|
+ $answer = '';
|
|
|
+ $real_correct_tags = $correct_tags;
|
|
|
+ $chosen_list = array();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- if (!$from_database) {
|
|
|
- $studentAnswer = htmlentities(
|
|
|
- api_utf8_encode($studentAnswer)
|
|
|
- );
|
|
|
+ for ($i = 0; $i < count($real_correct_tags); $i++) {
|
|
|
+ if ($i == 0) {
|
|
|
+ $answer .= $real_text[0];
|
|
|
+ }
|
|
|
+ if (!$switchable_answer_set) {
|
|
|
+
|
|
|
+ $user_tags[$i] = stripslashes($user_tags[$i]);
|
|
|
+ if ($correct_tags[$i] == $user_tags[$i]) {
|
|
|
+
|
|
|
+ $questionScore += $answerWeighting[$i];
|
|
|
+
|
|
|
+ $totalScore += $answerWeighting[$i];
|
|
|
+
|
|
|
+ $answer .= $correct_tags[$i];
|
|
|
+ } elseif (!empty($user_tags[$i])) {
|
|
|
+
|
|
|
+
|
|
|
+ $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $answer .= '';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (in_array($user_tags[$i], $correct_tags)) {
|
|
|
+ $chosen_list[] = $user_tags[$i];
|
|
|
+ $correct_tags = array_diff($correct_tags, $chosen_list);
|
|
|
+
|
|
|
+ $questionScore += $answerWeighting[$i];
|
|
|
+
|
|
|
+ $totalScore += $answerWeighting[$i];
|
|
|
+
|
|
|
+ $answer .= $user_tags[$i];
|
|
|
+ } elseif (!empty ($user_tags[$i])) {
|
|
|
+
|
|
|
+
|
|
|
+ $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $answer .= '';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- $correctAnswer = $listCorrectAnswers['tabwords'][$i];
|
|
|
- $isAnswerCorrect = 0;
|
|
|
- if (FillBlanks::isGoodStudentAnswer($studentAnswer, $correctAnswer)) {
|
|
|
-
|
|
|
- $questionScore += $answerWeighting[$i];
|
|
|
-
|
|
|
- $totalScore += $answerWeighting[$i];
|
|
|
- $isAnswerCorrect = 1;
|
|
|
+
|
|
|
+ $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]';
|
|
|
+ if (isset($real_text[$i +1])) {
|
|
|
+ $answer .= $real_text[$i +1];
|
|
|
}
|
|
|
- $listCorrectAnswers['studentanswer'][$i] = $studentAnswer;
|
|
|
- $listCorrectAnswers['studentscore'][$i] = $isAnswerCorrect;
|
|
|
}
|
|
|
} else {
|
|
|
-
|
|
|
- $listStudentAnswerTemp = $choice;
|
|
|
- $listTeacherAnswerTemp = $listCorrectAnswers['tabwords'];
|
|
|
-
|
|
|
- for ($i=0; $i < count($listStudentAnswerTemp); $i++) {
|
|
|
- $studentAnswer = trim($listStudentAnswerTemp[$i]);
|
|
|
- $found = false;
|
|
|
- for ($j=0; $j < count($listTeacherAnswerTemp); $j++) {
|
|
|
- $correctAnswer = $listTeacherAnswerTemp[$j];
|
|
|
- if (!$found) {
|
|
|
- if (FillBlanks::isGoodStudentAnswer($studentAnswer, $correctAnswer)) {
|
|
|
- $questionScore += $answerWeighting[$i];
|
|
|
- $totalScore += $answerWeighting[$i];
|
|
|
- $listTeacherAnswerTemp[$j] = "";
|
|
|
- $found = true;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $listCorrectAnswers = FillBlanks::getAnswerInfo(
|
|
|
+ $answer
|
|
|
+ );
|
|
|
+ $switchableAnswerSet = $listCorrectAnswers["switchable"];
|
|
|
+ $answerWeighting = $listCorrectAnswers["tabweighting"];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if ($from_database) {
|
|
|
+ $sql = "SELECT answer
|
|
|
+ FROM $TBL_TRACK_ATTEMPT
|
|
|
+ WHERE
|
|
|
+ exe_id = $exeId AND
|
|
|
+ question_id= ".intval($questionId);
|
|
|
+ $result = Database::query($sql);
|
|
|
+ $str = Database::result($result, 0, 'answer');
|
|
|
+ $listStudentResults = FillBlanks::getAnswerInfo(
|
|
|
+ $str,
|
|
|
+ true
|
|
|
+ );
|
|
|
+ $choice = $listStudentResults['studentanswer'];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!$switchableAnswerSet) {
|
|
|
+
|
|
|
+ for ($i = 0; $i < count(
|
|
|
+ $listCorrectAnswers['tabwords']
|
|
|
+ ); $i++) {
|
|
|
+ $studentAnswer = isset($choice[$i]) ? trim(
|
|
|
+ $choice[$i]
|
|
|
+ ) : '';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!$from_database) {
|
|
|
+ $studentAnswer = htmlentities(
|
|
|
+ api_utf8_encode($studentAnswer)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $correctAnswer = $listCorrectAnswers['tabwords'][$i];
|
|
|
+ $isAnswerCorrect = 0;
|
|
|
+ if (FillBlanks::isGoodStudentAnswer(
|
|
|
+ $studentAnswer,
|
|
|
+ $correctAnswer
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+
|
|
|
+ $questionScore += $answerWeighting[$i];
|
|
|
+
|
|
|
+ $totalScore += $answerWeighting[$i];
|
|
|
+ $isAnswerCorrect = 1;
|
|
|
}
|
|
|
+ $listCorrectAnswers['studentanswer'][$i] = $studentAnswer;
|
|
|
+ $listCorrectAnswers['studentscore'][$i] = $isAnswerCorrect;
|
|
|
}
|
|
|
- $listCorrectAnswers['studentanswer'][$i] = $studentAnswer;
|
|
|
- if (!$found) {
|
|
|
- $listCorrectAnswers['studentscore'][$i] = 0;
|
|
|
- } else {
|
|
|
- $listCorrectAnswers['studentscore'][$i] = 1;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $listStudentAnswerTemp = $choice;
|
|
|
+ $listTeacherAnswerTemp = $listCorrectAnswers['tabwords'];
|
|
|
+
|
|
|
+ for ($i = 0; $i < count(
|
|
|
+ $listStudentAnswerTemp
|
|
|
+ ); $i++) {
|
|
|
+ $studentAnswer = trim(
|
|
|
+ $listStudentAnswerTemp[$i]
|
|
|
+ );
|
|
|
+ $found = false;
|
|
|
+ for ($j = 0; $j < count(
|
|
|
+ $listTeacherAnswerTemp
|
|
|
+ ); $j++) {
|
|
|
+ $correctAnswer = $listTeacherAnswerTemp[$j];
|
|
|
+ if (!$found) {
|
|
|
+ if (FillBlanks::isGoodStudentAnswer(
|
|
|
+ $studentAnswer,
|
|
|
+ $correctAnswer
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ $questionScore += $answerWeighting[$i];
|
|
|
+ $totalScore += $answerWeighting[$i];
|
|
|
+ $listTeacherAnswerTemp[$j] = "";
|
|
|
+ $found = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $listCorrectAnswers['studentanswer'][$i] = $studentAnswer;
|
|
|
+ if (!$found) {
|
|
|
+ $listCorrectAnswers['studentscore'][$i] = 0;
|
|
|
+ } else {
|
|
|
+ $listCorrectAnswers['studentscore'][$i] = 1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ $answer = FillBlanks::getAnswerInStudentAttempt(
|
|
|
+ $listCorrectAnswers
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
- $answer = FillBlanks::getAnswerInStudentAttempt($listCorrectAnswers);
|
|
|
break;
|
|
|
|
|
|
case CALCULATED_ANSWER:
|
|
@@ -3426,7 +3594,8 @@ class Exercise
|
|
|
$answer,
|
|
|
$exeId,
|
|
|
$questionId,
|
|
|
- $results_disabled
|
|
|
+ $results_disabled,
|
|
|
+ $str
|
|
|
);
|
|
|
break;
|
|
|
case CALCULATED_ANSWER:
|