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); } } } }
/** * 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 au_subgroups_get_all_children_guids($group, $guids = array()) { // get children and delete them $children = au_subgroups_get_subgroups($group, 0); if (!$children) { return $guids; } foreach ($children as $child) { $guids[] = $child->guid; } foreach ($children as $child) { $guids = au_subgroups_get_all_children_guids($child, $guids); } return $guids; }
/** * when groups are created/updated, make sure subgroups have * access only by parent group acl */ function au_subgroups_group_visibility($event, $type, $object) { $parent = au_subgroups_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 = au_subgroups_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; } } } } }
<?php if ($vars['entity']->subgroups_enable == 'no' || !au_subgroups_get_subgroups($vars['entity'])) { // 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 = au_subgroups_get_subgroups($vars['entity'], 0); $body = ''; foreach ($subgroups as $subgroup) { if ($subgroup->isMember()) { $body .= elgg_view_image_block(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);