function test_add_group_to_grouping() { $this->assertTrue(groups_add_group_to_grouping($this->groupid, $this->groupingid)); $this->assertTrue(groups_belongs_to_grouping($this->groupid, $this->groupingid)); $this->assertTrue($groupings = groups_get_groupings_for_group($this->groupid)); //array... $this->assertTrue($groups = groups_get_groups_in_grouping($this->groupingid)); //... }
require_js('yui_yahoo'); require_js('yui_dom'); require_js('yui_connection'); require_js($CFG->wwwroot . '/group/lib/clientlib.js'); $success = true; $courseid = required_param('id', PARAM_INT); $groupingid = optional_param('grouping', GROUP_NOT_IN_GROUPING, PARAM_INT); $groupid = optional_param('group', false, PARAM_INT); $userid = optional_param('user', false, PARAM_INT); $action = groups_param_action(); if (empty($CFG->enablegroupings)) { // NO GROUPINGS YET! $groupingid = GROUP_NOT_IN_GROUPING; } if ($groupid) { $groupingsforgroup = groups_get_groupings_for_group($groupid); if ($groupingsforgroup) { // NOTE // We currently assume that a group can only belong to one grouping. // FIXME // The UI will have to be fixed if we want to support more than one // groupings per group in the future. // // vy-shane AT moodle DOT com $groupingid = array_shift($groupingsforgroup); } } // Get the course information so we can print the header and // check the course id is valid $course = groups_get_course_info($courseid); if (!$course) {
/// Course must be valid if (!($course = get_record('course', 'id', $courseid))) { error('Course ID was incorrect'); } $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:managegroups', $context); $group = false; if ($id) { if (!($group = get_record('groups', 'id', $id))) { error('Group ID was incorrect'); } $group->description = clean_text($group->description); if (!groups_group_belongs_to_course($group->id, $course->id)) { error('Group not from this course.'); } $groupings = groups_get_groupings_for_group($id); if (empty($groupings)) { $groupingid = -1; } else { if (!isset($groupings[$groupingid])) { $groupingid = $groupings[0]; } } } if ($groupingid != GROUP_NOT_IN_GROUPING and !groups_db_grouping_belongs_to_course($groupingid, $course->id)) { error('Grouping not from this course.'); } if ($newgrouping != GROUP_NOT_IN_GROUPING and !groups_db_grouping_belongs_to_course($newgrouping, $course->id)) { error('Grouping not from this course.'); } // Process delete action
/** * Delete a specified group, first removing members and links with courses and groupings. * @param int $groupid The group to delete * @return boolean True if deletion was successful, false otherwise */ function groups_db_delete_group($groupid) { if (!$groupid) { $success = false; } else { $success = true; // Get a list of users for the group and remove them all. $userids = groups_db_get_members($groupid); if ($userids != false) { foreach ($userids as $userid) { $userdeleted = groups_db_remove_member($userid, $groupid); if (!$userdeleted) { $success = false; } } } // Remove any links with groupings to which the group belongs. //TODO: dbgroupinglib also seems to delete these links - duplication? $groupingids = groups_get_groupings_for_group($groupid); if ($groupingids != false) { foreach ($groupingids as $groupingid) { $groupremoved = groups_remove_group_from_grouping($groupid, $groupingid); if (!$groupremoved) { $success = false; } } } // Remove links with courses. $results = delete_records('groups_courses_groups', 'groupid', $groupid); if ($results == false) { $success = false; } // Delete the group itself $results = delete_records($table = 'groups', $field1 = 'id', $value1 = $groupid); // delete_records returns an array of the results from the sql call, // not a boolean, so we have to set our return variable if ($results == false) { $success = false; } } return $success; }