/**
* Gets the list of roles assigned to this context and up (parents)
* @param object $context
+ * @param view - set to true when roles are pulled for display only
+ * this is so that we can filter roles with no visible
+ * assignment, for example, you might want to "hide" all
+ * course creators when browsing the course participants
+ * list.
* @return array
*/
-function get_roles_used_in_context($context) {
+function get_roles_used_in_context($context, $view = false) {
global $CFG;
+
+ // filter for roles with all hidden assignments
+ // no need to return when only pulling roles for reviewing
+ // e.g. participants page.
+ $hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 ';
$contextlist = get_related_contexts_string($context);
$sql = "SELECT DISTINCT r.id,
{$CFG->prefix}role r
WHERE r.id = ra.roleid
AND ra.contextid $contextlist
+ $hiddensql
ORDER BY r.sortorder ASC";
return get_records_sql($sql);
}
- if ($roles = get_roles_used_in_context($context)) {
+ if ($roles = get_roles_used_in_context($context, true)) {
// We should exclude "admin" users (those with "doanything" at site level) because
// Otherwise they appear in every participant list
$selectrole = " ";
}
$select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
- u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, ul.timeaccess AS lastaccess '; // s.lastaccess
+ u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, ul.timeaccess AS lastaccess, r.hidden '; // s.lastaccess
//$select .= $course->enrolperiod?', s.timeend ':'';
$from = "FROM {$CFG->prefix}user u INNER JOIN
{$CFG->prefix}role_assignments r on u.id=r.userid LEFT OUTER JOIN
{$CFG->prefix}user_lastaccess ul on (r.userid=ul.userid and ul.courseid = $course->id)";
+
+ $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';
+
// join on 2 conditions
// otherwise we run into the problem of having records in ul table, but not relevant course
// and user record is not pulled out
$where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
AND u.deleted = 0 $selectrole
AND (ul.courseid = $course->id OR ul.courseid IS NULL)
- AND u.username <> 'guest' ";
+ AND u.username <> 'guest'
+ $hiddensql ";
$where .= get_lastaccess_sql($accesssince);
$wheresearch = '';
} else {
$countrysort = (strpos($sort, 'country') !== false);
$timeformat = get_string('strftimedate');
+
+
if (!empty($userlist)) {
foreach ($userlist as $user) {
+ if ($user->hidden) {
+ // if the assignment is hidden, display icon
+ $hidden = "<img src=\"{$CFG->pixpath}/t/hide.gif\" alt=\"".get_string('hiddenassign')."\" class=\"hide-show-image\"/>";
+ } else {
+ $hidden = '';
+ }
+
if ($user->lastaccess) {
$lastaccess = format_time(time() - $user->lastaccess, $datestring);
} else {
$data = array (
print_user_picture($user->id, $course->id, $user->picture, false, true),
- '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a></strong>');
+ '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a></strong>'.$hidden);
if (!isset($hiddenfields['city'])) {
$data[] = $user->city;
}