Skip to content

Commit

Permalink
MDL-81996 block_mentees: consistently ordered list of users.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Dec 17, 2024
1 parent a97ddeb commit 128cac6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions blocks/mentees/block_mentees.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,23 @@ function get_content() {

// get all the mentees, i.e. users you have a direct assignment to
$userfieldsapi = \core_user\fields::for_name();
$allusernames = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, $allusernames
$userfieldssql = $userfieldsapi->get_sql('u', false, '', '', false);

[$usersort] = users_order_by_sql('u', null, $this->context, $userfieldssql->mappings);

if ($users = $DB->get_records_sql("SELECT u.id, $userfieldssql->selects
FROM {role_assignments} ra, {context} c, {user} u
WHERE ra.userid = ?
AND ra.contextid = c.id
AND c.instanceid = u.id
AND c.contextlevel = ".CONTEXT_USER, array($USER->id))) {
AND c.contextlevel = ?
ORDER BY $usersort", [$USER->id, CONTEXT_USER])) {

$this->content->text = '<ul>';
foreach ($usercontexts as $usercontext) {
$this->content->text .= '<li><a href="'.$CFG->wwwroot.'/user/view.php?id='.$usercontext->instanceid.'&amp;course='.SITEID.'">'.fullname($usercontext).'</a></li>';
foreach ($users as $user) {
$userprofileurl = \core_user::get_profile_url($user);
$userfullname = \core_user::get_fullname($user, $this->context);
$this->content->text .= '<li>' . \html_writer::link($userprofileurl, $userfullname) . '</li>';
}
$this->content->text .= '</ul>';
}
Expand Down

0 comments on commit 128cac6

Please sign in to comment.