Store
Community Documentation

v3 Knowledgebase

Get List of Friends

To get an ARRAY of friends for a user that is logged in you can connect to the friend module service class and use the get() method.

This service file can be found here:
/module/friend/include/service/friend.class.php

Use the following method to get the users friends:
PHP:
list($iTotalFriends$aFriends) = Phpfox::getService('friend')->get('friend.user_id = ' Phpfox::getUserId()); 

With this example the variable $aFriends will hold an ARRAY of friends for a user that is logged in.

If you would print_r the variable $aFriends you would get a similar output:
PHP:
Array
(
    [
0] => Array
        (
            [
dob_setting] => 0
            
[friend_id] => 6797
            
[is_top_friend] => 0
            
[time_stamp] => 1297075781
            
[user_id] => 2
            
[server_id] => 0
            
[user_name] => user2
            
[full_name] => Serenity Burton
            
[gender] => 1
            
[user_image] => 2011/03/61ce55126ed07a14ef97bc3f34136b98%s.jpg
            
[is_invisible] => 0
        
)

    [
1] => Array
        (
            [
dob_setting] => 0
            
[friend_id] => 2212
            
[is_top_friend] => 0
            
[time_stamp] => 1296833166
            
[user_id] => 353
            
[server_id] => 0
            
[user_name] => user353
            
[full_name] => Rylan Goodwin
            
[gender] => 2
            
[user_image] => 353%s.jpg
            
[is_invisible] => 0
        


If you want to get a list of friends for a specific user and not the user that is logged in you will have to know the users ID#. In this example we will use the number 2 as the users ID#:
PHP:
list($iTotalFriends$aFriends) = Phpfox::getService('friend')->get('friend.user_id = 2');