mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-29902: Course contacts display cleanup
This fixes warnings in course description when searching courses with users assigned multiple display roles. It cleans up inconsistent behaviour which I noticed whilst fixing the bug. Now course search and course listing use the same logic to display users.
This commit is contained in:
parent
3a81b37617
commit
e52a8ebdd2
@ -2454,61 +2454,48 @@ function print_course($course, $highlightterms = '') {
|
||||
if (!empty($CFG->coursecontact)) {
|
||||
$managerroles = explode(',', $CFG->coursecontact);
|
||||
$namesarray = array();
|
||||
if (isset($course->managers)) {
|
||||
if (count($course->managers)) {
|
||||
$rusers = $course->managers;
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
$rusers = array();
|
||||
|
||||
/// Rename some of the role names if needed
|
||||
if (isset($context)) {
|
||||
$aliasnames = $DB->get_records('role_names', array('contextid'=>$context->id), '', 'roleid,contextid,name');
|
||||
}
|
||||
|
||||
// keep a note of users displayed to eliminate duplicates
|
||||
$usersshown = array();
|
||||
foreach ($rusers as $ra) {
|
||||
|
||||
// if we've already displayed user don't again
|
||||
if (in_array($ra->user->id,$usersshown)) {
|
||||
continue;
|
||||
}
|
||||
$usersshown[] = $ra->user->id;
|
||||
|
||||
$fullname = fullname($ra->user, $canviewfullnames);
|
||||
|
||||
if (isset($aliasnames[$ra->roleid])) {
|
||||
$ra->rolename = $aliasnames[$ra->roleid]->name;
|
||||
}
|
||||
|
||||
$namesarray[] = format_string($ra->rolename).': '.
|
||||
html_writer::link(new moodle_url('/user/view.php', array('id'=>$ra->user->id, 'course'=>SITEID)), $fullname);
|
||||
}
|
||||
}
|
||||
if (!isset($course->managers)) {
|
||||
$rusers = get_role_users($managerroles, $context, true,
|
||||
'ra.id AS raid, u.id, u.username, u.firstname, u.lastname,
|
||||
r.name AS rolename, r.sortorder, r.id AS roleid',
|
||||
'r.sortorder ASC, u.lastname ASC');
|
||||
} else {
|
||||
$rusers = get_role_users($managerroles, $context,
|
||||
true, '', 'r.sortorder ASC, u.lastname ASC');
|
||||
if (is_array($rusers) && count($rusers)) {
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
// use the managers array if we have it for perf reasosn
|
||||
// populate the datastructure like output of get_role_users();
|
||||
foreach ($course->managers as $manager) {
|
||||
$u = new stdClass();
|
||||
$u = $manager->user;
|
||||
$u->roleid = $manager->roleid;
|
||||
$u->rolename = $manager->rolename;
|
||||
|
||||
/// Rename some of the role names if needed
|
||||
if (isset($context)) {
|
||||
$aliasnames = $DB->get_records('role_names', array('contextid'=>$context->id), '', 'roleid,contextid,name');
|
||||
}
|
||||
|
||||
foreach ($rusers as $teacher) {
|
||||
$fullname = fullname($teacher, $canviewfullnames);
|
||||
|
||||
/// Apply role names
|
||||
if (isset($aliasnames[$teacher->roleid])) {
|
||||
$teacher->rolename = $aliasnames[$teacher->roleid]->name;
|
||||
}
|
||||
|
||||
$namesarray[] = format_string($teacher->rolename).': '.
|
||||
html_writer::link(new moodle_url('/user/view.php', array('id'=>$teacher->id, 'course'=>SITEID)), $fullname);
|
||||
}
|
||||
$rusers[] = $u;
|
||||
}
|
||||
}
|
||||
|
||||
/// Rename some of the role names if needed
|
||||
if (isset($context)) {
|
||||
$aliasnames = $DB->get_records('role_names', array('contextid'=>$context->id), '', 'roleid,contextid,name');
|
||||
}
|
||||
|
||||
$namesarray = array();
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
foreach ($rusers as $ra) {
|
||||
if (isset($namesarray[$ra->id])) {
|
||||
// only display a user once with the higest sortorder role
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($aliasnames[$ra->roleid])) {
|
||||
$ra->rolename = $aliasnames[$ra->roleid]->name;
|
||||
}
|
||||
|
||||
$fullname = fullname($ra, $canviewfullnames);
|
||||
$namesarray[$ra->id] = format_string($ra->rolename).': '.
|
||||
html_writer::link(new moodle_url('/user/view.php', array('id'=>$ra->id, 'course'=>SITEID)), $fullname);
|
||||
}
|
||||
|
||||
if (!empty($namesarray)) {
|
||||
echo html_writer::start_tag('ul', array('class'=>'teachers'));
|
||||
foreach ($namesarray as $name) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user