/** * 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; }
/** * Prevents users from joining a subgroup if they're not a member of the parent * * @param type $event * @param type $type * @param ElggRelationship $object * @return boolean */ function au_subgroups_join_group($event, $type, $object) { if ($object instanceof ElggRelationship) { $user = get_entity($object->guid_one); $group = get_entity($object->guid_two); $parent = au_subgroups_get_parent_group($group); // use temp global config to decide if we should prevent joining // prevent joining if not a member of the parent group // except during a subgroup move invitation $au_subgroups_ignore_join = elgg_get_config('au_subgroups_ignore_join'); if ($parent && !$au_subgroups_ignore_join) { // cover the case of moved subgroups // user will have been invited, and have a plugin setting saying which other groups to join $invited = check_entity_relationship($group->guid, 'invited', $user->guid); $children_to_join = elgg_get_plugin_user_setting('invitation_' . $group->guid, $user->guid, 'au_subgroups'); if (!empty($children_to_join)) { $children_to_join = unserialize($children_to_join); } if ($invited) { elgg_set_config('au_subgroups_ignore_join', true); // we have been invited in through the back door by a subgroup move // join this user to all parent groups fo this group if (au_subgroups_join_parents_recursive($group, $user)) { // we're in, now lets rejoin the children if (is_array($children_to_join)) { $children_guids = au_subgroups_get_all_children_guids($group); foreach ($children_to_join as $child) { if (in_array($child, $children_guids)) { $child_group = get_entity($child); $child_group->join($user); } } } // delete plugin setting elgg_set_plugin_user_setting('invitation_' . $group->guid, '', $user->guid, 'au_subgroups'); } else { // something went wrong with joining the groups // lets stop everything now return false; } } elseif (!$parent->isMember($user)) { register_error(elgg_echo('au_subgroups:error:notparentmember')); return false; } } } }
<?php $group = $vars['entity']; $parent = au_subgroups_get_parent_group($group); if ($parent && !$group->isMember()) { ?> <div class=""> <?php echo elgg_echo('au_subgroups:needjoinparent'); ?> </div> <?php }
* * @uses $vars['entity'] The entity the icon represents - uses getIconURL() method * @uses $vars['size'] topbar, tiny, small, medium (default), large, master * @uses $vars['href'] Optional override for link * @uses $vars['img_class'] Optional CSS class added to img * @uses $vars['link_class'] Optional CSS class for the link */ $entity = $vars['entity']; $sizes = array('small', 'medium', 'large', 'tiny', 'master', 'topbar'); // Get size if (!in_array($vars['size'], $sizes)) { $vars['size'] = "medium"; } $class = elgg_extract('img_class', $vars, ''); $span = ''; $parent = au_subgroups_get_parent_group($entity); if ($parent) { if ($class) { $class .= ' '; } $class .= 'au_subgroup_icon'; $span = '<span class="au_subgroup au_subgroup_icon-' . $vars['size'] . '">' . elgg_echo('au_subgroups:subgroup') . '</span>'; } if (isset($entity->name)) { $title = $entity->name; } else { $title = $entity->title; } $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false); $url = $entity->getURL(); if (isset($vars['href'])) {
<?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;
function au_subgroups_titlemenu($h, $t, $r, $p) { if (in_array(elgg_get_context(), array('group_profile', 'groups'))) { $group = elgg_get_page_owner_entity(); // make sure we're dealing with a group if (!elgg_instanceof($group, 'group')) { return $r; } // make sure the group is a subgroup $parent = au_subgroups_get_parent_group($group); if (!$parent) { return $r; } // see if we're a member of the parent group if ($parent->isMember()) { return $r; } // we're not a member, so we need to remove any 'join'/'request membership' links foreach ($r as $key => $item) { if (in_array($item->getName(), array('groups:join', 'groups:joinrequest'))) { unset($r[$key]); } } return $r; } }