Hi,
I'm trying to custom-write a seemingly simple block that will count the relationships that the user (whos profile is being viewed) has. Exactly like we see in on Twitter: (X)Followers, (X)Following. But I can't find the correct function in UR API.

I have only 1 type of one-way relationship called "Following", which is also reciprocal.

So the code in block should look something like:

<?php $account = user_load(arg(1)); ?>
<a href="/followers"><?php print UNKNOWN_USER_RELATIONSHIPS_API($account->uid); ?></a>
<br />
<a href="/followers">Followers</a>

...and a similar thing for the count of "Following" (you to them) kind of relationships

Could you possibly help? Much appreciate your help in advance

Comments

drupalina’s picture

I think I'm getting very close. I just need a little push. So far I have:

<?php
//  I just need to find out how to correctly user_load the account that is being viewed
//  from arg or something like that.  What code should I put in these 2 lines?
$params = array("requestee_id" => $user_id, 'rtid' => 3);
$count = user_relationships_load($params, array("count" => TRUE));
echo $count;
?>

I just need a little help with loading the uid of the currently viewed user and/or the author of the currently viewed node, so that I can display the number of followers this user has inside the Author Pane.

alex.k’s picture

The URL when looking at a user account is user/{uid}, so if you say $user_id = arg(1); that will work.

utsujp’s picture

$count seems counts all including inactive users.
Can I limit the count for active user?

drupalina’s picture

@alex.k -- Thanks!
But what if I want to display the relationship numbers for each user who are listed in a View using Custom_Field module???
So - I want to create a view that lists users
[Mary's Picture] - Username:Mary Smith - Follow/un-follow - Following 17 - Followers 26
[Jack's Picture] - Username:Jack Brown - Follow/un-follow - Following 36 - Followers 12
[Tim's Picture] - Username:Tim Clarck - Follow/un-follow - Following 23 - Followers 27

if we use

global $user;
$user_id = $user->uid;

then it will load the currently logged in user.

If we use arg(1) then it will load the uid from url (and that definitely doesn't help)

The $user_id in this case must be derived from another place other than arg(1). But how?
any ideas?

ajayg’s picture

How are you getting "Username:Mary Smith"? So some how need to pass that parameter/field to get userid .

robby.smith’s picture

It be awesome if this could be possible using Views as well.
Subscribing

mrf’s picture

Status: Active » Fixed

Looks like this question was answered previously.

Robby.smith, please open a separate feature request describing how you'd like to see this type of information included in views.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.