I am hoping to do something really simple. I want to show the # of Flags per user in the forums, and on the profile page on my site. This way on the forums, you could see "Joe" has a collection of "32" items. Seems really simple, but I am not exactly sure how to do it (views?). Also, would there be anyway to cache this simple number so there wouldn't be lots of calculations to load a page like the forums?
Thanks
Comments
Comment #1
quicksketchThis is essentially a theming request. If you want to get the number of flags you can use code like the following:
This is not cached. Unfortunately this particular request there isn't actually a column or field that stores this exact number anywhere, it's done through a COUNT() query, so you can't build it in Views without using something like Views Calc or Views Group By. Either way I don't think Views would be appropriate for showing this count (though it is great if you want to list out the items that a user has flagged).
Comment #2
sammyman commentedFor some reason that didn't work. I used $account_id (User ID number for the author), so it would pull just info for the author of that post, but it still doesn't work. Any idea how to tweak this to pull the flag #'s?
Edit: Strange, it is working for other flags, but not "friend"... Any idea why "friend" would be different.
Comment #3
quicksketchYou're sure this is the count you want? This function will get you the number of items that the user with ID $account_id has flagged. So if "Joe" hasn't yet flagged any friends, this will be 0. It's not the number of times Joe himself has been flagged (that's $flag->get_count($account_id)).
Comment #4
sammyman commentedThanks for your help quicksketch. I tried the get_count like you suggested and it returned 0 as well. I guess I don't understand how the friend flag works, who is flagged, who is flagging.
I do want to give a count of the total #'s a user has been flagged as a friend I guess (how popular they are). Weird thing is that I am pretty sure the code was working and stopped for some reason....
Comment #5
sammyman commentedIt appears that this code counts the number of users that they have invited to be friends, NOT users that have accepted that friendship. Once the invitations have been accepted, the number goes to 0. So I guess I will keep trying to figure it out. Thanks for all the help.
Comment #6
quicksketchMy guess is that there is a second flag added by flag_friend that is actually used to store "accepted" friends. But I'm not sure how flag_friend works.
Comment #7
sammyman commentedIt looks like it is stored in flag_content. It is a "user" content type, rather than "node" content type like the rest of my site. I see the fid # is 5 too, but I have no idea how to access the data.
Comment #8
quicksketchLook up what fid 5 is in the flags table, then get the name of the flag from there.
Comment #9
quicksketchClosing after lack of activity.