]> git.mjollnir.org Git - moodle.git/commitdiff
replacing references to user_* tables
authortoyomoyo <toyomoyo>
Tue, 19 Sep 2006 01:44:33 +0000 (01:44 +0000)
committertoyomoyo <toyomoyo>
Tue, 19 Sep 2006 01:44:33 +0000 (01:44 +0000)
13 files changed:
admin/index.php
admin/user.php
auth/db/lib.php
auth/ldap/lib.php
course/import/activities/mod.php
lang/en_utf8/docs/releaseold.html
lib/accesslib.php
lib/datalib.php
lib/deprecatedlib.php
lib/moodlelib.php
message/lib.php
mod/hotpot/report.php
question/import.php

index 881671f4711c42490e2c0747f2a6a0380ba95517..6f9a39aaf90373de14ead227a9ecdffa1a20ee87 100644 (file)
@@ -98,7 +98,7 @@
         $maintables = true;
         $mtables = array("config", "course", "course_categories", "course_modules",
                          "course_sections", "log", "log_display", "modules",
-                         "user", "user_admins", "user_students", "user_teachers");
+                         "user");
         foreach ($mtables as $mtable) {
             if (!in_array($CFG->prefix.$mtable, $tables)) {
                 $maintables = false;
index 593a76e599481c466bc8c0af3901c24033692aeb..3b82eafff08708d8b71a03b70603d80937c71aa4 100644 (file)
                 $updateuser->idnumber = "";               // Clear this field to free it up
                 $updateuser->timemodified = time();
                 if (update_record("user", $updateuser)) {
-                    unenrol_student($user->id);  // From all courses
-                    remove_teacher($user->id);   // From all courses
-                    remove_admin($user->id);
+                    // not sure if this is needed. unenrol_student($user->id);  // From all courses
+                    delete_records('role_assignments', 'userid', $user->id); // unassign all roles
+                    // remove all context assigned on this user?              
                     notify(get_string("deletedactivity", "", fullname($user, true)) );
                 } else {
                     notify(get_string("deletednot", "", fullname($user, true)));
index 838d2647ca70b0ee10d5b8fe03ab247544af0b6a..b2f2aead37b9b38eda0f58644b273d95d5cd7e3b 100644 (file)
@@ -183,9 +183,10 @@ function auth_sync_users ($do_updates=0) {
             $updateuser->deleted = "1";
             $updateuser->timemodified = time();
             if (update_record("user", $updateuser)) {
-                unenrol_student($user->id);  // From all courses
-                remove_teacher($user->id);   // From all courses
-                remove_admin($user->id);
+                // unenrol_student($user->id);  // From all courses
+                // remove_teacher($user->id);   // From all courses
+                // remove_admin($user->id);
+                delete_records('role_assignments', 'userid', $user->id); // unassign all roles
                 notify(get_string("deletedactivity", "", fullname($user, true)) );
             } else {
                 notify(get_string("deletednot", "", fullname($user, true)));
index b0eb9e4092137075aa8cf4c32a5a59468eca5f7b..c314ea1b4ba9f16218be284f873e5d86d726d47f 100644 (file)
@@ -507,9 +507,10 @@ function auth_sync_users ($bulk_insert_records = 1000, $do_updates=1) {
             //$updateuser->email = "";               // Clear this field to free it up
             $updateuser->timemodified = time();
             if (update_record("user", $updateuser)) {
-                unenrol_student($user->id);  // From all courses
-                remove_teacher($user->id);   // From all courses
-                remove_admin($user->id);
+                // unenrol_student($user->id);  // From all courses
+                // remove_teacher($user->id);   // From all courses
+                // remove_admin($user->id);
+                delete_records('role_assignments', 'userid', $user->id); // unassign all roles
                 notify(get_string("deletedactivity", "", fullname($user, true)) );
             } else {
                 notify(get_string("deletednot", "", fullname($user, true)));
index 8776e5a28e5ef341aa3681499840f0bbc2617618..0a4776142b12e5ed8a172c206eb6e302dc944a84 100644 (file)
  
     $tcourseids = '';
  
-    if ($teachers = get_records_select('user_teachers', "userid = $USER->id AND editall = 1",'','id,course')) {
+    if ($teachers = get_user_capability_course('moodle/course:edit')) {
         foreach ($teachers as $teacher) {
-            if ($teacher->course != $course->id && $teacher->course != SITEID){
-                $tcourseids .= $teacher->course.',';
+            if ($teacher->id != $course->id && $teacher->id != SITEID){
+                $tcourseids .= $teacher->id',';
             }
         }
     }
index 30600502af23dc25f24a26aafd307ac3e3d4ee8d..7f26fb65f57de829717852d5d7785a679309dd9a 100644 (file)
         <li>Improved handling of ratings for single forums when secureforms is on.</li>
         <li>Multichoice question creation now defaults to a single correct answer format</li>
         <li>Guests can no longer see email addresses if "show only to course participants" has been set by that user</li>
-        <li>Primary admin is now the lowest-numbered entry in user_admins, rather than the admin with the lowest userid.</li>
+        <li>Primary admin is now the lowest-numbered entry in role_assignement with moodle/legacy:admin capability, rather than the admin with the lowest userid.</li>
         <li>Modified flash MP3 plugin to improve brightness of Play button on darker screens</li>
         <li>Various polishing and improvements in many language packs</li>
       </ul>
index a08efde48b972948a24ac5ea455f3a4715e66b6c..09148ff1461a33b229650d5a09673e182484615b 100755 (executable)
@@ -2546,4 +2546,28 @@ function get_role_users($roleid, $context, $parent=false) {
     return get_records_sql($SQL);
 }
 
+/** 
+ * This function gets the list of courses that this user has a particular capability in
+ * This is not the most efficient way of doing this
+ * @param string capability
+ * @param int $userid
+ * @return array
+ */
+function get_user_capability_course($capability, $userid='') {
+    
+    global $USER;
+    if (!$userid) {
+        $userid = $USER->id;  
+    }
+    
+    $usercourses = array();
+    $courses = get_records_select('course', '', '', 'id, id');
+    
+    foreach ($courses as $course) {
+        if (has_capability($capability, get_context_capability(CONTEXT_COURSE, $course->id))) {
+            $usercourses[] = $course;
+        }
+    }
+    return $usercourses;  
+}
 ?>
index e5b8158682e7464b77e8a823c0909b92627f8464..f7e2500557d459dbcda70802216ffcbe4ba211e7 100644 (file)
@@ -706,16 +706,6 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC') {
 
     return get_records_list('course', 'id', $courseids, $sort);
 */
-//  The following is correct but VERY slow with large datasets
-//
-//    return get_records_sql("SELECT c.*
-//                              FROM {$CFG->prefix}course c,
-//                                   {$CFG->prefix}user_students s,
-//                                   {$CFG->prefix}user_teachers t
-//                             WHERE (s.userid = '$userid' AND s.course = c.id)
-//                                OR (t.userid = '$userid' AND t.course = c.id)
-//                             GROUP BY c.id
-//                             ORDER BY $sort");
 }
 
 
index 4a2f94ba4bfc77b958d4a5e9483b1910e4cfb155..b48f0e43bee31d93a2ba02efb829ba395ed7d95a 100644 (file)
@@ -37,7 +37,7 @@
 
 
 
-      
+
 /**
  * Ensure that a variable is set
  *
@@ -56,7 +56,6 @@ function require_variable($var) {
     }
 }
 
-
 /**
  * Ensure that a variable is set
  *
@@ -75,8 +74,6 @@ function optional_variable(&$var, $default=0) {
     }
 }
 
-
-
 /**
  * Determines if a user an admin
  *
@@ -192,7 +189,6 @@ function isteacherinanycourse($userid=0, $includeadmin=true) {
     return false;
 }
 
-
 /**
  * Determines if a user is allowed to edit a given course
  *
@@ -282,8 +278,6 @@ function isguest($userid=0) {
     return has_capability('moodle/legacy:guest', $context, $userid, false);
 }
 
-
-
 /**
  * Enrols (or re-enrols) a student in a given course
  *
@@ -319,7 +313,6 @@ function enrol_student($userid, $courseid, $timestart=0, $timeend=0, $enrol='man
     return role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol);
 }
 
-
 /**
  * Unenrols a student from a given course
  *
@@ -681,7 +674,6 @@ function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page=''
     */
 }
 
-
 /**
  * Counts the students in a given course (or site), or a subset of them
  *
@@ -702,7 +694,6 @@ function count_course_students($course, $search='', $firstinitial='', $lastiniti
     return 0;
 }
 
-
 /**
  * Returns list of all teachers in this course
  *
@@ -754,8 +745,6 @@ function get_course_users($courseid, $sort='ul.timeaccess DESC', $exceptions='',
 
 }
 
-
-
 /**
  * Returns an array of user objects
  *
index 89d298578db0c8b7916d72138f65e1a0dda2c085..7bcf5b7c1947f2f699e97a1098055319f6404b97 100644 (file)
@@ -2665,8 +2665,8 @@ function remove_course_contents($courseid, $showfeedback=true) {
     // This array stores the tables that need to be cleared, as
     // table_name => column_name that contains the course id.
     $tablestoclear = array(
-        'user_students' => 'course', // Delete any user stuff
-        'user_teachers' => 'course',
+        //'user_students' => 'course', // Delete any user stuff
+        //'user_teachers' => 'course',
         'event' => 'courseid', // Delete events
         'log' => 'course', // Delete logs
         'course_sections' => 'course', // Delete any course stuff
@@ -2788,6 +2788,7 @@ function reset_course_userdata($data, $showfeedback=true) {
         } else {
             $result = false;
         }
+
         /// Delete group members (but keep the groups)
         if ($groups = get_records('groups', 'courseid', $data->courseid)) {
             foreach ($groups as $group) {
index e0fed63fd24e58e25d665ad2c6c0718f6acad6b3..acdec0c456a7ac15c84b3dae17aeedc4f0619def 100644 (file)
@@ -232,12 +232,12 @@ function message_print_search() {
         message_print_search_results($frm);
         
     } else {
-        if ($teachers = get_records('user_teachers', 'userid', $USER->id, '', 'id, course')) {
-        
+        // find all courses this use has readallmessages capabilities in
+        if ($teachers = get_user_capability_course('moodle/site:readallmessages')) {
             $courses = get_courses('all', 'c.sortorder ASC', 'c.id, c.shortname');
             $cs = '<select name="courseselect">';
             foreach ($teachers as $tcourse) {
-                $cs .= "<option value=\"$tcourse->course\">".$courses[$tcourse->course]->shortname."</option>\n";
+                $cs .= "<option value=\"$tcourse->course\">".$courses[$tcourse->id]->shortname."</option>\n";
             }
             $cs .= '</select>';
         }
@@ -701,24 +701,20 @@ function message_search_users($courseid, $searchtext, $sort='', $exceptions='')
                           $except $order");
     } else {
 
-
-        if (!$teachers = get_records_sql("SELECT $fields
-                      FROM {$CFG->prefix}user u,
-                           {$CFG->prefix}user_teachers s
-                      WHERE $select AND s.course = '$courseid' AND s.userid = u.id
-                          AND ($fullname $LIKE '%$searchtext%')
-                          $except $order")) {
-            $teachers = array();
-        }
-        if (!$students = get_records_sql("SELECT $fields
-                      FROM {$CFG->prefix}user u,
-                           {$CFG->prefix}user_students s
-                      WHERE $select AND s.course = '$courseid' AND s.userid = u.id
-                          AND ($fullname $LIKE '%$searchtext%')
-                          $except $order")) {
-            $students = array();
-        }
-        return $teachers + $students;
+        $context = get_context_instance(CONTEXT_COURSE, $courseid);
+        $contextlists = get_related_contexts_string($context);
+        
+        // everyone who has a role assignement in this course or higher
+        $users = get_records_sql("SELECT $fields
+                                 FROM {$CFG->prefix}user u,
+                                      {$CFG->prefix}role_assignments ra
+                                 WHERE $select 
+                                       AND ra.contextid $contextlists
+                                       AND u.id = ra.userid
+                                       AND ($fullname $LIKE '%$searchtext%')
+                                       $except $order");
+
+        return $users;
     }
 }
 
index 22f1ff682b73ed53ddaa9adf58e8aa0ab7615bc0..689f49887e78440ae4e7cf71a7e372a124b945c2 100644 (file)
@@ -87,7 +87,8 @@
             $hotpot_ids = $hotpot->id;
             break;
         case 'all' :
-            $records = get_records_select_menu('user_teachers', "userid='$USER->id'", 'course', 'id, course');
+            $records = get_user_capability_course('mod/hotpot:viewreport');
+            //$records = get_records_select_menu('user_teachers', "userid='$USER->id'", 'course', 'id, course');
             $course_ids = join(',', array_values($records));
 
             $records = get_records_select_menu('hotpot', "reference='$hotpot->reference'", 'reference', 'id, reference');
     $users = array();
     switch ($formdata['reportusers']) {
         case 'all':
+            /*
             $admin_ids = get_records_select_menu('user_admins');
             if (is_array($admin_ids)) {
                 $users = array_merge($users, $admin_ids);
             if (is_array($guest_id)) {
                 $users = array_merge($users, $guest_id);
             }
+            */
             // add students next
 
         case 'students':
index d8f21e85f9093ef8c83ba782583275c49915e429..ae28974543fe39653e3c15b64e5477574ba1416e 100644 (file)
             error("Could not find any question categories!"); // Something is really wrong
         }
     } else { // select only the categories to which the teacher has write access
-        $sql = "SELECT c.*
-              FROM {$CFG->prefix}question_categories AS c,
-                   {$CFG->prefix}user_teachers AS t
-             WHERE t.userid = '$USER->id'
-               AND t.course = c.course
-               AND (c.course = '$course->id' 
-                   OR (c.publish = '1' AND t.editall = '1'))
-          ORDER BY c.parent ASC, c.sortorder ASC, c.name ASC";
-        if (!$categories = get_records_sql($sql)) {
+        $cats = get_records('question_categories');
+        $categories = array();
+        foreach ($cats as $cat) {
+            if (has_capability('moodle/question:managecateory', get_context_instance(CONTEXT_COURSE, $cat->course))) {
+                $categories[] = $cat;
+            }      
+        }
+        if (empty($categories)) {
             error("Could not find any question categories!");
         }
     }