Sfoglia il codice sorgente

Cleaning all incomplete attempts of the admin/teacher to avoid weird problems when changing the exercise settings, number of questions, etc see #2469

Julio Montoya 14 anni fa
parent
commit
2d8cb37dd8
2 ha cambiato i file con 33 aggiunte e 14 eliminazioni
  1. 11 14
      main/exercice/admin.php
  2. 22 0
      main/inc/lib/events.lib.inc.php

+ 11 - 14
main/exercice/admin.php

@@ -86,35 +86,32 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
 if ( empty ( $exerciseId ) ) {
     $exerciseId = intval($_GET['exerciseId']);
 }
-if ( empty ( $newQuestion ) )
-{
+if ( empty ( $newQuestion ) ) {
     $newQuestion = $_GET['newQuestion'];
 }
-if ( empty ( $modifyAnswers ) )
-{
+if ( empty ( $modifyAnswers ) ) {
     $modifyAnswers = $_GET['modifyAnswers'];
 }
-if ( empty ( $editQuestion ) )
-{
+if ( empty ( $editQuestion ) ) {
     $editQuestion = $_GET['editQuestion'];
 }
-if ( empty ( $modifyQuestion ) )
-{
+if ( empty ( $modifyQuestion ) ) {
     $modifyQuestion = $_GET['modifyQuestion'];
 }
-if ( empty ( $deleteQuestion ) )
-{
+if ( empty ( $deleteQuestion ) ) {
     $deleteQuestion = $_GET['deleteQuestion'];
 }
-if ( empty ( $questionId ) )
-{
+if ( empty ( $questionId ) ) {
     $questionId = $_SESSION['questionId'];
 }
-if ( empty ( $modifyExercise ) )
-{
+if ( empty ( $modifyExercise ) ) {
     $modifyExercise = $_GET['modifyExercise'];
 }
 
+//Cleaning all incomplete attempts of the admin/teacher to avoid weird problems when changing the exercise settings, number of questions, etc
+
+delete_all_incomplete_attempts(api_get_user_id(), $exerciseId, api_get_course_id(), api_get_session_id());
+
 // get from session
 $objExercise = $_SESSION['objExercise'];
 $objQuestion = $_SESSION['objQuestion'];

+ 22 - 0
main/inc/lib/events.lib.inc.php

@@ -679,6 +679,28 @@ function delete_student_lp_events($user_id, $lp_id, $course, $session_id) {
     }
 }
 
+/**
+ * Delete exercise attempts (NO in LP) 
+ * 
+ * @param 	int		user id
+ * @param 	int		exercise id 
+ * @param 	string	course code
+ * @param 	int		session id
+  */
+function delete_all_incomplete_attempts($user_id, $exercise_id, $course_code, $session_id = 0) {
+    $track_e_exercises     = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+    $track_attempts        = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
+    $user_id         = intval($user_id);
+    $exercise_id     = intval($exercise_id);
+    $course_code     = Database::escape_string($course_code);
+    $session_id      = intval($session_id);
+    if (!empty($user_id) && !empty($exercise_id) && !empty($course_code)) {
+        $sql = "DELETE FROM $track_e_exercises  WHERE exe_user_id = $user_id AND exe_exo_id = $exercise_id AND exe_cours_id = '$course_code' AND session_id = $session_id AND status = 'incomplete' ";
+        $result = Database::query($sql); 
+    }
+    
+}
+
 /**
  * Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
  * @param   int     exercise id