MDL-9062: Completed the new form.
This commit is contained in:
+8
-3
@@ -20,6 +20,9 @@ $id = optional_param('id', false, PARAM_INT);
|
||||
$groupingid = optional_param('grouping', false, PARAM_INT);
|
||||
$newgrouping = optional_param('newgrouping', false, PARAM_INT);
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
if ($groupingid === false) {
|
||||
$groupingid = -1;
|
||||
}
|
||||
|
||||
$delete = optional_param('delete', false, PARAM_BOOL);
|
||||
|
||||
@@ -68,11 +71,13 @@ if ($editform->is_cancelled()) {
|
||||
} else {
|
||||
$success = (bool)$id;
|
||||
$data->id = $id;
|
||||
if ($groupingid) {
|
||||
$success = $success && groups_add_group_to_grouping($id, $groupingid);
|
||||
}
|
||||
}
|
||||
} elseif ($groupingid != $newgrouping) { // Moving group to new grouping
|
||||
if ($groupingid != GROUP_NOT_IN_GROUPING) {
|
||||
$success = $success && groups_remove_group_from_grouping($id, $groupingid);
|
||||
}
|
||||
$success = $success && groups_remove_group_from_grouping($id, $groupingid);
|
||||
$success = $success && groups_add_group_to_grouping($id, $newgrouping);
|
||||
} else { // Updating group
|
||||
if (!groups_update_group($data, $course->id)) {
|
||||
print_error('groupnotupdated');
|
||||
|
||||
@@ -54,6 +54,26 @@ class group_edit_form extends moodleform {
|
||||
$buttonstr = get_string('save', 'group');
|
||||
$mform->addElement('hidden','id', null);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
// Options to move group to another grouping
|
||||
$groupingids = groups_get_groupings($courseid);
|
||||
|
||||
// Add pseudo-grouping "Not in a grouping"
|
||||
$groupingids[] = GROUP_NOT_IN_GROUPING;
|
||||
if ($groupingids) {
|
||||
// Put the groupings into a hash and sort them
|
||||
foreach($groupingids as $id) {
|
||||
$listgroupings[$id] = groups_get_grouping_displayname($id, $courseid);
|
||||
}
|
||||
natcasesort($listgroupings);
|
||||
$mform->addElement('select', 'newgrouping', get_string('addgroupstogrouping', 'group'), $listgroupings);
|
||||
$mform->setDefault('newgrouping', $groupingid);
|
||||
}
|
||||
}
|
||||
|
||||
if($groupingid) {
|
||||
$mform->addElement('hidden', 'grouping', $groupingid);
|
||||
$mform->setType('grouping', PARAM_INT);
|
||||
}
|
||||
|
||||
$this->add_action_buttons(true, $buttonstr);
|
||||
|
||||
@@ -397,10 +397,11 @@ function groups_create_grouping($courseid, $groupingsettings = false) {
|
||||
*/
|
||||
function groups_add_group_to_grouping($groupid, $groupingid) {
|
||||
if (GROUP_NOT_IN_GROUPING == $groupingid) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
$belongstogrouping = groups_belongs_to_grouping($groupid, $groupingid);
|
||||
if (!groups_grouping_exists($groupingid)) {
|
||||
|
||||
if (!groups_grouping_exists($groupingid)) {
|
||||
$groupadded = false;
|
||||
} elseif (!$belongstogrouping) {
|
||||
$groupadded = groups_db_add_group_to_grouping($groupid, $groupingid);
|
||||
@@ -489,4 +490,4 @@ function groups_delete_all_groupings($courseid) {
|
||||
return $success;
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user