hi guys like the title say.

how i can check this?

in buddylist i used the following to check whether someony is my friend or not:

if (@in_array($user->uid, array_keys(buddylist_get_buddies($account->uid))) && user_access('maintain buddy list'))
{ $mybuddy = 1 ; } else { $mybuddy = 0 ; }

please someone help me

regards

Lausch

PS: also possible to check in witch relationship group my user is?

Comments

sprsquish’s picture

Sure. It's pretty easy actually.

  // Put all the relationships existing between $user and $account into $relationships.
  // Set $mybuddy to TRUE if there are relationships and FALSE if not.
  $mybuddy = !!($relationships = user_relationships_load(array('between' => array($user->uid, $account->uid))));

  // Loop through the relationships existing between $user and $account and print their names.
  foreach ($relationships as $relationship) {
    print $relationship->name;
  }
Lausch’s picture

hi, thanks for your help,

$mybuddy is empty? what do i wrong?

i need simply a check whether the profile i view is from my buddy or not...

the last

if (@in_array($user->uid, array_keys(buddylist_get_buddies($account->uid))) && user_access('maintain buddy list'))
{ $mybuddy = 1 ; } else { $mybuddy = 0 ; }

worked for me...

i need it for example to show the messages like

this is your friend

or

this is not your friend

regards

Lausch

sprsquish’s picture

Well, I'm not sure why it's not working. If you create two users (1 and 2) and set them as follows and create a relationship between them that code should work. To simplify it and only set $mybuddy to 1 if the person is a buddy or 0 if not you could do the following:

  $mybuddy = user_relationships_load(array('between' => array($user->uid, $account->uid))) ? 1 : 0;

That will set $mybuddy to 1 if there is any relationship between the two users and 0 if not. It's a drop in replacement for the code you're showing me.

Lausch’s picture

ok hum,

i tryd the following now:

$mybuddy = !!($relationships = user_relationships_load(array('between' => array($user->uid, $GLOBALS['user']->uid))));

now it returns 1 if it is my buddy or NOTHING if it isnt my buddy.

regards

Lausch

sprsquish’s picture

Okay, I think I see the problem.

What are you trying to use to display the value of $mybuddy? It looks like you're using print($mybuddy) If that's the case you'll get exactly the results you're seeing.

Try using var_dump($mybuddy) You should see it dump out "bool(true)" if the person is your buddy and "bool(false)" if not. This is correct behaviour.

If you'd still like to set $mybuddy to 1 if it is a buddy or 0 if it's not you can use the following:

  $mybuddy = !!($relationships = user_relationships_load(array('between' => array($user->uid, $GLOBALS['user']->uid)))) ? 1 : 0;

If you then use print($mybuddy) you'll see 1 if their a buddy and 0 if not.

Lausch’s picture

Status: Active » Fixed

ok many many thanks!

now it works for me :-)

best regards

Lausch

Lausch’s picture

Status: Fixed » Closed (fixed)