mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
groups MDL-24262 Tidied up inline script from group selector
This commit is contained in:
parent
d484419c61
commit
0b3f854736
@ -201,27 +201,35 @@ var removeLoaderImgs = function (elClass, parentId) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the current groups information shown about a user when a user is selected.
|
||||
*
|
||||
* @global {Array} userSummaries
|
||||
* userSummaries is added to the page via /user/selector/lib.php - group_non_members_selector::print_user_summaries()
|
||||
* as a global that can be used by this function.
|
||||
*/
|
||||
function updateUserSummary() {
|
||||
var selectEl = document.getElementById('addselect');
|
||||
var summaryDiv = document.getElementById('group-usersummary');
|
||||
var length = selectEl.length;
|
||||
var selectCnt = 0;
|
||||
var selectIdx = -1;
|
||||
var selectEl = document.getElementById('addselect'),
|
||||
summaryDiv = document.getElementById('group-usersummary'),
|
||||
length = selectEl.length,
|
||||
selectCnt = 0,
|
||||
selectIdx = -1,
|
||||
i;
|
||||
|
||||
for(i=0;i<length;i++) {
|
||||
if (selectEl.options[i].selected) {
|
||||
selectCnt++;
|
||||
selectIdx = i;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
if (selectEl.options[i].selected) {
|
||||
selectCnt++;
|
||||
selectIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectCnt == 1 && userSummaries[selectIdx]) {
|
||||
summaryDiv.innerHTML = userSummaries[selectIdx];
|
||||
} else {
|
||||
summaryDiv.innerHTML = '';
|
||||
}
|
||||
if (selectCnt == 1 && userSummaries[selectIdx]) {
|
||||
summaryDiv.innerHTML = userSummaries[selectIdx];
|
||||
} else {
|
||||
summaryDiv.innerHTML = '';
|
||||
}
|
||||
|
||||
return(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
function init_add_remove_members_page(Y) {
|
||||
|
@ -738,27 +738,30 @@ class group_non_members_selector extends groups_user_selector_base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a Javascript array containing the other groups non-members are in.
|
||||
* Used on the add group members page.
|
||||
* 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;
|
||||
global $DB, $PAGE;
|
||||
|
||||
echo <<<END
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
var userSummaries = Array(
|
||||
END;
|
||||
$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, 'pm0');
|
||||
$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 ";
|
||||
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;
|
||||
if ($rs = $DB->get_recordset_sql($sql, $params)) {
|
||||
foreach ($rs as $usergroup) {
|
||||
@ -767,32 +770,21 @@ END;
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
$membercnt = count($potentialmembersids);
|
||||
$i=1;
|
||||
foreach ($potentialmembersids as $userid) {
|
||||
if (isset($usergroups[$userid])) {
|
||||
$usergrouplist = '<ul>';
|
||||
|
||||
foreach ($usergroups[$userid] as $groupitem) {
|
||||
$usergrouplist .= '<li>'.addslashes_js(format_string($groupitem->name)).'</li>';
|
||||
}
|
||||
$usergrouplist .= '</ul>';
|
||||
}
|
||||
else {
|
||||
$usergrouplist = '';
|
||||
}
|
||||
echo "'$usergrouplist'";
|
||||
if ($i < $membercnt) {
|
||||
echo ', ';
|
||||
}
|
||||
$i++;
|
||||
if (isset($usergroups[$userid])) {
|
||||
$usergrouplist = html_writer::start_tag('ul');
|
||||
foreach ($usergroups[$userid] as $groupitem) {
|
||||
$usergrouplist .= html_writer::tag('li', format_string($groupitem->name));
|
||||
}
|
||||
$usergrouplist .= html_writer::end_tag('ul');
|
||||
} else {
|
||||
$usergrouplist = '';
|
||||
}
|
||||
$usersummaries[] = $usergrouplist;
|
||||
}
|
||||
}
|
||||
echo <<<END
|
||||
);
|
||||
//]]>
|
||||
</script>
|
||||
END;
|
||||
|
||||
$PAGE->requires->data_for_js('userSummaries', $usersummaries);
|
||||
}
|
||||
|
||||
public function find_users($search) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user