D
D
Deefs2018-01-31 12:44:53
PHP
Deefs, 2018-01-31 12:44:53

Show only those with whom you have mutual friends?

Good afternoon, there is a block to show randomly possible friends, but it would be better to show those with whom there are mutual friends, how can it be implemented?
fields in the table
5a718fc2283c0641584753.png
Function for displaying possible friends

function relationship_suggest($limit, $refId = null, $only_people = true) {
    $ignoredUsers = mostIgnoredUsers();
    $refId = ($refId) ? $refId : get_userid();

    $whereClause = "";

    $ignoredUsers = array_merge($ignoredUsers, get_friends($refId));
    $ignoredUsers = array_merge($ignoredUsers, get_requested_friends($refId));
    $friendsFriends = get_friends_of_friend($refId);
    if ($friendsFriends) {
        $friendsFriends = implode(',', $friendsFriends);
        $whereClause .= "id IN({$friendsFriends}) ";
    }

    //$followersFollowing = get_following_following($refId);
    $ignoredUsers = array_merge($ignoredUsers, get_following($refId));

    $userCountry = get_user_data('country');
    $userCity = get_user_data('city');
    $userState = get_user_data('state');
    $whereClause .= ($whereClause) ? " OR `country`='{$userCountry}' OR `city`='{$userCity}' OR `state`='{$userState}' OR avatar !=''": "`country`='{$userCountry}' OR `city`='{$userCity}' OR `state`='{$userState}' OR avatar !=''";
    $whereClause = fire_hook('users.suggestion.sql', $whereClause);
    $after_whereClause = "";
    $after_whereClause = fire_hook('users.category.filter',$after_whereClause,array($after_whereClause, true));
    $ignoredUsers = implode(',', array_merge(array($refId), $ignoredUsers));
    $mutual = array();
     $loggedInFriends = get_friends();
     $userid = get_userid();
    $thisUserFriends = get_friends($userid);
    if (is_array($thisUserFriends)) {
        foreach($thisUserFriends as $f) {
            if (in_array($f, $loggedInFriends) and $f != get_userid()) $mutual[] = $f;
        }
    }
    $fields = get_users_fields();


    $query = "SELECT {$fields} FROM `users` WHERE `id`NOT IN({$refId}) AND ({$whereClause}) AND id NOT IN ({$ignoredUsers}) AND activated=1 {$after_whereClause} ORDER BY rand()";
    $query = fire_hook("state.city.suggestions",$query,array($fields,$refId,$whereClause,$ignoredUsers));
    if($only_people){

        $query = fire_hook('get.suggest.non.doctors',$query,array($fields,$mutual,$refId,$whereClause,$ignoredUsers));
    }
    //exit($query);
    return paginate($query, $limit);
}

There is also a function that only shows the number of mutual friends
function get_mutual_friends($userid) {
    $loggedInFriends = get_friends();
    $thisUserFriends = get_friends($userid);
    $mutual = array();
    if (is_array($thisUserFriends)) {
        foreach($thisUserFriends as $f) {
            if (in_array($f, $loggedInFriends) and $f != get_userid()) $mutual[] = $f;
        }
    }
    return $mutual;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-01-31
@BorisKorobkov

with whom there are mutual friends how to realize

Selection from the table of friends and once again join the same table ("friends of friends"). And then there are all sorts of clarifications on the type of a common city, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question