Skip to content

Instantly share code, notes, and snippets.

@tranepura
Created May 31, 2015 11:58
Show Gist options
  • Select an option

  • Save tranepura/7fec0a61f3682d8f3e9c to your computer and use it in GitHub Desktop.

Select an option

Save tranepura/7fec0a61f3682d8f3e9c to your computer and use it in GitHub Desktop.
Fix for MDL -29774 Fix
/**
* Creates a global JS variable (userSummaries) that is used by the group selector
* to print related information when the user clicks on a user in the groups UI.
*
* Used by /group/clientlib.js
*
* @global moodle_database $DB
* @global moodle_page $PAGE
* @param int $courseid
*/
public function print_user_summaries($courseid) {
global $DB, $PAGE;
$usersummaries = array();
// Get other groups user already belongs to.
$usergroups = array();
$potentialmembersids = $this->potentialmembersids;
if (empty($potentialmembersids) == false) {
list($membersidsclause, $params) = $DB->get_in_or_equal($potentialmembersids, SQL_PARAMS_NAMED, 'pm');
$sql = "SELECT u.id AS userid, g.*
FROM {user} u
JOIN {groups_members} gm ON u.id = gm.userid
JOIN {groups} g ON gm.groupid = g.id
WHERE u.id $membersidsclause AND g.courseid = :courseid ";
$params['courseid'] = $courseid;
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $usergroup) {
$usergroups[$usergroup->userid][$usergroup->id] = $usergroup;
}
$rs->close();
foreach ($potentialmembersids as $userid) {
if (isset($usergroups[$userid])) {
$usergrouplist = html_writer::start_tag('ul');
foreach ($usergroups[$userid] as $groupitem) {
$usergrouplist .= html_writer::tag('li', format_string($groupitem->name),array('value'=>$userid));
}
$usergrouplist .= html_writer::end_tag('ul');
} else {
$usergrouplist = '';
}
$usersummaries[$userid] = $usergrouplist;
}
}
$PAGE->requires->data_for_js('userSummaries', $usersummaries);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment