]> git.mjollnir.org Git - moodle.git/commitdiff
made get_course_users and similar functions work also for the site course
authorgustav_delius <gustav_delius>
Thu, 1 Jul 2004 21:00:07 +0000 (21:00 +0000)
committergustav_delius <gustav_delius>
Thu, 1 Jul 2004 21:00:07 +0000 (21:00 +0000)
lib/datalib.php
lib/moodlelib.php

index 8e0ff705ea0a56e686093201ab0becbcfbddfda1..79eb6f6e97e093cd34b32b70c911094912a5619f 100644 (file)
@@ -1106,7 +1106,8 @@ function get_recent_enrolments($courseid, $timestart) {
 }
 
 /**
-* Returns list of all students in this course
+* Returns array of userinfo of all students in this course
+* or on this site if courseid is id of site
 * 
 * @param    type description
 */
@@ -1115,6 +1116,16 @@ function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0,
 
     global $CFG;
 
+    $site = get_site();
+    if ($courseid == $site->id) { 
+        $sort = str_replace('s.timeaccess', '', $sort); // site users can't be sorted by timeaccess
+        $sort = str_replace('u.', '', $sort); // the get_user function doesn't use the u. prefix to fields
+        if ($sort) {
+            $sort = "$sort $dir";
+        }
+        return get_users(true, $search, true, '', $sort, $firstinitial, $lastinitial, $page, $recordsperpage);
+    }
+
     switch ($CFG->dbtype) {
         case "mysql":
              $fullname = " CONCAT(firstname,\" \",lastname) ";
@@ -1169,7 +1180,7 @@ function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0,
 }
 
 /**
-* Counts the students in a given course, or a subset of them
+* Counts the students in a given course (or site), or a subset of them
 * 
 * @param    type description
 */
@@ -1177,6 +1188,10 @@ function count_course_students($course, $search="", $firstinitial="", $lastiniti
 
     global $CFG;
 
+    if (!$course->category) {
+        return get_users(false, $search, true, '', '', $firstinitial, $lastinitial);
+    }
+
     switch ($CFG->dbtype) {
         case "mysql":
              $fullname = " CONCAT(firstname,\" \",lastname) ";
@@ -1217,7 +1232,8 @@ function count_course_students($course, $search="", $firstinitial="", $lastiniti
 
 
 /**
-* Returns list of all teachers in this course
+* Returns list of all teachers in this course 
+* (also works for site)
 * 
 * @param    type description
 */
@@ -1246,7 +1262,7 @@ function get_course_users($courseid, $sort="timeaccess DESC") {
     $site = get_site();
 
     if ($courseid == $site->id) {
-        return get_site_users();
+        return get_users(true, '', true, '', $sort);
     }
 
     /// Using this method because the single SQL just would not always work!
index db5ecb0eef55dea8462061b1b352f49d5e5904d7..cd1b7bdc5dd011704bd70531c8c9456df1b58102 100644 (file)
@@ -560,8 +560,20 @@ function iscreator ($userid=0) {
 
 function isstudent($courseid, $userid=0) {
 /// Is the user a student in this course?
+/// If course is site, is the user a confirmed user on the site?
     global $USER;
 
+    $site = get_site();
+    if ($courseid == $site->id) {
+        if (!$userid) {
+            $userid = $USER->id;
+        }
+        if (isguest($userid)) {
+            return false;
+        }
+        return record_exists('user', 'id', $userid, 'confirmed', 1, 'deleted', 0);
+    }
+
     if (!$userid) {
         return !empty($USER->student[$courseid]);
     }