Exemple #1
0
 /**
  * Listen to the create member_of_site relationship event to handle new users
  *
  * @param string            $event        the name of the event
  * @param string            $type         the type of the event
  * @param \ElggRelationship $relationship supplied param
  *
  * @return void
  */
 public static function siteJoinDomainBasedGroups($event, $type, $relationship)
 {
     if (!self::validateSiteJoinRelationship($relationship)) {
         return;
     }
     $user_guid = (int) $relationship->guid_one;
     $site_guid = (int) $relationship->guid_two;
     $user = get_user($user_guid);
     // ignore access
     $ia = elgg_set_ignore_access(true);
     // find domain based groups
     $groups = group_tools_get_domain_based_groups($user, $site_guid);
     if (empty($groups)) {
         // restore access settings
         elgg_set_ignore_access($ia);
         return;
     }
     foreach ($groups as $group) {
         // join the group
         $group->join($user);
     }
     // restore access settings
     elgg_set_ignore_access($ia);
 }
Exemple #2
0
/**
 * Event when the user joins a site, mostly when registering
 *
 * @param string           $event        create
 * @param string           $type         member_of_site
 * @param ElggRelationship $relationship the membership relation
 *
 * @return void
 */
function group_tools_join_site_handler($event, $type, $relationship)
{
    if (!empty($relationship) && $relationship instanceof ElggRelationship) {
        $user_guid = $relationship->guid_one;
        $site_guid = $relationship->guid_two;
        $user = get_user($user_guid);
        if (!empty($user)) {
            // ignore access
            $ia = elgg_set_ignore_access(true);
            // add user to the auto join groups
            $auto_joins = elgg_get_plugin_setting("auto_join", "group_tools");
            if (!empty($auto_joins)) {
                $auto_joins = string_to_tag_array($auto_joins);
                foreach ($auto_joins as $group_guid) {
                    $group = get_entity($group_guid);
                    if (!empty($group) && $group instanceof ElggGroup) {
                        if ($group->site_guid == $site_guid) {
                            // join the group
                            $group->join($user);
                        }
                    }
                }
            }
            // auto detect email invited groups
            $groups = group_tools_get_invited_groups_by_email($user->email, $site_guid);
            if (!empty($groups)) {
                foreach ($groups as $group) {
                    // join the group
                    $group->join($user);
                }
            }
            // check for manual email invited groups
            $group_invitecode = get_input("group_invitecode");
            if (!empty($group_invitecode)) {
                $group = group_tools_check_group_email_invitation($group_invitecode);
                if (!empty($group)) {
                    // join the group
                    $group->join($user);
                    // cleanup the invite code
                    $group_invitecode = sanitise_string($group_invitecode);
                    $options = array("guid" => $group->getGUID(), "annotation_name" => "email_invitation", "wheres" => array("(v.string = '" . $group_invitecode . "' OR v.string LIKE '" . $group_invitecode . "|%')"), "annotation_owner_guid" => $group->getGUID(), "limit" => 1);
                    // ignore access in order to cleanup the invitation
                    $ia = elgg_set_ignore_access(true);
                    elgg_delete_annotations($options);
                    // restore access
                    elgg_set_ignore_access($ia);
                }
            }
            // find domain based groups
            $groups = group_tools_get_domain_based_groups($user, $site_guid);
            if (!empty($groups)) {
                foreach ($groups as $group) {
                    // join the group
                    $group->join($user);
                }
            }
            // restore access settings
            elgg_set_ignore_access($ia);
        }
    }
}