Пример #1
0
/**
 * 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 false;
    }
    $userids = groups_get_members($groupid);
    if (!$userids) {
        return false;
    }
    $success = true;
    foreach ($userids as $id) {
        $success = $success && groups_db_remove_member($groupid, $id);
    }
    $success = $success && groups_db_set_group_modified($groupid);
    return $success;
}
Пример #2
0
/** 
 * 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;
}