Example #1
0
/**
 * recursively travels down all routes to gather all guids of
 * groups that are children of the supplied group
 * 
 * @param type $group
 * @param type $guids
 * @return type
 */
function get_all_children_guids($group, $guids = array())
{
    // get children and delete them
    $children = get_subgroups($group, 0);
    if (!$children) {
        return $guids;
    }
    foreach ($children as $child) {
        $guids[] = $child->guid;
    }
    foreach ($children as $child) {
        $guids = get_all_children_guids($child, $guids);
    }
    return $guids;
}
Example #2
0
function 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 = get_subgroups($group, 1);
        $parent = 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}");
            }
        }
    }
}
Example #3
0
<?php

/*
2015/10/20-
Added panel footer styling
Added count to view all link
*/
namespace AU\SubGroups;

if ($vars['entity']->subgroups_enable == 'no') {
    // no subgroups allowed
    return;
}
$sgCount = '';
$subgroups = get_subgroups($vars['entity'], 3);
$body = '';
if (!$subgroups) {
    $body = '<div class="elgg-subtext">' . elgg_echo('au_subgroups:nogroups') . '</div>';
} else {
    foreach ($subgroups as $subgroup) {
        $body .= elgg_view_image_block(elgg_view_entity_icon($subgroup, 'tiny'), elgg_view('output/url', array('href' => $subgroup->getURL(), 'text' => $subgroup->name, 'is_trusted' => true)));
    }
    //count total number of subgroups and add it to view all link
    $subgroupsTotalCount = get_subgroups($vars['entity']);
    $sgCount = '(' . count($subgroupsTotalCount) . ')';
}
$title = elgg_echo('au_subgroups:subgroups');
$all_link = elgg_view('output/url', array('href' => 'groups/subgroups/list/' . $vars['entity']->guid, 'text' => elgg_echo('au_subgroups:subgroups:more') . $sgCount, 'is_trusted' => true));
$footer = "<div class='text-right'>{$all_link}</div>";
echo elgg_view_module('aside', $title, $body, array('footer' => $footer));
Example #4
0
<?php

namespace AU\SubGroups;

if ($vars['entity']->subgroups_enable == 'no') {
    // no subgroups allowed
    return;
}
$all_link = elgg_view('output/url', array('href' => 'groups/subgroups/list/' . $vars['entity']->guid, 'text' => elgg_echo('au_subgroups:subgroups:more'), 'is_trusted' => true));
$subgroups = get_subgroups($vars['entity'], 5);
$body = '';
if (!$subgroups) {
    $body = '<div class="elgg-subtext">' . elgg_echo('au_subgroups:nogroups') . '</div>';
} else {
    foreach ($subgroups as $subgroup) {
        $body .= elgg_view_image_block(elgg_view_entity_icon($subgroup, 'tiny'), elgg_view('output/url', array('href' => $subgroup->getURL(), 'text' => $subgroup->name, 'is_trusted' => true)));
    }
}
$title = elgg_echo('au_subgroups:subgroups');
$body .= "<div class='center mts'>{$all_link}</div>";
echo elgg_view_module('aside', $title, $body);
Example #5
0
/**
 * when groups are created/updated, make sure subgroups have
 * access only by parent group acl
 */
function group_visibility($event, $type, $object)
{
    $parent = get_parent_group($object);
    // make sure the visibility is what was set on the form
    $vis = get_input('vis', false);
    if ($vis !== false) {
        // this makes sure we only update access when it's done via form
        switch ($vis) {
            case 'parent_group_acl':
                $access_id = $parent->group_acl;
                break;
            case ACCESS_PRIVATE:
                $access_id = $object->group_acl;
                break;
            default:
                $access_id = $vis;
                break;
        }
        /*
         * Here we have some trickiness, because save is called twice with the visibility being
         * reset the second time.  So we have to make sure we're only updating the visibility
         * of the original (not a subgroup or parent) on subsequent calls.
         * 
         * To do this we're setting a temporary config variable to say that yes, we've been here once
         * and pass the guid of the group we're concerned with in another config variable.
         * That way we know only to update the vis of the matching guid
         */
        if (!elgg_get_config('au_subgroups_visupdate')) {
            // this is the first pass, lets mark it and save the guid of the group we care about
            elgg_set_config('au_subgroups_visupdate', true);
            elgg_set_config('au_subgroups_vis_guid', $object->guid);
        }
        if (elgg_get_config('au_subgroups_vis_guid') == $object->guid) {
            // we need to update it - first in memory, then in the db
            $object->access_id = $access_id;
            $q = "UPDATE " . elgg_get_config('dbprefix') . "entities SET access_id = {$access_id} WHERE guid = {$object->guid}";
            update_data($q);
            // make sure our metadata follows suit
            metadata_update('update', 'group', $object);
        }
        // if this group has subgroups, and we're making the visibility more restrictive
        // we need to check the subgroups to make sure they're not more visible than this group
        set_time_limit(0);
        // this is recursive and could take a while
        $children = get_subgroups($object, 0);
        if ($children) {
            foreach ($children as $child) {
                switch ($access_id) {
                    case ACCESS_PUBLIC:
                        // do nothing, most permissive access
                        break;
                    case ACCESS_LOGGED_IN:
                        // if child access is public, bump it up
                        if ($child->access_id == ACCESS_PUBLIC) {
                            $child->access_id = ACCESS_LOGGED_IN;
                            $child->save();
                        }
                        break;
                    default:
                        // two options here, group->group_acl = hidden
                        // or parent->group_acl = visible to parent group members
                        // if the child is more permissive than the parent, we're changing the child to
                        // the next level up - in this case, visible to parent group
                        if (!in_array($child->access_id, array($child->group_acl, $object->group_acl))) {
                            $child->access_id = $object->group_acl;
                            $child->save();
                        }
                        break;
                }
            }
        }
    }
}