Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New functions for getting lists of people in a course, and some cleanups

  • Loading branch information...
commit 8a9e3fd753eabf6bbde69a0b72330fb484df1425 1 parent 34354e4
martin authored
Showing with 24 additions and 6 deletions.
  1. +24 −6 lib/moodlelib.php
30 lib/moodlelib.php
View
@@ -911,7 +911,7 @@ function isadmin($userid=0) {
return record_exists_sql("SELECT * FROM user_admins WHERE user='$userid'");
}
-function isteacher($course, $userid=0) {
+function isteacher($courseid, $userid=0) {
global $USER;
if (isadmin($userid)) { // admins can do anything the teacher can
@@ -919,23 +919,23 @@ function isteacher($course, $userid=0) {
}
if (!$userid) {
- return $USER->teacher[$course];
+ return $USER->teacher[$courseid];
}
- return record_exists_sql("SELECT * FROM user_teachers WHERE user='$userid' AND course='$course'");
+ return record_exists_sql("SELECT * FROM user_teachers WHERE user='$userid' AND course='$courseid'");
}
-function isstudent($course, $userid=0) {
+function isstudent($courseid, $userid=0) {
global $USER;
if (!$userid) {
- return $USER->student[$course];
+ return $USER->student[$courseid];
}
$timenow = time(); // todo: add time check below
- return record_exists_sql("SELECT * FROM user_students WHERE user='$userid' AND course='$course'");
+ return record_exists_sql("SELECT * FROM user_students WHERE user='$userid' AND course='$courseid'");
}
function isguest($userid=0) {
@@ -948,6 +948,24 @@ function isguest($userid=0) {
return record_exists_sql("SELECT * FROM user WHERE user='$userid' AND username = 'guest' ");
}
+function get_course_students($courseid, $sort="u.lastaccess DESC") {
+ return get_records_sql("SELECT u.* FROM user u, user_students s
+ WHERE s.course = '$courseid' AND s.user = u.id
+ ORDER BY $sort");
+}
+
+function get_course_teachers($courseid, $sort="t.authority ASC") {
+ return get_records_sql("SELECT u.* FROM user u, user_teachers t
+ WHERE t.course = '$courseid' AND t.user = u.id
+ ORDER BY $sort");
+}
+
+function get_course_participants($courseid, $sort="u.lastaccess DESC") {
+ return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
+ WHERE (s.course = '$courseid' AND s.user = u.id) OR
+ (t.course = '$courseid' AND t.user = u.id)
+ ORDER BY $sort");
+}
function reset_login_count() {
global $SESSION;
Please sign in to comment.
Something went wrong with that request. Please try again.