From 3c268f25696204304a3e1d42c3271d039b847ee4 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 25 May 2008 14:27:33 +0000 Subject: [PATCH] MDL-14978 removed obsoleted get_course_users() --- lib/deprecatedlib.php | 54 ----------------------------------------- mod/forum/lib.php | 6 +++-- mod/survey/download.php | 8 +++--- mod/survey/graph.php | 8 +++--- mod/survey/report.php | 10 +++++--- 5 files changed, 21 insertions(+), 65 deletions(-) diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 6be85ee74a..1221c48911 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -203,60 +203,6 @@ function get_recent_enrolments($courseid, $timestart) { ORDER BY l.time ASC"); } -/** - * Returns all the users of a course: students and teachers - * - * @param int $courseid The course in question. - * @param string $sort ? - * @param string $exceptions ? - * @param string $fields A comma separated list of fields to be returned from the chosen table. - * @return object - * @todo Finish documenting this function - */ -function get_course_users($courseid, $sort='ul.timeaccess DESC', $exceptions='', $fields='u.*, ul.timeaccess as lastaccess') { - global $CFG; - - $context = get_context_instance(CONTEXT_COURSE, $courseid); - - /// If the course id is the SITEID, we need to return all the users if the "defaultuserroleid" - /// has the capbility of accessing the site course. $CFG->nodefaultuserrolelists set to true can - /// over-rule using this. - if (($courseid == SITEID) && !empty($CFG->defaultuserroleid) && empty($CFG->nodefaultuserrolelists)) { - if ($roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context)) { - $hascap = false; - foreach ($roles as $role) { - if ($role->id == $CFG->defaultuserroleid) { - $hascap = true; - break; - } - } - if ($hascap) { - if (empty($fields)) { - $fields = '*'; - } - return get_users(true, '', true, $exceptions, 'lastname ASC', '', '', '', '', $fields); - } - } - } - return get_users_by_capability($context, 'moodle/course:view', $fields, $sort, '','','',$exceptions, false); - -} - -/** - * Returns a list of all site users - * Obsolete, just calls get_course_users(SITEID) - * - * @uses SITEID - * @deprecated Use {@link get_course_users()} instead. - * @param string $fields A comma separated list of fields to be returned from the chosen table. - * @return object|false {@link $USER} records or false if error. - */ -function get_site_users($sort='u.lastaccess DESC', $fields='*', $exceptions='') { - - return get_course_users(SITEID, $sort, $exceptions, $fields); -} - - ########### FROM weblib.php ########################################################################## /** diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 3d99f90ece..3368e3e813 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -70,8 +70,10 @@ function forum_add_instance($forum) { } } - if ($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE) { // all users should be subscribed initially - $users = get_course_users($forum->course); + if ($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE) { + // all users should be subscribed initially + $users = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $forum->course), + 'mod/forum:initialsubscriptions', 'u.id', '', '','','',null, false); foreach ($users as $user) { forum_subscribe($user->id, $forum->id); } diff --git a/mod/survey/download.php b/mod/survey/download.php index eb966aae06..fab478824a 100644 --- a/mod/survey/download.php +++ b/mod/survey/download.php @@ -16,8 +16,10 @@ print_error("Course is misconfigured"); } + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + require_login($course->id, false, $cm); - require_capability('mod/survey:download', get_context_instance(CONTEXT_MODULE, $cm->id)) ; + require_capability('mod/survey:download', $context) ; if (! $survey = get_record("survey", "id", $cm->instance)) { print_error("Survey ID was incorrect"); @@ -30,9 +32,9 @@ $groupmode = groups_get_activity_groupmode($cm); // Groups are being used if ($groupmode and $group) { - $users = groups_get_members($group); + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $group, null, false); } else { - $users = get_course_users($course->id); + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', '', null, false); $group = false; } diff --git a/mod/survey/graph.php b/mod/survey/graph.php index 4d2e9c5edc..71f2bf01fa 100644 --- a/mod/survey/graph.php +++ b/mod/survey/graph.php @@ -37,11 +37,13 @@ /// Check to see if groups are being used in this survey if ($group) { - $users = groups_get_members($group); + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $group, null, false); } else if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) { - $users = groups_get_grouping_members($cm->groupingid); + $groups = groups_get_all_groups($courseid, 0, $cm->groupingid); + $groups = array_keys($groups); + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $groups, null, false); } else { - $users = get_course_users($course->id); + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', '', null, false); $group = false; } diff --git a/mod/survey/report.php b/mod/survey/report.php index ea1a154c56..b18ee4b8cc 100644 --- a/mod/survey/report.php +++ b/mod/survey/report.php @@ -80,12 +80,16 @@ } if ($currentgroup) { - $users = groups_get_members($currentgroup); + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $currentgroup, null, false); } else if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) { - $users = groups_get_grouping_members($cm->groupingid); + $groups = groups_get_all_groups($courseid, 0, $cm->groupingid); + $groups = array_keys($groups); + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $groups, null, false); } else { - $users = get_course_users($course->id); + $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', '', null, false); + $group = false; } + $groupingid = $cm->groupingid; print_simple_box_start("center"); -- 2.39.5