diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index b09ffb24b4..dc241b46e2 100644 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -43,22 +43,13 @@ require_once api_get_path(LIBRARY_PATH)."groupmanager.lib.php"; // for group fil $is_allowedToEdit = api_is_allowed_to_edit(null,true); $is_tutor = api_is_allowed_to_edit(true); $is_tutor_course = api_is_course_tutor(); -$tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); -$TBL_USER = Database :: get_main_table(TABLE_MAIN_USER); + $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT); $TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); -$TBL_EXERCICE_ANSWER = Database :: get_course_table(TABLE_QUIZ_ANSWER); $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_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); -$TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); -$TBL_TRACK_ATTEMPT = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); -$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); -$TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW); -$TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM); -$TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW); -$TBL_GROUP_REL_USER = Database :: get_course_table(TABLE_GROUP_USER); +$table_lp_item = Database::get_course_table(TABLE_LP_ITEM); // document path $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document"; @@ -285,7 +276,7 @@ if ($is_allowedToEdit) { break; case 'enable' : // enables an exercise $newVisibilityStatus = "1"; //"visible" - $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'"; + $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='" . Database :: escape_string($file) . "'"; $res = Database::query($query); $row = Database :: fetch_array($res, 'ASSOC'); api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']); @@ -294,7 +285,7 @@ if ($is_allowedToEdit) { break; case 'disable' : // disables an exercise $newVisibilityStatus = "0"; //"invisible" - $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'"; + $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='" . Database :: escape_string($file) . "'"; $res = Database::query($query); $row = Database :: fetch_array($res, 'ASSOC'); api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']); @@ -326,13 +317,14 @@ $condition_session = api_get_session_condition($session_id,true,true); // Only for administrators if ($is_allowedToEdit) { - $total_sql = "SELECT count(id) as count FROM $TBL_EXERCICES WHERE active<>'-1' $condition_session "; - $sql = "SELECT * FROM $TBL_EXERCICES WHERE active<>'-1' $condition_session ORDER BY title LIMIT ".$from."," .$limit; + $total_sql = "SELECT count(id) as count FROM $TBL_EXERCICES WHERE c_id = $course_id AND active<>'-1' $condition_session "; + $sql = "SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND active<>'-1' $condition_session ORDER BY title LIMIT ".$from."," .$limit; } else { // Only for students - $total_sql = "SELECT count(id) as count FROM $TBL_EXERCICES WHERE active = '1' $condition_session "; + $total_sql = "SELECT count(id) as count FROM $TBL_EXERCICES WHERE c_id = $course_id AND active = '1' $condition_session "; $sql = "SELECT id, title, type, description, results_disabled, session_id, start_time, end_time, max_attempt FROM $TBL_EXERCICES - WHERE active='1' $condition_session + WHERE c_id = $course_id AND + active='1' $condition_session ORDER BY title LIMIT ".$from."," .$limit; } @@ -349,20 +341,22 @@ if (Database :: num_rows($result_total)) { //get HotPotatoes files (active and inactive) if ($is_allowedToEdit) { - $sql = "SELECT * FROM $TBL_DOCUMENT WHERE path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'"; + $sql = "SELECT * FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'"; $res = Database::query($sql); $hp_count = Database :: num_rows($res); } else { - $res = Database::query("SELECT * FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip - WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' - AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' - AND ip.visibility='1' AND d.c_id=".api_get_course_int_id()." AND ip.c_id=".api_get_course_int_id()); + $sql = "SELECT * FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip + WHERE d.id = ip.ref AND + ip.tool = '" . TOOL_DOCUMENT . "' AND + d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND + ip.visibility ='1' AND + d.c_id = ".$course_id." AND + ip.c_id = ".$course_id; + $res = Database::query($sql); $hp_count = Database :: num_rows($res); } $total = $total_exercises + $hp_count; - - if ($is_allowedToEdit && $origin != 'learnpath') { echo '' . Display :: return_icon('new_exercice.png', get_lang('NewEx'),'','32').''; @@ -448,7 +442,7 @@ if ($is_allowedToEdit) { $count = 0; if (!empty($exercise_list)) - foreach ($exercise_list as $row) { + foreach ($exercise_list as $row) { //echo '
'; print_r($list);*/
+ }
//Getting the best results of every student
$best_score_return = array();
@@ -1125,13 +1117,32 @@ function get_best_exercise_results_by_user($exercise_id, $course_code, $session_
if ($current_best_score[$user_id] > $best_score_return[$user_id]['exe_result']) {
$best_score_return[$user_id] = $student_result;
}
- }
- /*
- echo count($best_score_return);
- echo ''; print_r($best_score_return);*/
+ }
return $best_score_return;
}
+function count_exercise_result($exercise_id, $course_code, $session_id = 0) {
+ $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+
+ $course_code = Database::escape_string($course_code);
+
+ $session_id = intval($session_id);
+ $exercise_id = intval($exercise_id);
+ $select = '*';
+ $sql = "SELECT count(*) as count FROM $table_track_exercises
+ WHERE status = '' AND
+ exe_exo_id = $exercise_id AND
+ exe_cours_id = '$course_code' AND
+ session_id = $session_id AND
+ orig_lp_id = 0 AND
+ orig_lp_item_id = 0 ORDER BY exe_id";
+ $res = Database::query($sql);
+
+ $row = Database::fetch_array($res,'ASSOC');
+ return $row['count'];
+
+}
+
/**
* Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user