예제 #1
0
function au_subgroups_delete_group($hook, $type, $return, $params)
{
    $guid = get_input('guid');
    if (!$guid) {
        $guid = get_input('group_guid');
    }
    $group = get_entity($guid);
    if (elgg_instanceof($group, 'group')) {
        // determine if the group has any child groups
        $child = au_subgroups_get_subgroups($group, 1);
        $parent = au_subgroups_get_parent_group($group);
        if ($child || $parent) {
            // here we are, we're deleting something with subgroups or a parent
            // if we've already sorted out what happens to content
            // we'll have a special input
            $content_policy = get_input('au_subgroups_content_policy', false);
            if (!$content_policy) {
                forward(elgg_get_site_url() . "groups/subgroups/delete/{$group->guid}");
            }
            // this is the top level to delete, so if transferring content to parent, it's the parent of this
            // apply content policy recursively, then delete all subgroups recursively
            // this could take a while...
            set_time_limit(0);
            $guids = au_subgroups_get_all_children_guids($group);
            if (is_array($guids) && count($guids)) {
                if ($content_policy != 'delete' && is_array($guids) && count($guids)) {
                    $options = array('container_guids' => $guids, 'au_subgroups_content_policy' => $content_policy, 'au_subgroups_parent_guid' => $parent->guid, 'limit' => 0);
                    $batch = new ElggBatch('elgg_get_entities', $options, 'au_subgroups_move_content', 25);
                }
                // now delete the groups themselves
                $options = array('guids' => $guids, 'types' => array('group'), 'limit' => 0);
                $batch = new ElggBatch('elgg_get_entities', $options, 'au_subgroups_delete_entities', 25, false);
            }
        }
    }
}
예제 #2
0
/**
 * Determines if a subgroup could potentially be moved
 * To a parent group
 * Makes sure permissions are in order, and that the subgroup isn't already a parent
 * of the parent or anything weird like that
 * 
 * @param type $user ElggUser
 * @param type $subgroup_guid
 * @param type $parentgroup_guid
 */
function au_subgroups_can_move_subgroup($subgroup, $parent, $user = NULL)
{
    if (!elgg_instanceof($user, 'user')) {
        $user = elgg_get_logged_in_user_entity();
    }
    if (!$user) {
        return false;
    }
    // make sure they're really groups
    if (!elgg_instanceof($subgroup, 'group') || !elgg_instanceof($parent, 'group')) {
        return false;
    }
    // make sure we can edit them
    if (!$subgroup->canEdit($user->guid) || !$parent->canEdit($user->guid)) {
        return false;
    }
    // make sure we can edit all the way up, and we're not trying to move a group into itself
    if (!au_subgroups_can_edit_recursive($subgroup) || $subgroup->guid == $parent->guid) {
        return false;
    }
    // make sure we're not moving a group into it's existing parent
    $current_parent = au_subgroups_get_parent_group($subgroup);
    if ($current_parent && $current_parent->guid == $parent->guid) {
        return false;
    }
    // also make sure the potential parent isn't a subgroup of the subgroup
    $children = au_subgroups_get_all_children_guids($subgroup);
    if (in_array($parent->guid, $children)) {
        return false;
    }
    return true;
}
예제 #3
0
파일: events.php 프로젝트: lorea/Hydra-dev
/**
 * When leaving a group, make sure users are removed from any subgroups
 * 
 * @param type $event
 * @param type $type
 * @param type $object
 */
function au_subgroups_leave_group($event, $type, $params)
{
    $guids = au_subgroups_get_all_children_guids($params['group']);
    foreach ($guids as $guid) {
        leave_group($guid, $params['user']->guid);
    }
}
예제 #4
0
파일: move.php 프로젝트: lorea/Hydra-dev
<?php

$subgroup_guid = get_input('subgroup_guid');
$parent_guid = get_input('parent_guid');
if ($parent_guid == -1) {
    // remove any existing parent relationships
    au_subgroups_remove_parent_group($subgroup_guid);
} else {
    $subgroup = get_entity($subgroup_guid);
    $parent = get_entity($parent_guid);
    $oldparent = au_subgroups_get_parent_group($subgroup);
    $child_groups = au_subgroups_get_all_children_guids($subgroup);
    //sanity check
    if (!elgg_instanceof($subgroup, 'group') || !elgg_instanceof($parent, 'group')) {
        register_error(elgg_echo('au_subgroups:error:invalid:group'));
        forward(REFERER);
    }
    // we need to have edit permissions all the way up
    if (!au_subgroups_can_move_subgroup($subgroup, $parent)) {
        register_error(elgg_echo('au_subgroups:error:permissions'));
        forward(REFERER);
    }
    // remove any existing parent relationships
    au_subgroups_remove_parent_group($subgroup->guid);
    au_subgroups_set_parent_group($subgroup->guid, $parent->guid);
    // determine the access_id of the new group, must be equal or more restrictive than the parent
    switch ($parent->access_id) {
        case ACCESS_PUBLIC:
            // only need to check that subgroup wasn't to old parent only
            if ($subgroup->access_id == $oldparent->group_acl) {
                $subgroup->access_id = $parent->group_acl;