Fixing query see #5257

skala
Julio Montoya 13 years ago
parent 9231d900ff
commit 9d30f8b124
  1. 44
      main/exercice/exercise.lib.php
  2. 18
      main/exercice/stats.php

@ -1684,7 +1684,7 @@ function get_number_students_answer_hotspot_count($answer_id, $question_id, $ex
}
function get_number_students_answer_count($answer_id, $question_id, $exercise_id, $course_code, $session_id, $question_type = null, $answer = null, $fill_in_blank_answer = null) {
function get_number_students_answer_count($answer_id, $question_id, $exercise_id, $course_code, $session_id, $question_type = null, $correct_answer = null, $current_answer = null) {
$track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
@ -1695,12 +1695,15 @@ function get_number_students_answer_count($answer_id, $question_id, $exercise_id
$course_code = Database::escape_string($course_code);
$session_id = intval($session_id);
if ($question_type == FILL_IN_BLANKS) {
$answer_condition = "";
$select_condition = " e.exe_id, answer ";
} else {
$answer_condition = "answer = $answer_id AND ";
$select_condition = "DISTINCT exe_user_id";
switch ($question_type) {
case FILL_IN_BLANKS:
$answer_condition = "";
$select_condition = " e.exe_id, answer ";
break;
case MATCHING:
default:
$answer_condition = " answer = $answer_id AND ";
$select_condition = " DISTINCT exe_user_id ";
}
$sql = "SELECT $select_condition
@ -1709,26 +1712,29 @@ function get_number_students_answer_count($answer_id, $question_id, $exercise_id
WHERE exe_exo_id = $exercise_id AND
a.course_code = '$course_code' AND
e.session_id = $session_id AND
$answer_condition
question_id = $question_id AND
cu.status = ".STUDENT." AND
relation_type <> 2 AND
e.status = ''";
//var_dump($sql);
$result = Database::query($sql);
$return = 0;
if ($result) {
if ($question_type == FILL_IN_BLANKS) {
$good_answers = 0;
while ($row = Database::fetch_array($result, 'ASSOC')) {
$fill_blank = check_fill_in_blanks($answer, $row['answer']);
if (isset($fill_blank[$fill_in_blank_answer]) && $fill_blank[$fill_in_blank_answer] == 1 ) {
$good_answers++;
$good_answers = 0;
switch ($question_type) {
case FILL_IN_BLANKS:
while ($row = Database::fetch_array($result, 'ASSOC')) {
$fill_blank = check_fill_in_blanks($correct_answer, $row['answer']);
if (isset($fill_blank[$current_answer]) && $fill_blank[$current_answer] == 1 ) {
$good_answers++;
}
}
}
return $good_answers;
} else {
$return = Database::num_rows($result);
return $good_answers;
break;
case MATCHING:
default:
$return = Database::num_rows($result);
}
}
return $return;

@ -131,7 +131,7 @@ if (!empty($question_list)) {
$data[$id]['correct'] = '-';
$count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), $question_obj->type, $answer_info_db, $answer_item);
$count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), FILL_IN_BLANKS, $answer_info_db, $answer_item);
$percentange = $count/$count_students*100;
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
@ -141,24 +141,26 @@ if (!empty($question_list)) {
}
break;
case MATCHING:
if ($is_correct == 0) {
if ($is_correct == 0) {
if ($answer_id == 1) {
$data[$id]['name'] = cut($question_obj->question, 100);
} else {
$data[$id]['name'] = '-';
}
$correct = '';
for ($i = 1; $i <= $answer_count; $i++) {
$is_correct_i = $answer->isCorrect($i);
$is_correct_i = $answer->isCorrect($i);
if ($is_correct_i != 0 && $is_correct_i == $answer_id) {
$correct = $answer->selectAnswer($i);
break;
}
}
$data[$id]['answer'] = $answer_info;
$data[$id]['correct'] = $correct;
$count = get_number_students_answer_count($answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), $real_answer_id);
$data[$id]['answer'] = $correct;
$data[$id]['correct'] = $answer_info;
$count = get_number_students_answer_count($answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), MATCHING);
$percentange = $count/$count_students*100;
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
}

Loading…
Cancel
Save