Hi there and thanks for your great module :-)
I want to display an info inside a block if there is a pending friend request.
For the privatemsg module I used this kind of snippet:
<?php
$num = privatemsg_unread_count();
if ($num > 0) {
print $num ." new messages";
}
?>Is there a silimar solution for the flag friend module?
Thanks for your answer,
Culfin
Comments
Comment #1
sirkitree commentedThe simplest solution would be to create a block in Views. See the view that comes with the module and create a block display that has similar settings to the 'Pending' page display. I think the only thing you might want to change is where the argument handler gets it's default argument, which is the user - I think the page display's argument gets the user from the url, and you would want to get it from the currently logged in user.
Comment #2
liliplanet commentedHi,
If I may go a little further on this request.
As private messages show 'Messages (4)' as a menu item, in other words '4 waiting messages' ..
It would be stunning if Flag Requests could have for instance 'Friend Requests (5)' in the menu (my case secondary menu).
Is that at all possible please? Flag friend is naturally our most important networking module :)
Look forward to any reply, and thank you.
Lilian
Comment #3
sirkitree commentedI've actually done the same thing on our new website, but since our menu system is custom coded, I did not actually change the view title. I'm actually not sure how to dynamically change the view title to tell you the truth.
Comment #4
sirkitree commentedGetting that count is a bit tricky as well. Please see #434020: Get total count of friends by $flag->get_user_count
Comment #5
Ralla commentedHere's how I did it:
Comment #6
Caderial commentedWhere would i put this code to implement it? and then how would i show the link in my secondary links menu?
Comment #7
Ralla commentedI haven't really done this, but this might work - I didnt test this though :) And there's probably a much better way to do this..
Put this in template.php for your theme. Remember to replace "yourtheme" with the actual name of your theme.
Comment #8
garciac1212 commented#5 works great! the only prob is that I want it to display only if there IS a friend request/pending. If there isn't any I don't want it to display "0" like it does by default.
Any way around this?
Comment #9
sibany commentedhey!, garciac1212
whats wrong?
am still learning php.. :)
so her what i did :
in template.php
i past the code like this:
function _get_pending_friend_requests($uid) {
$friend_flag_fid = flag_get_flag('friend');
$pending_friends = db_result(db_query('SELECT COUNT(*) FROM {flag_content} WHERE fid = %d AND content_id = %d', $friend_flag_fid->fid, $uid));
return $pending_friends;
}
function tendu_menu_item_link($link) {
if ($link['user/[user-id]/friends/pending'] == 'the path of the menu item that should have the count added.') {
global $user;
$new_friend_requests = _get_pending_friend_requests($user->uid);
$link['title'] = $link['title'] . ' ('. $new_friend_requests .')';
}
}
by the way, i put the link menu friend request "the path of the menu item" as token to show for each user...
user/[user-id]/friends/pending
also tried this...
user/%/friends/pending
M.sibany
Comment #10
shakylegz commentedHi..
Anyone that wants to have a block showing the number pending friend requests can use this code(Drupal 7):
Regards
Comment #11
dankung1 commentedHi, thank you,hakylegz .
I modified a little, just add a URL to deal with the friend request.
tested on drupal 7
Comment #12
sibany commentedGod Bless you Guys!
Thanks! :)
Comment #13
sharmavijay86 commentedHI i am
new to drupal
and using flag with flagfriend module.
tried above in a new block phpcode. i checked in mysql there is no table called {flag_content}.
I wanted to show message of new friend requests count to a user when he login.
Please help!
Comment #14
giorgiopg commentedFor all those still interested. It worked for me.