Skip to content

Commit

Permalink
change participants of frontpage course to display all users, if curr…
Browse files Browse the repository at this point in the history
…ent user has capability MDL-11143
  • Loading branch information
toyomoyo committed Oct 2, 2007
1 parent f476ae2 commit 165088f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 39 deletions.
27 changes: 17 additions & 10 deletions blocks/participants/block_participants.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,29 @@ function get_content() {
if (empty($this->instance->pageid)) {
return '';
}


$this->content = new object();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';

if (!$currentcontext = get_context_instance(CONTEXT_COURSE, $this->instance->pageid)) {
$this->content = '';
return $this->content;
}

if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
$this->content = '';
return $this->content;

if ($this->instance->pageid == SITEID) {
if (!has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
$this->content = '';
return $this->content;
}
} else {
if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
$this->content = '';
return $this->content;
}
}

$this->content = new object();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';

$this->content->items[] = '<a title="'.get_string('listofallpeople').'" href="'.
$CFG->wwwroot.'/user/index.php?contextid='.$currentcontext->id.'">'.get_string('participants').'</a>';
$this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/users.gif" class="icon" alt="" />';
Expand Down
9 changes: 9 additions & 0 deletions lib/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,15 @@
'admin' => CAP_ALLOW
)
),

'moodle/site:viewparticipants' => array(

'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'admin' => CAP_ALLOW
)
),

'moodle/course:viewscales' => array(

Expand Down
88 changes: 61 additions & 27 deletions user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@
require_login($course);

$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);

if (!has_capability('moodle/course:viewparticipants', $context)) {
print_error('nopermissions');
if ($context->id != $frontpagectx->id) {
if (!has_capability('moodle/course:viewparticipants', $context)) {
print_error('nopermissions');
}
} else {
if (!has_capability('moodle/site:viewparticipants', $sitecontext)) {
print_error('nopermissions');
}
}

/// front page course is different
$rolenames = array();
$avoidroles = array();

Expand Down Expand Up @@ -74,8 +82,9 @@
}
}

// no roles to display yet?
if (empty($rolenames)) {
// no roles to display yet?
// frontpage course is an exception, on the front page course we should display all users
if (empty($rolenames) && $context->id != $frontpagectx->id) {
if (has_capability('moodle/role:assign', $context)) {
redirect($CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id);
} else {
Expand Down Expand Up @@ -259,7 +268,6 @@
}
}


/// Define a table showing a list of users in the current role selection

$tablecolumns = array('userpic', 'fullname');
Expand Down Expand Up @@ -321,24 +329,41 @@
} else {
$selectrole = " ";
}
$select = 'SELECT u.id, u.username, u.firstname, u.lastname,

if ($context->id != $frontpagectx->id) {
$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, u.imagealt,
COALESCE(ul.timeaccess, 0) AS lastaccess,
r.hidden,
ctx.id AS ctxid, ctx.path AS ctxpath,
ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';
$select .= $course->enrolperiod?', r.timeend ':'';
} else {
$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, u.imagealt,
u.lastaccess,
ctx.id AS ctxid, ctx.path AS ctxpath,
ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';

}

$select .= $course->enrolperiod?', r.timeend ':'';

$from = "FROM {$CFG->prefix}user u
LEFT OUTER JOIN {$CFG->prefix}context ctx
ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
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) ";

if ($context->id != $frontpagectx->id) {
$from = "FROM {$CFG->prefix}user u
LEFT OUTER JOIN {$CFG->prefix}context ctx
ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
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) ";
} else {
$from = "FROM {$CFG->prefix}user u
LEFT OUTER JOIN {$CFG->prefix}context ctx
ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") ";

}

$hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';

// exclude users with roles we are avoiding
Expand All @@ -353,14 +378,20 @@
// 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'
$adminroles
$hiddensql ";
$where .= get_lastaccess_sql($accesssince);


if ($context->id != $frontpagectx->id) {
$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'
$adminroles
$hiddensql ";
$where .= get_lastaccess_sql($accesssince);
} else {
$where = "WHERE u.deleted = 0
AND u.username != 'guest'";
$where .= get_lastaccess_sql($accesssince);
}
$wheresearch = '';

if (!empty($search)) {
Expand Down Expand Up @@ -611,12 +642,15 @@ function checkchecked(form) {
if (has_capability('moodle/site:readallmessages', $context) && !empty($CFG->messaging)) {
$displaylist['messageselect.php'] = get_string('messageselectadd');
}
if (has_capability('moodle/notes:manage', $context)) {
if (has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) {
$displaylist['addnote.php'] = get_string('addnewnote', 'notes');
$displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
}
$displaylist['extendenrol.php'] = get_string('extendenrol');
$displaylist['groupextendenrol.php'] = get_string('groupextendenrol');

if ($context->id != $frontpagectx->id) {
$displaylist['extendenrol.php'] = get_string('extendenrol');
$displaylist['groupextendenrol.php'] = get_string('groupextendenrol');
}

helpbutton("participantswithselectedusers", get_string("withselectedusers"));
choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "if(checksubmit(this.form))this.form.submit();", "");
Expand Down
2 changes: 1 addition & 1 deletion user/tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
print_heading(format_string($site->fullname));

if ($CFG->bloglevel >= 4) {
if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
if (has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
$toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.SITEID,
get_string('participants'));
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)

$version = 2007092806; // YYYYMMDD = date
$version = 2007092807; // YYYYMMDD = date
// XY = increments within a single day

$release = '1.9 Beta +'; // Human-friendly version name
Expand Down

0 comments on commit 165088f

Please sign in to comment.