How can I add the number of friends a user has in the footer of the view?

i tried creating a custom php field counting the number of entries and storing it in $static but i couldnt print it in the footer...

it would be good if there was a field with the number of friends a user has available in the views.

Comments

alex.k’s picture

user_relationships_load(array('user' => $user->uid, 'approved' => 1), array('count' => TRUE))

should return you the number of all approved relationships the user has. Pls see docs for user_relationships_load() in user_relationships_api.api.inc for additional filtering you might want such as type of the relationship.

andrenoronha’s picture

Status: Active » Closed (fixed)

thank you so much Alex
i got there.

halloffame’s picture

Where does this code suppose go? I tried putting it in my view footer but its not working. I'm looking for a similar thing. But more precisely along the 'more' link. Something like 'more (xxx)'.

andrenoronha’s picture

I made my own more link to show the number of users.

put this code in the footer, but remember to use PHP code input:

<?php
$account = user_load($array = array('uid' => views_get_current_view()->args[0]));

print '<a href="/user/'. $account->uid .'/allfriends">More ( ';
print user_relationships_load(array('user' => $account->uid, 'approved' => 1), array('count' => TRUE));
print ' )</a>';

?>

notice that "/user/'. $account->uid .'/allfriends" stands for the url of the page view of this view.

indiralanza’s picture

Hi
I need to recover the related nodes involved in a relationship, I dont know how to do it. Maybe I can make a db query to get the nodes references of other node, or working with views and accesing to the data of the view programally? I really need to solve it, I dont know how?? Please write back soon.