From: toyomoyo Date: Wed, 15 Nov 2006 04:28:18 +0000 (+0000) Subject: Adding hidden role assignment, currently used in course participants page and print_c... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3997cb403736bf5ab7d75fca3fde2ea3bc4f6d9f;p=moodle.git Adding hidden role assignment, currently used in course participants page and print_course function. Please test. --- diff --git a/admin/roles/assign.html b/admin/roles/assign.html index 8ee63e9a47..620d77bcf7 100755 --- a/admin/roles/assign.html +++ b/admin/roles/assign.html @@ -31,6 +31,8 @@ + + <?php print_string('hiddenassign') ?>

diff --git a/admin/roles/assign.php b/admin/roles/assign.php index b36bbf1007..d49cc3daed 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -19,7 +19,7 @@ $timeend = optional_param('timened', 0, PARAM_INT); $userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs $courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs - + $errors = array(); $previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0; diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 8da55c0895..92288d1134 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -668,6 +668,7 @@ $string['helpsummaries'] = 'About these summaries'; $string['helptext'] = 'How to write text'; $string['helpwiki'] = 'How to write Wiki-like text'; $string['helpwriting'] = 'Write carefully'; +$string['hiddenassign'] = 'Hidden assignment'; $string['hiddensections'] = 'Hidden sections'; $string['hiddensectionscollapsed'] = 'Hidden sections are shown in collapsed form'; $string['hiddensectionsinvisible'] = 'Hidden sections are completely invisible'; diff --git a/lib/accesslib.php b/lib/accesslib.php index 9efcbad8bd..1cba7edc8e 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2707,11 +2707,21 @@ function get_component_string($component, $contextlevel) { /** * 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, @@ -2722,6 +2732,7 @@ function get_roles_used_in_context($context) { {$CFG->prefix}role r WHERE r.id = ra.roleid AND ra.contextid $contextlist + $hiddensql ORDER BY r.sortorder ASC"; return get_records_sql($sql); diff --git a/user/index.php b/user/index.php index 27d695dc51..ef7361c4e5 100644 --- a/user/index.php +++ b/user/index.php @@ -254,7 +254,7 @@ } - 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 @@ -335,18 +335,22 @@ $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 = ''; @@ -514,8 +518,17 @@ } 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 = "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 { @@ -536,7 +549,7 @@ $data = array ( print_user_picture($user->id, $course->id, $user->picture, false, true), - ''.fullname($user).''); + ''.fullname($user).''.$hidden); if (!isset($hiddenfields['city'])) { $data[] = $user->city; }