Answer the question
In order to leave comments, you need to log in
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
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);
}
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
with whom there are mutual friends how to realize
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question