mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Adding hidden role assignment, currently used in course participants page and print_course function.
Please test.
This commit is contained in:
parent
4158fd81ce
commit
3997cb4037
@ -31,6 +31,8 @@
|
||||
|
||||
</select></td>
|
||||
<td valign="top">
|
||||
<input type="checkbox" name="hidden" value="1" />
|
||||
<img src="<?php echo $CFG->pixpath; ?>/t/hide.gif" alt="<?php print_string('hiddenassign') ?>" class="hide-show-image" />
|
||||
<br />
|
||||
<input name="add" type="submit" id="add" value="←" />
|
||||
<br />
|
||||
|
@ -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;
|
||||
|
@ -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';
|
||||
|
@ -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);
|
||||
|
@ -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 = "<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 {
|
||||
@ -536,7 +549,7 @@
|
||||
|
||||
$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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user