Hi guys. I had a feature/interface idea that I'm having some trouble figuring out.
I have inserted a display of the 10 newest buddies into my custom user profile page.
I would like to add a little icon and some text that says if the given buddy is just a buddy or if the user is also a buddyof the buddy (they are mutual buddies). I am having some trouble writing a condition to do this check. I'm not sure if it would require a sql query or if the data is already available through the buddylist module. I suspect it is, since buddylist already has a "buddy of" page.
Here is the logic of what I'm trying to do:

given we're on user1's profile page:
  we are inside a foreach to get all the buddies of user1:
    if (user2 is user1's buddy) and (user1 is a buddy of user2) {
      display (mutual-icon) (Mutual buddies text);
    }
    else {
      display (buddy-icon) (regular buddy text);
    }
  break;

As you can probably tell from my pseudo code above, I am very new to php, and I'm not sure exactly how to accomplish the above feature.

If I could get some help on this I would be very appreciative, and I'll definitely post my final code here to share with others.

Comments

dldege’s picture

here's a function to get get a buddy of b


function _buddylistext_is_buddy($uid,$bid) {
  $isbuddy = db_result(db_query("SELECT * FROM {buddylist} WHERE uid = %d AND buddy = %d",$uid, $bid));
  return $isbuddy;
}

You could call this with a,b and then b,a as to get both directions of relationships

ZrO-1’s picture

Ah yeah, very nice. Thanks dldege!
I'll work on getting this setup as a module, and post the result here.

ZrO-1’s picture

Here's what I have so far. Am I on the right track with this? I'd like to get this setup as a full module that maybe could get added as a contrib to buddylist.

<?php
function mutualbuddies_mutualcheck($usera, $userb) {
  $sql = "SELECT * FROM {buddylist} WHERE uid = %d AND buddy = %d";
  $query1 = db_query($sql, $usera, $userb);
  $buddyonce = db_fetch_array($query1);
  $query2 = db_query($sql, $userb, $usera);
  $buddytwice = db_fetch_array($query2);
  $mutualnotice = '';
  
  if ($buddyonce->userb == $buddytwice->userb && $buddyonce->usera == $buddytwice->usera) {
    $mutualnotice = theme_image(drupal_get_path('module', 'mutualbuddies') .'/icons/friends-16.png').'&nbsp;'.t('Mutual Buddies');
  }
  else {
    $mutualnotice = theme_image(drupal_get_path('module', 'mutualbuddies') .'/icons/buddies-16.png').'&nbsp;'.t('Buddy');
  }
  
  return $mutualnotice;
}
?>

Thanks for all the help guys.

designwork’s picture

Hi Zr0-1,

i have some problem. I have a tab that i wanna only show if the current user is a buddy of the userprofile he is at.
Do you have any idea how to do this?

Dirk