Hi,

I have used $flag->get_user_count to get total count but I believe it includes pending friends I have flagged, is there anyway to get total counts for approved friends only? Thanks

Comments

sirkitree’s picture

Category: support » feature
Status: Active » Postponed (maintainer needs more info)

Currently there is not way other than a direct query of the flag_friend table. However I'm open to adding this as a feature. Do you have a proposed way of going about adding it?

dropchew’s picture

I did a search through views issues and the only temporary solution I can find is to get total pager items in a views template...Sorry I have limited coding knowledge...

sirkitree’s picture

Category: feature » task
Status: Postponed (maintainer needs more info) » Active

This would be quite useful, however I think we really need to implement our own function for this. $flag->get_user_count() is going to be unreliable for a few reasons.

1) It only will get you a list of 'pending' friends, or people that you have requested to be friend with.
2) Of that list, it will include 'blocked' users, rendering the count different than what Views will report.
3) We need a list of actual friends (from the flag_friend table) instead of just flagged users, or requests.

Making this a task.

gausarts’s picture

Subscribing. Thanks

sammyman’s picture

Is there any update to this. I have been struggling with the same problem. Is there any "quick fix" for the meantime? I was using $flag->get_user_count until I finally realized it was only showing pending friends.

Ralla’s picture

try this simple query:

global $user;
$friend_count = db_result(db_query('SELECT COUNT(*) FROM {flag_friend} WHERE uid = %d OR friend_uid = %d', $user->uid, $user->uid));
sammyman’s picture

I tried that but it didn't work. This code did for me however:

Not sure if it is the best way to write the code, but it works! Thanks!

<?php
$flag = flag_get_flag('friend');
print flag_friend_get_friend_count($account_id);
?>
sirkitree’s picture

Status: Active » Fixed

seeing as this function was added at some point (I lost track) marking as fixed.

Status: Fixed » Closed (fixed)

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

sammyman’s picture

Sorry for bringing this up late, but how do you implement this if it has been added?

sirkitree’s picture

You implemented it just fine in #7