How long before this module gets the attention of buddylist and we get snippets for custom profiles?

Comments

sprsquish’s picture

Status: Active » Postponed (maintainer needs more info)

Define "snippets for custom profiles"

netentropy’s picture

like a snippet to show your top 10 buddies on your user.tpl.php

sprsquish’s picture

Sorry, I may just be dense, but I'm still not sure what you mean by snippets. Are you talking about blocks that could be used, or code examples that developers could use? I'm still not exactly sure.

lias’s picture

I think he's talking about the php code in the drupal handbook php snippets section http://drupal.org/handbook/customization/snippets. THese are used to place in your custom profile pages, etc.

netentropy’s picture

yes.

when making a custom user profile....how could we show the avatars of our buddies

VVN’s picture

my php skill sucks at this time, like my english skill, but this may works:

//pick 10 random friends (relationship id = 1, may change)
  $relamici = user_relationships_load(array('user' => $user->uid, 'rtid' => 1),FALSE,'rid','RAND()',10);
//open div
  $printamici = '<div id="amiciav">';
  foreach ($relamici as $ramico) {
//pick only approved friends
  if ($ramico->approved) {
//determine the friend's uid
    if ($ramico->requester_id == $user->uid) { $amico_id = $ramico->requestee_id; }
	else { $amico_id = $ramico->requester_id; }
//load user info (picture but also all Profile fields)
	$amico =  user_load(array('uid' => $amico_id));
//themize friend's avatar
	if ($amico->picture) { $printamici .= theme('user_picture', $user); }
    }
  }
//close div
  $printamici .= '</div>';
//print the whole div with all the themed avatars
  print $printamici;

not tested, i'm using another code and now i can't test this. tell me if you has problems

sprsquish’s picture

This would be the more "user relationships" way to do it:

The loader will accept any valid column as a condition, so we let the database find 10 approved relationships sorted at random.

Pushing each avatar into an array lets us easily change the output in the future. This can quickly become a list or table without needing to muck with the loading code.

  //pick 10 random approved friends (relationship id = 1, may change)
  $rtid = 1;
  $relamici = user_relationships_load(array('user' => $user->uid, 'rtid' => $rtid, 'approved' => TRUE), FALSE, 'rid', 'RAND()', 10);

  $printamici = array;
  foreach ($relamici as $ramico) {
    //determine the friend's uid
    $amico_id = $ramico->requester_id == $user->uid ? $ramico->requestee_id : $ramico->requester_id;
    //load user info (picture but also all Profile fields)
    $amico =  user_load(array('uid' => $amico_id));
    //themize friend's avatar
    if ($amico->picture) { 
      $printamici[] = theme('user_picture', $user); 
    }
  }

  //print the themed avatars
  print "<div id='amiciav'>".implode('', $printamici).'</div>';

  //OR a list
  print "<ul id='amiciav'><li>".implode('</li><li>', $printamici).'</li></ul>';

  //OR a table with one avatar per row (with a bit more work this could be a multi-column table)
  print "<table id='amiciav'><tbody><tr><td>".implode('</td></tr><tr><td>', $printamici).'</td></tr></tbody></table>';
netentropy’s picture

is there a way to show a top 10 or the first ten

Joe Malik’s picture

Hi, first of all thx a lot for the code snippet.
The last snippet is causing an error, because the array $printamici isn't initialized correctly:
$printamici = array;
should be
$printamici = array();

When using $amico_id = $ramico->requester_id == $user->uid ? $ramico->requestee_id : $ramico->requester_id;, only the current user (me) is printed as a friend - ie. 10 times. I changed it to $amico_id = $ramico->requestee_id;, because the requestee is the one who should be printed out. Now: am I on the right way? Or what's goin' wrong there?

netentropy’s picture

i was not able to get the snippet to work at all...

Joe Malik’s picture

Here's the Code i'm using in my user_profile.tpl.php - maybe this helps?

//pick 10 random approved friends (relationship id = 1, may change)
  $rtid = 1;
  $relamici = user_relationships_load(array('user' => $user->uid, 'rtid' => $rtid, 'approved' => TRUE), FALSE, 'rid', 'RAND()', 99);

  $printamici = array();
  foreach ($relamici as $ramico) {
    //determine the friend's uid
    $amico_id = $ramico->requestee_id;
    //load user info (picture but also all Profile fields)
    $amico =  user_load(array('uid' => $amico_id));
    //themize friend's avatar
    if ($amico->picture) {
      $printamici[] = theme('user_picture', $amico);
    }
  }
  
  $count=1;
  print '<table><tr>';
  foreach($printamici as $friend)
  {
  	print '<td>'.$friend.'</td>';
	if($count++ == 5) { print '</tr><tr>'; $count=1; }
	}

print '</tr></table>';
sprsquish’s picture

Component: Code » User interface
Category: feature » support
Status: Postponed (maintainer needs more info) » Active
socialnicheguru’s picture

subscribing

rodrix’s picture

Is this code for buddylist1, buddylist2 or user relationships?!
Code says Userrelationships but title says buddy list.

Thanks!

rodrix’s picture

I am sorry, we're on User Relatinships Issues. I actually thought this issue was on Advanced Profiles project page (I accindetaly switched windows)
Thanks! Still subscribing

ajayg’s picture

Title: Getting the attention of buddy list » How to show a list of relationships on profile
Status: Active » Closed (fixed)

Updated the title to correctly reflect content of the issue.
I suggest to close this as some snippets are already provided above. Please make it active if you are not satisfied. Just trying to help clear issue queue.

ncameron’s picture

Nice one Joe, worked a charm. Two tweaks which may help others:

1) If you use this on a Node profile or bio page (or any page which is not the user page)

replace:

<?php
  $relamici = user_relationships_load(array('user' => $user->uid, 'rtid' => $rtid, 'approved' => TRUE), FALSE, 'rid', 'RAND()', 99);
?>

with:

<?php
  $relamici = user_relationships_load(array('user' => $node->uid, 'rtid' => $rtid, 'approved' => TRUE), FALSE, 'rid', 'RAND()', 99);
?>

2) Personally, I like to see the usernames along with the avatars. You can get this by modifying:

<?php
    if ($amico->picture) {
      $printamici[] = theme('user_picture', $amico);
    }
?>

with:

<?php
    if ($amico->picture) {
      $printamici[] = theme('user_picture', $amico);
      $printamici[] = $amico->name;
    }
?>

viva drupal, viva user relationships!

Cheers,

Neil