/** * Cleans up all the groups and groupings in a course (it does this best-effort * i.e. if one deletion fails, it still attempts further deletions). * IMPORTANT: Note that if the groups and groupings are used by other courses * somehow, they will still be deleted - it doesn't protect against this. * @param int $courseid The id of the course * @return boolean True if the clean up was successful, false otherwise. */ function groups_cleanup_groups($courseid) { $success = true; // Delete all the groupings $groupings = groups_get_groupings($courseid); if ($groupings != false) { foreach ($groupings as $groupingid) { $groupingdeleted = groups_delete_grouping($groupingid); if (!$groupingdeleted) { $success = false; } } } // Delete all the groups $groupids = groups_get_groups($courseid); if ($groupids != false) { foreach ($groupids as $groupid) { $groupdeleted = groups_delete_group($groupid); if (!$groupdeleted) { $success = false; } } } return $success; }
/** * Delete all groupings from a course. Groups MUST be deleted first. * TODO: If groups or groupings are to be shared between courses, think again! * @param $courseid The course ID. * @return boolean True if all deletes were successful, false otherwise. */ function groups_delete_all_groupings($courseid) { if (!$courseid) { return false; } $groupingids = groups_get_groupings($courseid); if (!$groupingids) { return true; } $success = true; foreach ($groupingids as $gg_id) { $success = $success && groups_db_delete_grouping($gg_id); } return $success; }
<input type="hidden" name="sesskey" value="<?php p($sesskey) ?>" /> <input type="hidden" name="roleid" value="<?php p($roleid) ?>" /> */ echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">' . "\n"; echo '<tr>' . "\n"; if (empty($CFG->enablegroupings)) { // NO GROUPIGS YET! $sel_groupingid = -1; } else { echo '<td class="generalboxcontent">' . "\n"; echo '<p><label for="groupings">' . get_string('groupings', 'group') . '<span id="dummygrouping"> </span></label></p>' . "\n"; echo '<select name="grouping" id="groupings" size="15" class="select"'; echo ' onchange="groupsCombo.refreshGroups(this.options[this.selectedIndex].value);"'; //NOTE: onclick/onmouseout is for long names in IE6 (Firefox/IE7 display OPTION title). echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">' . "\n"; $groupingids = groups_get_groupings($courseid); if (groups_count_groups_in_grouping(GROUP_NOT_IN_GROUPING, $courseid) > 0) { //NOTE, only show the pseudo-grouping if it has groups. $groupingids[] = GROUP_NOT_IN_GROUPING; } $sel_groupingid = -1; 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); // Print out the HTML $count = 1; foreach ($listgroupings as $id => $name) { $select = '';
function definition() { global $USER, $CFG, $COURSE; $strrequired = get_string('required'); $buttonstr = get_string('creategroup', 'group'); if (isset($this->_customdata['group'])) { $group = $this->_customdata['group']; } else { $group = false; } $groupingid = $this->_customdata['groupingid']; $newgrouping = $this->_customdata['newgrouping']; $courseid = $this->_customdata['courseid']; $mform =& $this->_form; $mform->addElement('text', 'name', get_string('groupname', 'group'), 'maxlength="254" size="50"'); $mform->setDefault('name', get_string('defaultgroupname', 'group')); $mform->addRule('name', get_string('missingname'), 'required', null, 'client'); $mform->setType('name', PARAM_MULTILANG); $mform->addElement('htmleditor', 'description', get_string('groupdescription', 'group'), array('rows' => '15', 'course' => $courseid, 'cols' => '45')); $mform->setType('description', PARAM_RAW); $mform->addElement('text', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey')); $mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true); $mform->setType('enrolmentkey', PARAM_RAW); $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes); if (!empty($CFG->gdversion) and $maxbytes) { $options = array(get_string('no'), get_string('yes')); $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options); $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false)); $mform->addElement('file', 'imagefile', get_string('newpicture', 'group')); $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')), true); } if ($group) { $buttonstr = get_string('save', 'group'); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); if (empty($CFG->enablegroupings)) { // NO GROUPINGS YET! $mform->addElement('hidden', 'newgrouping', GROUP_NOT_IN_GROUPING); $mform->setType('newgrouping', PARAM_INT); } else { // 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); $mform->addElement('hidden', 'courseid', $courseid); }