Skip to content

Commit

Permalink
making hidden assignment work with multiple roles
Browse files Browse the repository at this point in the history
  • Loading branch information
toyomoyo committed Nov 16, 2006
1 parent 73d402e commit b06334e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
17 changes: 7 additions & 10 deletions course/lib.php
Expand Up @@ -1547,22 +1547,19 @@ function print_course($course, $width="100%") {
echo '<td valign="top" width="50%" class="info">';
echo '<b><a title="'.get_string('entercourse').'"'.
$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
$course->fullname.'</a></b><br />';

$course->fullname.'</a></b><br />';
if ($teachers = get_users_by_capability($context, 'moodle/course:update',
'u.*, ul.timeaccess as lastaccess, ra.hidden',
'r.sortorder ASC', '','','','', false)) {

$canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
'u.*, ul.timeaccess as lastaccess',
'r.sortorder ASC', '','','','', false, true)) {
$namesarray = array();
foreach ($teachers as $teacher) {
if (!$teacher->hidden || $canseehidden) {
$roles = get_user_roles($context, $teacher->id, true, 'r.sortorder ASC');
if ($roles = get_user_roles($context, $teacher->id, true, 'r.sortorder ASC', true)) {
$role = array_shift($roles); // First one
$fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
$namesarray[] = format_string($role->name).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
$teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
}
$teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
}
}
if ($namesarray) {
echo "<ul class=\"teachers\">\n<li>";
Expand Down
25 changes: 20 additions & 5 deletions lib/accesslib.php
Expand Up @@ -2870,9 +2870,14 @@ function get_all_roles() {
* allow_override tables
* @param object $context
* @param int $userid
* @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_user_roles($context, $userid=0, $checkparentcontexts=true, $order='c.contextlevel DESC, r.sortorder ASC') {
function get_user_roles($context, $userid=0, $checkparentcontexts=true, $order='c.contextlevel DESC, r.sortorder ASC', $view=false) {

global $USER, $CFG, $db;

Expand All @@ -2882,6 +2887,8 @@ function get_user_roles($context, $userid=0, $checkparentcontexts=true, $order='
}
$userid = $USER->id;
}
// set up hidden sql
$hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 ';

if ($checkparentcontexts && ($parents = get_parent_contexts($context))) {
$contexts = ' ra.contextid IN ('.implode(',' , $parents).','.$context->id.')';
Expand All @@ -2896,7 +2903,7 @@ function get_user_roles($context, $userid=0, $checkparentcontexts=true, $order='
WHERE ra.userid = '.$userid.
' AND ra.roleid = r.id
AND ra.contextid = c.id
AND '.$contexts.
AND '.$contexts . $hiddensql .
' ORDER BY '.$order);
}

Expand Down Expand Up @@ -3012,9 +3019,14 @@ function get_default_course_role($course) {
* @param $limitnum - number of records to fetch
* @param $groups - single group or array of groups - group(s) user is in
* @param $exceptions - list of users to exclude
* @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.
*/
function get_users_by_capability($context, $capability, $fields='', $sort='',
$limitfrom='', $limitnum='', $groups='', $exceptions='', $doanything=true) {
$limitfrom='', $limitnum='', $groups='', $exceptions='', $doanything=true, $view=false) {
global $CFG;

/// Sorting out groups
Expand Down Expand Up @@ -3045,6 +3057,8 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
}

$sortby = $sort ? " ORDER BY $sort " : '';
/// Set up hidden sql
$hiddensql = ($view && has_capability('moodle/role:viewhiddenassigns', $context))? '':' AND ra.hidden = 0 ';

/// If context is a course, then construct sql for ul
if ($context->contextlevel == CONTEXT_COURSE) {
Expand Down Expand Up @@ -3095,8 +3109,9 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
AND u.deleted = 0
AND ra.roleid in $roleids
$exceptionsql
$groupsql";

$groupsql
$hiddensql";

return get_records_sql($select.$from.$where.$sortby, $limitfrom, $limitnum);
}

Expand Down

0 comments on commit b06334e

Please sign in to comment.