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.'&course='.SITEID.'">'.$fullname.'</a>';
- }
+ $teacher->id.'&course='.SITEID.'">'.$fullname.'</a>';
+ }
}
if ($namesarray) {
echo "<ul class=\"teachers\">\n<li>";
* 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;
}
$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.')';
WHERE ra.userid = '.$userid.
' AND ra.roleid = r.id
AND ra.contextid = c.id
- AND '.$contexts.
+ AND '.$contexts . $hiddensql .
' ORDER BY '.$order);
}
* @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
}
$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) {
AND u.deleted = 0
AND ra.roleid in $roleids
$exceptionsql
- $groupsql";
-
+ $groupsql
+ $hiddensql";
+
return get_records_sql($select.$from.$where.$sortby, $limitfrom, $limitnum);
}