Browse Source

Minor - Improve comments in set_coach_to_course_session() and return false in general if no successful result

Yannick Warnier 10 years ago
parent
commit
365967d882
1 changed files with 11 additions and 7 deletions
  1. 11 7
      main/inc/lib/sessionmanager.lib.php

+ 11 - 7
main/inc/lib/sessionmanager.lib.php

@@ -2613,13 +2613,16 @@ class SessionManager
 
         if (Database::num_rows($rs_check_user) > 0) {
             if ($nocoach) {
-                // check if user_id exits int session_rel_user
+                // check if user_id exists in session_rel_user (if the user is
+                // subscribed to the session in any manner)
                 $sql = "SELECT id_user FROM $tbl_session_rel_user
                         WHERE id_session = '$session_id' AND id_user = '$user_id'";
                 $res = Database::query($sql);
 
                 if (Database::num_rows($res) > 0) {
-                    // The user don't be a coach now
+                    // The user is already subscribed to the session. Change the
+                    // record so the user is NOT a coach for this course anymore
+                    // and then exit
                     $sql = "UPDATE $tbl_session_rel_course_rel_user SET status = 0
                             WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id' ";
                     Database::query($sql);
@@ -2628,7 +2631,9 @@ class SessionManager
                     else
                         return false;
                 } else {
-                    // The user don't be a coach now
+                    // The user is not subscribed to the session, so make sure
+                    // he isn't subscribed to a course in this session either
+                    // and then exit
                     $sql = "DELETE FROM $tbl_session_rel_course_rel_user
                             WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id' ";
                     Database::query($sql);
@@ -2638,8 +2643,8 @@ class SessionManager
                         return false;
                 }
             } else {
-                // Assign user like a coach to course
-                // First check if the user is registered in the course
+                // Assign user as a coach to course
+                // First check if the user is registered to the course
                 $sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user
                         WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id'";
                 $rs_check = Database::query($sql);
@@ -2665,9 +2670,8 @@ class SessionManager
                     }
                 }
             }
-        } else {
-            return false;
         }
+        return false;
     }
 
     /**