Skip to content

Commit

Permalink
MDL-14978 removed obsoleted get_course_users()
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed May 25, 2008
1 parent 9fa45d3 commit 3c268f2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 65 deletions.
54 changes: 0 additions & 54 deletions lib/deprecatedlib.php
Expand Up @@ -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 ##########################################################################

/**
Expand Down
6 changes: 4 additions & 2 deletions mod/forum/lib.php
Expand Up @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions mod/survey/download.php
Expand Up @@ -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");
Expand All @@ -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;
}

Expand Down
8 changes: 5 additions & 3 deletions mod/survey/graph.php
Expand Up @@ -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;
}

Expand Down
10 changes: 7 additions & 3 deletions mod/survey/report.php
Expand Up @@ -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");
Expand Down

0 comments on commit 3c268f2

Please sign in to comment.