/** * 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); } }
/** * Remove a user from the group. * * @param ElggUser $user User * * @return bool */ public function leave(ElggUser $user) { return leave_group($this->getGUID(), $user->getGUID()); }
$AU_SUBGROUPS_ALL_MEMBERS = array_unique($AU_SUBGROUPS_ALL_MEMBERS); // array of user guids we need to invite back into the group $invite = array(); foreach ($AU_SUBGROUPS_ALL_MEMBERS as $member_guid) { if (!is_group_member($parent_guid, $member_guid)) { $invite[] = $member_guid; // the user isn't a member of the parent group // so we have to remove them from this subgroup, and all subgroups of this subgroup // and send them an invitation // we'll set a plugin setting on the user, which we'll monitor for when they accept the invitation $groups_left = array($subgroup_guid); foreach ($child_groups as $child_guid) { if (is_group_member($child_guid, $member_guid)) { $groups_left[] = $child_guid; } } leave_group($subgroup_guid, $member_guid); // now we need to set a plugin user setting for this user that we can monitor elgg_set_plugin_user_setting('invitation_' . $subgroup_guid, serialize($groups_left), $member_guid, 'au_subgroups'); // invite the user add_entity_relationship($subgroup_guid, 'invited', $member_guid); $user = get_user($member_guid); if ($user) { // notify the user $url = elgg_normalize_url("groups/invitations/{$user->username}"); notify_user($member_guid, $subgroup->owner_guid, elgg_echo('groups:invite:subject', array($user->name, $subgroup->name)), elgg_echo('au_subgroups:invite:body', array($user->name, $subgroup->name, $parent->name, $url))); } } } system_message(elgg_echo('au_subgroups:move:success')); forward(REFERER);