|
|
|
|
@ -2864,6 +2864,53 @@ HOTSPOT; |
|
|
|
|
|
|
|
|
|
return $return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the correct answer count for a fill blanks question |
|
|
|
|
* |
|
|
|
|
* @param int $question_id |
|
|
|
|
* @param int $exercise_id |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
public static function getNumberStudentsFillBlanksAnwserCount( |
|
|
|
|
$question_id, |
|
|
|
|
$exercise_id |
|
|
|
|
) { |
|
|
|
|
$listStudentsId = []; |
|
|
|
|
$listAllStudentInfo = CourseManager::get_student_list_from_course_code( |
|
|
|
|
api_get_course_id(), |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
foreach ($listAllStudentInfo as $i => $listStudentInfo) { |
|
|
|
|
$listStudentsId[] = $listStudentInfo['user_id']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$listFillTheBlankResult = FillBlanks::getFillTheBlankTabResult( |
|
|
|
|
$exercise_id, |
|
|
|
|
$question_id, |
|
|
|
|
$listStudentsId, |
|
|
|
|
'1970-01-01', |
|
|
|
|
'3000-01-01' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$arrayCount = []; |
|
|
|
|
|
|
|
|
|
foreach ($listFillTheBlankResult as $resultCount) { |
|
|
|
|
foreach ($resultCount as $index => $count) { |
|
|
|
|
//this is only for declare the array index per answer |
|
|
|
|
$arrayCount[$index] = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($listFillTheBlankResult as $resultCount) { |
|
|
|
|
foreach ($resultCount as $index => $count) { |
|
|
|
|
$count = ($count === 0) ? 1 : 0; |
|
|
|
|
$arrayCount[$index] += $count; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $arrayCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param int $question_id |
|
|
|
|
@ -3126,7 +3173,8 @@ HOTSPOT; |
|
|
|
|
while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
|
|
|
$fill_blank = self::check_fill_in_blanks( |
|
|
|
|
$correct_answer, |
|
|
|
|
$row['answer'] |
|
|
|
|
$row['answer'], |
|
|
|
|
$current_answer |
|
|
|
|
); |
|
|
|
|
if (isset($fill_blank[$current_answer]) && $fill_blank[$current_answer] == 1) { |
|
|
|
|
$good_answers++; |
|
|
|
|
@ -3151,7 +3199,7 @@ HOTSPOT; |
|
|
|
|
* @param string $user_answer |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public static function check_fill_in_blanks($answer, $user_answer) |
|
|
|
|
public static function check_fill_in_blanks($answer, $user_answer, $current_answer) |
|
|
|
|
{ |
|
|
|
|
// the question is encoded like this |
|
|
|
|
// [A] B [C] D [E] F::10,10,10@1 |
|
|
|
|
@ -3208,10 +3256,28 @@ HOTSPOT; |
|
|
|
|
|
|
|
|
|
preg_match_all('#\[([^[]*)\]#', $str, $arr); |
|
|
|
|
$str = str_replace('\r\n', '', $str); |
|
|
|
|
$choice = $arr[1]; |
|
|
|
|
|
|
|
|
|
$choices = $arr[1]; |
|
|
|
|
$choice = []; |
|
|
|
|
$check = false; |
|
|
|
|
$i = 0; |
|
|
|
|
foreach ($choices as $item) { |
|
|
|
|
if ($current_answer === $item) { |
|
|
|
|
$check = true; |
|
|
|
|
} |
|
|
|
|
if ($check) { |
|
|
|
|
$choice[] = $item; |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
if ($i == 3) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$tmp = api_strrpos($choice[$j], ' / '); |
|
|
|
|
$choice[$j] = api_substr($choice[$j], 0, $tmp); |
|
|
|
|
|
|
|
|
|
if ($tmp !== false) { |
|
|
|
|
$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 |
|
|
|
|
|