diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index d13b21b7be..6871481682 100644 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -15,17 +15,6 @@ */ // The initialization class for the online editor is needed here. require_once dirname(__FILE__).'/../inc/lib/fckeditor/fckeditor.php'; -/* -$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); -$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); -$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); -$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); -$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); - -$main_user_table = Database::get_main_table(TABLE_MAIN_USER); -$main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER); -$TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); -$TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);*/ /** * Shows a question @@ -1623,8 +1612,6 @@ function get_best_average_score_by_exercise($exercise_id, $course_code, $session return $avg_score; } - - function get_exercises_to_be_taken($course_code, $session_id) { $course_info = api_get_course_info($course_code); $exercises = get_all_exercises($course_info, $session_id); @@ -1655,7 +1642,7 @@ function get_student_stats_by_question($question_id, $exercise_id, $course_code $course_code = Database::escape_string($course_code); $session_id = intval($session_id); - $sql = "SELECT count(exe_user_id) as users, MAX(marks) as max , MIN(marks) as min, AVG(marks) as average + $sql = "SELECT MAX(marks) as max , MIN(marks) as min, AVG(marks) as average FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) WHERE exe_exo_id = $exercise_id AND course_code = '$course_code' AND @@ -1670,14 +1657,89 @@ function get_student_stats_by_question($question_id, $exercise_id, $course_code return $return; } +function get_number_students_question_with_answer_count($question_id, $exercise_id, $course_code, $session_id) { + $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + + $question_id = intval($question_id); + $exercise_id = intval($exercise_id); + $course_code = Database::escape_string($course_code); + $session_id = intval($session_id); + + $sql = "SELECT DISTINCT exe_user_id + FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) + WHERE exe_exo_id = $exercise_id AND + course_code = '$course_code' AND + e.session_id = $session_id AND + question_id = $question_id AND + answer <> 0 AND + status = ''"; + $result = Database::query($sql); + $return = 0; + if ($result) { + $return = Database::num_rows($result); + } + return $return; +} + +function get_number_students_answer_count($answer_id, $question_id, $exercise_id, $course_code, $session_id) { + $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); -// --------------------------------------------------------- + $question_id = intval($question_id); + $answer_id = intval($answer_id); + $exercise_id = intval($exercise_id); + $course_code = Database::escape_string($course_code); + $session_id = intval($session_id); + + $sql = "SELECT DISTINCT exe_user_id + FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) + WHERE exe_exo_id = $exercise_id AND + course_code = '$course_code' AND + e.session_id = $session_id AND + answer = $answer_id AND + question_id = $question_id AND status = ''"; + $result = Database::query($sql); + $return = 0; + if ($result) { + $return = Database::num_rows($result); + } + return $return; +} + + +function get_number_students_finish_exercise($exercise_id, $course_code, $session_id) { + $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + + $exercise_id = intval($exercise_id); + $course_code = Database::escape_string($course_code); + $session_id = intval($session_id); + + $sql = "SELECT DISTINCT exe_user_id + FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) + WHERE exe_exo_id = $exercise_id AND + course_code = '$course_code' AND + e.session_id = $session_id AND + status = ''"; + $result = Database::query($sql); + $return = 0; + if ($result) { + $return = Database::num_rows($result); + + } + return $return; +} + + + +/** // return the HTML code for a menu with students group // @input : $in_name : is the name and the id of the -// --------------------------------------------------------- +*/ function displayGroupMenu($in_name, $in_default, $in_onchange="") { // check the default value of option $tabSelected = array($in_default => " selected='selected' "); @@ -1700,10 +1762,7 @@ function displayGroupMenu($in_name, $in_default, $in_onchange="") { } -// ------------------------------------------------------ -// return a list of group for user with user_id=in_userid -// separated with in_separator -// -------------------------------------------------- +/* Return a list of group for user with user_id=in_userid separated with in_separator */ function displayGroupsForUser($in_separator, $in_userid) { $res = implode($in_separator, GroupManager::get_user_group_name($in_userid)); if ($res == "") { diff --git a/main/exercice/stats.php b/main/exercice/stats.php index f7d36dced4..3af124e362 100644 --- a/main/exercice/stats.php +++ b/main/exercice/stats.php @@ -19,6 +19,7 @@ if (!$result) { } $students = CourseManager :: get_student_list_from_course_code(api_get_course_id(), false); +$count_students = count($students); $question_list = $objExercise->get_validated_question_list(); @@ -27,7 +28,8 @@ $data = array(); $headers = array( get_lang('Question'), get_lang('QuestionType'), - get_lang('NumberOfStudentsWhoTryTheExercise'), + //get_lang('NumberOfStudentsWhoTryTheExercise'), + get_lang('NumberStudentWhoSelectedIt'), get_lang('LowestScore'), get_lang('AverageScore'), get_lang('HighestScore'), @@ -38,10 +40,15 @@ if (!empty($question_list)) { foreach($question_list as $question_id) { $question_obj = Question::read($question_id); $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id()); + $count_users = get_number_students_question_with_answer_count($question_id, $exercise_id, api_get_course_id(), api_get_session_id()); $data[$question_id]['name'] = cut($question_obj->question, 100); $data[$question_id]['type'] = $question_obj->get_question_type_name(); - $data[$question_id]['students_who_try_exercise'] = $exercise_stats['users']; + //$data[$question_id]['students_who_try_exercise'] = $exercise_stats['users']; + $percentange = $count_users/$count_students*100; + + $data[$question_id]['students_who_try_exercise'] = Display::bar_progress($percentange, false, $count_users .' / '.$count_students); + $data[$question_id]['lowest_score'] = round($exercise_stats['min'], 2); $data[$question_id]['average_score'] = round($exercise_stats['average'], 2); $data[$question_id]['highest_score'] = round($exercise_stats['max'], 2); @@ -76,10 +83,68 @@ $headers = array( get_lang('Question'), get_lang('Answer'), get_lang('Correct'), - get_lang('NumberStudentWhoSelectedIt'), - get_lang('HighestScore'), - get_lang('MaximumScore') + get_lang('NumberStudentWhoSelectedIt') ); + +$data = array(); + +if (!empty($question_list)) { + $id = 0; + foreach ($question_list as $question_id) { + $question_obj = Question::read($question_id); + $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id()); + + $answer = new Answer($question_id); + $answer_count = $answer->selectNbrAnswers(); + + for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) { + $answer_info = $answer->selectAnswer($answer_id); + if ($answer_id == 1) { + $data[$id]['name'] = cut($question_obj->question, 100); + } else { + $data[$id]['name'] = '-'; + } + $data[$id]['answer'] = $answer_info; + $is_correct = $answer->isCorrect($answer_id); + + $data[$id]['correct'] = $is_correct == 1 ? get_lang('Yes') : get_lang('No'); + + $real_answer_id = $answer->selectAutoId($answer_id); + + $count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id()); + //$data[$id]['attempts'] = $count.'/'.$count_students; + $percentange = $count/$count_students*100; + $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students); + + + $id++; + } + + } +} + +//Format A table +$table = new HTML_Table(array('class' => 'data_table')); +$row = 0; +$column = 0; +foreach ($headers as $header) { + $table->setHeaderContents($row, $column, $header); + $column++; +} +$row++; +foreach ($data as $row_table) { + $column = 0; + foreach ($row_table as $cell) { + $table->setCellContents($row, $column, $cell); + $table->updateCellAttributes($row, $column, 'align="center"'); + $column++; + } + $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true); + $row++; +} +$content .= $table->toHtml(); + + $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices')); $interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name);