|
|
|
|
@ -2283,9 +2283,9 @@ class Exercise |
|
|
|
|
$user_answer = ''; |
|
|
|
|
|
|
|
|
|
// Get answer list for matching |
|
|
|
|
$sql_answer = 'SELECT id_auto, id, answer FROM '.$table_ans.' |
|
|
|
|
WHERE c_id = '.$course_id.' AND question_id = "'.$questionId.'"'; |
|
|
|
|
$res_answer = Database::query($sql_answer); |
|
|
|
|
$sql = "SELECT id_auto, id, answer FROM $table_ans |
|
|
|
|
WHERE c_id = $course_id AND question_id = $questionId"; |
|
|
|
|
$res_answer = Database::query($sql); |
|
|
|
|
|
|
|
|
|
$answerMatching = array(); |
|
|
|
|
while ($real_answer = Database::fetch_array($res_answer)) { |
|
|
|
|
@ -2440,15 +2440,17 @@ class Exercise |
|
|
|
|
break; |
|
|
|
|
case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
|
|
|
|
if ($from_database) { |
|
|
|
|
$queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
|
|
|
|
WHERE exe_id = ".$exeId." AND question_id= ".$questionId; |
|
|
|
|
$resultans = Database::query($queryans); |
|
|
|
|
$sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
|
|
|
|
WHERE exe_id = $exeId AND question_id= ".$questionId; |
|
|
|
|
$resultans = Database::query($sql); |
|
|
|
|
while ($row = Database::fetch_array($resultans)) { |
|
|
|
|
$ind = $row['answer']; |
|
|
|
|
$result = explode(':',$ind); |
|
|
|
|
$my_answer_id = $result[0]; |
|
|
|
|
$option = $result[1]; |
|
|
|
|
$choice[$my_answer_id] = $option; |
|
|
|
|
if (isset($result[0])) { |
|
|
|
|
$my_answer_id = $result[0]; |
|
|
|
|
$option = $result[1]; |
|
|
|
|
$choice[$my_answer_id] = $option; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$studentChoice = $choice[$answerAutoId]; |
|
|
|
|
|
|
|
|
|
@ -2472,16 +2474,17 @@ class Exercise |
|
|
|
|
break; |
|
|
|
|
case MULTIPLE_ANSWER_COMBINATION: |
|
|
|
|
if ($from_database) { |
|
|
|
|
$queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
|
|
|
|
WHERE exe_id = '".$exeId."' and question_id= '".$questionId."'"; |
|
|
|
|
$resultans = Database::query($queryans); |
|
|
|
|
$sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
|
|
|
|
WHERE exe_id = $exeId AND question_id= $questionId"; |
|
|
|
|
$resultans = Database::query($sql); |
|
|
|
|
while ($row = Database::fetch_array($resultans)) { |
|
|
|
|
$ind = $row['answer']; |
|
|
|
|
$choice[$ind] = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
|
|
|
|
|
|
|
|
|
if ($answerCorrect == 1) { |
|
|
|
|
if ($answerCorrect == $answerAutoId) { |
|
|
|
|
if ($studentChoice) { |
|
|
|
|
$real_answers[$answerId] = true; |
|
|
|
|
} else { |
|
|
|
|
@ -2591,155 +2594,6 @@ class Exercise |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$answer = FillBlanks::getAnswerInStudentAttempt($listCorrectAnswers); |
|
|
|
|
|
|
|
|
|
// the question is encoded like this |
|
|
|
|
// [A] B [C] D [E] F::10,10,10@1 |
|
|
|
|
// number 1 before the "@" means that is a switchable fill in blank question |
|
|
|
|
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 |
|
|
|
|
// means that is a normal fill blank question |
|
|
|
|
// first we explode the "::" |
|
|
|
|
/* |
|
|
|
|
$pre_array = explode('::', $answer); |
|
|
|
|
// is switchable fill blank or not |
|
|
|
|
$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]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// splits weightings that are joined with a comma |
|
|
|
|
$answerWeighting = explode(',', $is_set_switchable[0]); |
|
|
|
|
|
|
|
|
|
// we save the answer because it will be modified |
|
|
|
|
$temp = $answer; |
|
|
|
|
|
|
|
|
|
$answer = ''; |
|
|
|
|
$j = 0; |
|
|
|
|
//initialise answer tags |
|
|
|
|
$user_tags = $correct_tags = $real_text = array(); |
|
|
|
|
|
|
|
|
|
// the loop will stop at the end of the text |
|
|
|
|
while (1) { |
|
|
|
|
// quits the loop if there are no more blanks (detect '[') |
|
|
|
|
if (($pos = api_strpos($temp, '[')) === false) { |
|
|
|
|
// adds the end of the text |
|
|
|
|
$answer = $temp; |
|
|
|
|
$real_text[] = $answer; |
|
|
|
|
break; //no more "blanks", quit the loop |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// adds the piece of text that is before the blank |
|
|
|
|
// and ends with '[' into a general storage array |
|
|
|
|
$real_text[] = api_substr($temp, 0, $pos +1); |
|
|
|
|
$answer .= api_substr($temp, 0, $pos +1); |
|
|
|
|
|
|
|
|
|
//take the string remaining (after the last "[" we found) |
|
|
|
|
$temp = api_substr($temp, $pos +1); |
|
|
|
|
|
|
|
|
|
// quit the loop if there are no more blanks, and update $pos to the position of next ']' |
|
|
|
|
if (($pos = api_strpos($temp, ']')) === false) { |
|
|
|
|
// adds the end of the text |
|
|
|
|
$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]); |
|
|
|
|
|
|
|
|
|
// Needed to let characters ' and " to work as part of an answer |
|
|
|
|
$choice[$j] = stripslashes($choice[$j]); |
|
|
|
|
} else { |
|
|
|
|
$choice[$j] = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// This value is the user input, not escaped while correct answer is escaped by fckeditor |
|
|
|
|
// Works with cyrillic alphabet and when using ">" chars |
|
|
|
|
$choice[$j] = htmlentities(api_utf8_encode(trim($choice[$j]))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$user_tags[] = $choice[$j]; |
|
|
|
|
|
|
|
|
|
//put the contents of the [] answer tag into correct_tags[] |
|
|
|
|
$correct_tags[] = api_substr($temp, 0, $pos); |
|
|
|
|
$j++; |
|
|
|
|
$temp = api_substr($temp, $pos +1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$answer = ''; |
|
|
|
|
$real_correct_tags = $correct_tags; |
|
|
|
|
$chosen_list = array(); |
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($real_correct_tags); $i++) { |
|
|
|
|
if ($i == 0) { |
|
|
|
|
$answer .= $real_text[0]; |
|
|
|
|
} |
|
|
|
|
if (!$switchable_answer_set) { |
|
|
|
|
// Needed to parse ' and " characters |
|
|
|
|
$user_tags[$i] = stripslashes($user_tags[$i]); |
|
|
|
|
if ($correct_tags[$i] == $user_tags[$i]) { |
|
|
|
|
// gives the related weighting to the student |
|
|
|
|
$questionScore += $answerWeighting[$i]; |
|
|
|
|
// increments total score |
|
|
|
|
$totalScore += $answerWeighting[$i]; |
|
|
|
|
// adds the word in green at the end of the string |
|
|
|
|
$answer .= $correct_tags[$i]; |
|
|
|
|
} elseif (!empty($user_tags[$i])) { |
|
|
|
|
// else if the word entered by the student IS NOT the same as the one defined by the professor |
|
|
|
|
// adds the word in red at the end of the string, and strikes it |
|
|
|
|
$answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>'; |
|
|
|
|
} else { |
|
|
|
|
// adds a tabulation if no word has been typed by the student |
|
|
|
|
$answer .= ''; // remove that causes issue |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// switchable fill in the blanks |
|
|
|
|
if (in_array($user_tags[$i], $correct_tags)) { |
|
|
|
|
$chosen_list[] = $user_tags[$i]; |
|
|
|
|
$correct_tags = array_diff($correct_tags, $chosen_list); |
|
|
|
|
|
|
|
|
|
// gives the related weighting to the student |
|
|
|
|
$questionScore += $answerWeighting[$i]; |
|
|
|
|
// increments total score |
|
|
|
|
$totalScore += $answerWeighting[$i]; |
|
|
|
|
// adds the word in green at the end of the string |
|
|
|
|
$answer .= $user_tags[$i]; |
|
|
|
|
} elseif (!empty ($user_tags[$i])) { |
|
|
|
|
// else if the word entered by the student IS NOT the same as the one defined by the professor |
|
|
|
|
// adds the word in red at the end of the string, and strikes it |
|
|
|
|
$answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>'; |
|
|
|
|
} else { |
|
|
|
|
// adds a tabulation if no word has been typed by the student |
|
|
|
|
$answer .= ''; // remove that causes issue |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// adds the correct word, followed by ] to close the blank |
|
|
|
|
$answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]'; |
|
|
|
|
if (isset($real_text[$i +1])) { |
|
|
|
|
$answer .= $real_text[$i + 1]; |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
break; |
|
|
|
|
// for calculated answer |
|
|
|
|
case CALCULATED_ANSWER: |
|
|
|
|
|