Exemple #1
0
$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;
            }
            break;
        case ACCESS_LOGGED_IN:
    $options['wheres'][] = "MATCH(g.name, g.description) AGAINST('{$query}')";
    $options['order_by'] = 'relevance DESC';
}
$groups = elgg_get_entities($options);
$context = elgg_get_context();
elgg_set_context('widgets');
// use widgets context so no entity menu is used
if ($groups) {
    echo '<div class="au-subgroups-result-col">';
    for ($i = 0; $i < count($groups); $i++) {
        // break results into 2 columns of 5
        if ($i == 5) {
            echo '</div>';
            echo '<div class="au-subgroups-result-col">';
        }
        if (au_subgroups_can_move_subgroup($subgroup, $groups[$i])) {
            $class = 'au-subgroups-parentable';
        } else {
            $class = 'au-subgroups-non-parentable';
        }
        $action_url = elgg_get_site_url() . 'action/au_subgroups/move?parent_guid=' . $groups[$i]->guid;
        $action_url = elgg_add_action_tokens_to_url($action_url);
        echo "<div class=\"{$class}\" data-action=\"{$action_url}\">";
        echo elgg_view_entity($groups[$i], array('full_view' => false));
        echo "</div>";
    }
    echo '</div>';
} else {
    echo elgg_echo('au_subgroups:search:noresults');
}
elgg_set_context($context);