/**
- * Deletes a specified group
+ * 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
*/
$success = false;
} else {
$success = true;
- // Get a list of the users for the group and delete them all from the
- // group
+ // Get a list of users for the group and remove them all.
$userids = groups_db_get_members($groupid);
if ($userids != false) {
}
}
- // Remove any groupings that the group belongs to
+ // 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) {
}
}
+ // Remove links with courses.
$results = delete_records('groups_courses_groups', 'groupid', $groupid);
if ($results == false) {
$success = false;
}
/**
- * Return member records, for backup.
+ * Get the user ID and time added for each member of a group, for backup4.
+ * @return array An array of member records.
*/
function groups_get_member_records($groupid) {
if (!$groupid) {
return $groupids;
}
+/**
+ * Get the groups to which a user belongs in any course on site.
+ * @return array | false An array of the group IDs, or false on error.
+ */
function groups_get_all_groups_for_user($userid) {
$groups = get_records('groups_members', 'userid', $userid);
if (! $groups) {
} else {
$useradded = groups_db_add_member($member->groupid, $member->userid, $member->timeadded);
}
- return true;
+ return $useradded;
}
/**
- * Deletes a group best effort
+ * Delete a group best effort, 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
* See comment above on web service autoupdating.
return $groupdeleted;
}
-/*function groups_delete_groups($groupids) {
- if (! $groupids) {
- return false;
- }
- $success = true;
- foreach ($groupids as $id) {
- $success = $success && groups_db_delete_group($id);
- }
- return $success;
-}*/
-
/**
- * Deletes the specified user from the specified group
+ * Deletes the link between the specified user and group.
* @param int $groupid The group to delete the user from
* @param int $userid The user to delete
* @return boolean True if deletion was successful, false otherwise
return $success;
}
+/**
+ * Removes all users from the specified group.
+ * @param int $groupid The ID of the group.
+ * @return boolean True for success, false otherwise.
+ */
function groups_remove_all_members($groupid) {
if (! groups_group_exists($groupid)) {
//Woops, delete group last!
return $success;
}
-
?>
\ No newline at end of file
function groups_get_grouping_records($courseid) {
- /*$groupingids = groups_db_get_groupings($courseid);
- if (! $groupingids) {
- return false;
- }
- $groupings = groups_groupingids_to_groupings($groupingids);
-*/
global $CFG;
if (! $courseid) {
return false;
}
/**
- * Gets a list of the groups in a specified grouping
+ * Gets a list of the group IDs in a specified grouping
* @param int $groupingid The id of the grouping
* @return array | false. An array of the ids of the groups, or false if there
* are none or an error occurred.
return groups_db_get_groups_in_grouping($groupingid);
}
+/**
+ * Gets complete group-data for each group in a grouping.
+ * @param int $groupingid The ID of the grouping.
+ * @return array | false An array of group records, or false on error.
+ */
function groups_get_groups_in_grouping_records($groupingid) {
if (! $groupingid) {
return false;
*/
function groups_get_groups_not_in_any_grouping($courseid) {
global $CFG;
-/*Was: $sql = "SELECT g.id FROM {$CFG->prefix}groups AS g
- WHERE g.id NOT IN
- (SELECT groupid FROM {$CFG->prefix}groups_groupings_groups)";
-*/
+
$join = '';
$where= '';
if ($courseid) {
$records = get_records_sql($sql);
$groupids = groups_groups_to_groupids($records, $courseid);
- /*$groupids = array();
- if ($records) {
- foreach ($records as $r) {
- $groupids[] = $r->id;
- }
- } else {
- return false;
- }*/
+
return $groupids;
}
*****************************/
/**
- * Removes a specified group from a specified grouping. Note that this does
+ * Removes a specified group from a grouping. Note that this does
* not delete the group.
* @param int $groupid The id of the group.
* @param int $groupingid The id of the grouping
}
+/**
+ * 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;
+}
+
?>
\ No newline at end of file
}
}
-/// Delete any groups, removing members first. TODO: check.
+/// Delete any groups, removing members and grouping/course links first.
+ //TODO: If groups or groupings are to be shared between courses, think again!
if ($groupids = groups_get_groups($course->id)) {
foreach ($groupids as $groupid) {
- if (groups_remove_all_group_members($groupid)) {
+ if (groups_remove_all_members($groupid)) {
if ($showfeedback) {
notify($strdeleted .' groups_members');
}
$result = false;
}
/// Delete any associated context for this group ??
- delete_context(CONTEXT_GROUP, $group->id);
+ delete_context(CONTEXT_GROUP, $groupid);
if (groups_delete_group($groupid)) {
if ($showfeedback) {
}
}
}
+/// Delete any groupings.
+ $result = groups_delete_all_groupings($course->id);
+ if ($result && $showfeedback) {
+ notify($strdeleted .' groupings');
+ }
/// Delete all related records in other tables that may have a courseid
/// This array stores the tables that need to be cleared, as