/** * Returns the ids of the users in the specified group. * @param int $groupid The groupid to get the users for * @param string $membertype Either 'student', 'teacher' or false. The function * only returns these * types of group members. If set to false, returns all group members. * @return array | false Returns an array of the user ids for the specified * group or false if no users or an error returned. */ function groups_get_members($groupid, $membertype = false) { $userids = groups_db_get_members($groupid); return $userids; }
/** * 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; }