mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-10383 - groups/groupings refactoring and improvements - basic UI for groupings implemented
This commit is contained in:
parent
baea72ec48
commit
62d6383803
12 changed files with 454 additions and 196 deletions
207
group/assign.php
207
group/assign.php
|
@ -1,145 +1,108 @@
|
|||
<?php
|
||||
/**
|
||||
* Add/remove members from group.
|
||||
*
|
||||
* @copyright © 2006 The Open University
|
||||
* @author N.D.Freear AT open.ac.uk
|
||||
* @author J.White AT open.ac.uk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* Add/remove group from grouping.
|
||||
* @package groups
|
||||
*/
|
||||
require_once('../config.php');
|
||||
require_once('lib.php');
|
||||
|
||||
define("MAX_USERS_PER_PAGE", 5000);
|
||||
$groupingid = required_param('id', PARAM_INT);
|
||||
|
||||
$groupid = required_param('group', PARAM_INT);
|
||||
$searchtext = optional_param('searchtext', '', PARAM_RAW); // search string
|
||||
$showall = optional_param('showall', 0, PARAM_BOOL);
|
||||
|
||||
if ($showall) {
|
||||
$searchtext = '';
|
||||
}
|
||||
|
||||
|
||||
require_login();
|
||||
if (!$group = get_record('groups', 'id', $groupid)) {
|
||||
if (!$grouping = get_record('groupings', 'id', $groupingid)) {
|
||||
error('Incorrect group id');
|
||||
}
|
||||
|
||||
if (! $course = get_record('course', 'id', $group->courseid)) {
|
||||
if (! $course = get_record('course', 'id', $grouping->courseid)) {
|
||||
print_error('invalidcourse');
|
||||
}
|
||||
|
||||
require_login($course);
|
||||
$courseid = $course->id;
|
||||
|
||||
$strsearch = get_string('search');
|
||||
$strshowall = get_string('showall');
|
||||
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid.'&group='.$groupid;
|
||||
|
||||
require_login($course);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
require_capability('moodle/course:managegroups', $context);
|
||||
|
||||
if ($frm = data_submitted() and confirm_sesskey()) {
|
||||
$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid;
|
||||
|
||||
if (isset($frm->cancel)) {
|
||||
redirect($returnurl);
|
||||
|
||||
} else if (isset($frm->add) and !empty($frm->addselect)) {
|
||||
if ($frm = data_submitted() and confirm_sesskey()) {
|
||||
|
||||
foreach ($frm->addselect as $userid) {
|
||||
if (! $userid = clean_param($userid, PARAM_INT)) {
|
||||
continue;
|
||||
}
|
||||
if (!groups_add_member($groupid, $userid)) {
|
||||
print_error('erroraddremoveuser', 'group', $returnurl);
|
||||
}
|
||||
if (isset($frm->cancel)) {
|
||||
redirect($returnurl);
|
||||
|
||||
} else if (isset($frm->add) and !empty($frm->addselect)) {
|
||||
foreach ($frm->addselect as $groupid) {
|
||||
$groupid = (int)$groupid;
|
||||
if (record_exists('groupings_groups', 'groupingid', $grouping->id, 'groupid', $groupid)) {
|
||||
continue;
|
||||
}
|
||||
$assign = new object();
|
||||
$assign->groupingid = $grouping->id;
|
||||
$assign->groupid = $groupid;
|
||||
$assign->timeadded = time();
|
||||
insert_record('groupings_groups', $assign);
|
||||
}
|
||||
|
||||
} else if (isset($frm->remove) and !empty($frm->removeselect)) {
|
||||
} else if (isset($frm->remove) and !empty($frm->removeselect)) {
|
||||
|
||||
foreach ($frm->removeselect as $userid) {
|
||||
if (! $userid = clean_param($userid, PARAM_INT)) {
|
||||
continue;
|
||||
}
|
||||
if (!groups_remove_member($groupid, $userid)) {
|
||||
print_error('erroraddremoveuser', 'group', $returnurl);
|
||||
}
|
||||
|
||||
// MDL-9983
|
||||
$eventdata = new object();
|
||||
$eventdata -> groupid = $groupid;
|
||||
$eventdata -> userid = $userid;
|
||||
events_trigger('group_user_removed', $eventdata);
|
||||
}
|
||||
foreach ($frm->removeselect as $groupid) {
|
||||
$groupid = (int)$groupid;
|
||||
delete_records('groupings_groups', 'groupingid', $grouping->id, 'groupid', $groupid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$groupmembers = groups_get_members($groupid);
|
||||
$groupmembersoptions = '';
|
||||
$groupmemberscount = 0;
|
||||
if ($groupmembers != false) {
|
||||
// Put the groupings into a hash and sorts them
|
||||
foreach ($groupmembers as $userid) {
|
||||
$listmembers[$userid] = groups_get_user_displayname($userid, $courseid);
|
||||
$groupmemberscount ++;
|
||||
}
|
||||
natcasesort($listmembers);
|
||||
|
||||
// Print out the HTML
|
||||
foreach($listmembers as $id => $name) {
|
||||
$groupmembersoptions .= "<option value=\"$id\">$name</option>\n";
|
||||
}
|
||||
} else {
|
||||
$groupmembersoptions .= '<option> </option>';
|
||||
}
|
||||
$currentmembers = array();
|
||||
$potentialmembers = array();
|
||||
|
||||
$potentialmembers = array();
|
||||
$potentialmembersoptions = '';
|
||||
$potentialmemberscount = 0;
|
||||
|
||||
$potentialmembers = groups_get_users_not_in_group($courseid, $groupid, $searchtext);
|
||||
if (!empty($potentialmembers)) {
|
||||
$potentialmemberscount = count($potentialmembers);
|
||||
} else {
|
||||
$potentialmemberscount = 0;
|
||||
}
|
||||
if ($potentialmemberscount <= MAX_USERS_PER_PAGE) {
|
||||
|
||||
if ($potentialmembers != false) {
|
||||
// Put the groupings into a hash and sorts them
|
||||
foreach ($potentialmembers as $userid => $user) {
|
||||
$nonmembers[$userid] = fullname($user);
|
||||
//$nonmembers[$userid] = groups_get_user_displayname($userid, $courseid);
|
||||
}
|
||||
natcasesort($nonmembers);
|
||||
|
||||
// Print out the HTML
|
||||
foreach($nonmembers as $id => $name) {
|
||||
$potentialmembersoptions .= "<option value=\"$id\">$name</option>\n";
|
||||
}
|
||||
} else {
|
||||
$potentialmembersoptions .= '<option> </option>';
|
||||
if ($groups = get_records('groups', 'courseid', $courseid, 'name')) {
|
||||
if ($assignment = get_records('groupings_groups', 'groupingid', $grouping->id)) {
|
||||
foreach ($assignment as $ass) {
|
||||
$currentmembers[$ass->groupid] = $groups[$ass->groupid];
|
||||
unset($groups[$ass->groupid]);
|
||||
}
|
||||
}
|
||||
$potentialmembers = $groups;
|
||||
}
|
||||
|
||||
// Print the page and form
|
||||
$strgroups = get_string('groups');
|
||||
$strparticipants = get_string('participants');
|
||||
$currentmembersoptions = '';
|
||||
$currentmemberscount = 0;
|
||||
if ($currentmembers) {
|
||||
foreach($currentmembers as $group) {
|
||||
$currentmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
|
||||
$currentmemberscount ++;
|
||||
}
|
||||
} else {
|
||||
$currentmembersoptions .= '<option> </option>';
|
||||
}
|
||||
|
||||
$groupname = groups_get_group_displayname($groupid);
|
||||
$potentialmembersoptions = '';
|
||||
$potentialmemberscount = 0;
|
||||
if ($potentialmembers) {
|
||||
foreach($potentialmembers as $group) {
|
||||
$potentialmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
|
||||
$potentialmemberscount ++;
|
||||
}
|
||||
} else {
|
||||
$potentialmembersoptions .= '<option> </option>';
|
||||
}
|
||||
|
||||
print_header("$course->shortname: $strgroups",
|
||||
$course->fullname,
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
|
||||
"-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
|
||||
"-> <a href=\"$CFG->wwwroot/group/index.php?id=$courseid\">$strgroups</a>".
|
||||
'-> '. get_string('adduserstogroup', 'group'), '', '', true, '', user_login_string($course, $USER));
|
||||
// Print the page and form
|
||||
$strgroups = get_string('groups');
|
||||
$strparticipants = get_string('participants');
|
||||
|
||||
$groupingname = format_string($grouping->name);
|
||||
|
||||
print_header("$course->shortname: $strgroups",
|
||||
$course->fullname,
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
|
||||
"-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
|
||||
"-> <a href=\"$CFG->wwwroot/group/index.php?id=$courseid\">$strgroups</a>".
|
||||
'-> '. get_string('addgroupstogroupings', 'group'), '', '', true, '', user_login_string($course, $USER));
|
||||
|
||||
?>
|
||||
<div id="addmembersform">
|
||||
<h3 class="main"><?php print_string('adduserstogroup', 'group'); echo " $groupname"; ?></h3>
|
||||
<h3 class="main"><?php print_string('addgroupstogroupings', 'group'); echo ": $groupingname"; ?></h3>
|
||||
|
||||
<form id="assignform" method="post" action="">
|
||||
<div>
|
||||
|
@ -149,13 +112,13 @@ require_capability('moodle/course:managegroups', $context);
|
|||
<table summary="" cellpadding="5" cellspacing="0">
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<label for="removeselect"><?php print_string('existingmembers', 'group', $groupmemberscount); //count($contextusers) ?></label>
|
||||
<label for="removeselect"><?php print_string('existingmembers', 'group', $currentmemberscount); //count($contextusers) ?></label>
|
||||
<br />
|
||||
<select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
|
||||
onfocus="document.getElementById('assignform').add.disabled=true;
|
||||
document.getElementById('assignform').remove.disabled=false;
|
||||
document.getElementById('assignform').addselect.selectedIndex=-1;">
|
||||
<?php echo $groupmembersoptions ?>
|
||||
<?php echo $currentmembersoptions ?>
|
||||
</select></td>
|
||||
<td valign="top">
|
||||
<?php // Hidden assignment? ?>
|
||||
|
@ -174,37 +137,13 @@ require_capability('moodle/course:managegroups', $context);
|
|||
onfocus="document.getElementById('assignform').add.disabled=false;
|
||||
document.getElementById('assignform').remove.disabled=true;
|
||||
document.getElementById('assignform').removeselect.selectedIndex=-1;">
|
||||
<?php
|
||||
if ($potentialmemberscount > MAX_USERS_PER_PAGE) {
|
||||
echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
|
||||
.'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
|
||||
} else {
|
||||
echo $potentialmembersoptions;
|
||||
}
|
||||
?>
|
||||
<?php echo $potentialmembersoptions ?>
|
||||
</select>
|
||||
<br />
|
||||
<label for="searchtext" class="accesshide"><?php p($strsearch) ?></label>
|
||||
<input type="text" name="searchtext" id="searchtext" size="30" value="<?php p($searchtext, true) ?>"
|
||||
onfocus ="getElementById('assignform').add.disabled=true;
|
||||
getElementById('assignform').remove.disabled=true;
|
||||
getElementById('assignform').removeselect.selectedIndex=-1;
|
||||
getElementById('assignform').addselect.selectedIndex=-1;"
|
||||
onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
|
||||
if (keyCode == 13) {
|
||||
getElementById('assignform').previoussearch.value=1;
|
||||
getElementById('assignform').submit();
|
||||
} " />
|
||||
<input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
|
||||
<?php
|
||||
if (!empty($searchtext)) {
|
||||
echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td>
|
||||
<input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
|
||||
<input type="submit" name="cancel" value="<?php print_string('backtogroupings', 'group'); ?>" />
|
||||
</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -213,4 +152,6 @@ require_capability('moodle/course:managegroups', $context);
|
|||
|
||||
<?php
|
||||
print_footer($course);
|
||||
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue