9

I have created a relationship Followers which can be reciprocated using the user relationship module. Now user A's relationship is something like: Followers(Them to you): User B, User C, User D Followers(You to them): User D

Now i want to create a view which only shows the number of followers and following: Follower: 3
Following: 1

I went about to create the view (Views 3, Drupal7) but was not able to do. Didnt get any filters or relationships regarding this. Also, tried using the Views Cal but am not clear. Would appreciate any help.

Thanks

Edit:

Apologies for not being clear.

I created a view of type Users. Then i added a relationship (this is the part where i am not sure if i am correct or not). I tried with all the available relationships pertaining to this such as User relationships:

 User relationships: Requestee user
 User relationships: Requestee user is current user 
 User relationships: Requester user
 User relationships: Requester user is current user
 User relationships: RTID

(i tried individually all of them and various combinations of them as well)

Then under Others i clicked yes for Use Aggregates and when asked for the grouping function ("Group type"), i selected "Count and unchecked the label in the configure field screen, so that it only shows the number.

I also added a filter that the user is logged in. However, it just shows me the number of relationships of different users who have requested the current one.

Edit 2:

Found this thread: http://drupal.org/node/809476. However its for Drupal 6..., am trying to implement it for 7. lets see...if you have any pointers i would be grateful...will keep you posted

Edit 3:

Based on the above thread i wrote the following code into a custom block.

<?php
global $user;
$user_id = $user->uid;
$params = array("requestee_id" => $user_id, 'rtid' => 3);
$count = user_relationships_load($params, array("count" => TRUE));
echo $user_id;
echo $count;
?>

I just printed out the user id to check if correct user or not and it prints the correct user. However, count prints 0. Why is that?

Edit 4:

I think i am on the right way using http://drupal.org/node/203396. However there are some fixes there. The correct code is:

<?php
global $user;
$requests = user_relationships_load($param = array("approved" => 1, "user" => $user->uid), $options = array(), $reset = FALSE);
$requestcount = count($requests);
echo  $requestcount;
?>

This displays the total number of approved relationships. Now i want only the followers type relationship number. Looking into that. If anyone has any suggestions would appreciate them. Will keep you all posted

Edit5:

And now i am stuck. Whatever i try to do i am only getting the total number of relationships. I just want the number of followers(them to you) in one block and then using that, i hope, i will be able to get number of following(you to them). Would appreciate any help.

Thanks

  • 1
    What have you tried? As in specifically what have you tried? What didn't work? How did what you tried differ from what you were expecting? You must show that you have tried to solve problems yourself, this website isn't for requesting tutorials – Clive Feb 18 '13 at 11:06
  • maybe i can use function user_relationships_type_load($param = array(), $reset = NULL) but i need some direction or help – why Feb 19 '13 at 6:16
  • The paramaters for user_relationships_load also include a between paramater. "array("between" => array($uid1, $uid2)) will return all relationships between the two user ids" – Mark Ferree Feb 20 '13 at 18:13
  • @kewal, please were you able to resolve the problem? I have a need for this function in my project. Thanks. – seyi Aug 3 '13 at 16:03
  • @seyi i did it using the built in blocks available and displaying it via panels...also you can use user_relationships_type_load($param = array(), $reset = NULL)....sorry i am unable to remember the exact details but would get back to you in some time if i find it...regards – why Aug 5 '13 at 4:38
1

The following function works for me to display the count of friends a user have:

function mymodule_user_friends_count ($user) {
  $count = user_relationships_load(
    array("user" => $user->uid, 'approved' => 1, "name"=>'Friend'), 
    array('count' => TRUE));
  return $count;
}

Notice I only count approved friends and only relationships of type 'Friend'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.