displaying user relationships 'properly' !

The user_relationship module can be used to create relationships among users . More on this over here . Now there is a problem with this module , let us take a case for example . If X has a relationship of 'father' with Y and Y has a relationship of 'son' with X , where X and Y are users on a drupal site . Now when we access the page /relationships or /relationships/list the module lists all the relationships of the present user . But the mistake is , for X the entries would be

Y                 son                [online status]                 [remove link]
Y                 father             [online status]                 [remove link]

ie, the module lists each relationships from both sides though they are one way relationships .Similary Y will have two entries with X as both father and son . This is not the ideal behaviour . For X we should list only the relationships others hold with him , not the relationships he holds with others . So the code used for presenting the relationships ( in user_relationships_theme.inc) . The one condition which needs to be implemented is that only those relationships be displayed for which the viewer is the requestee . The following changes had to be made to in user_relationships_theme.inc :

while ($relation = db_fetch_object($result)) {
      $this_user = $viewed_user->uid == $relation->requestee_id ? 'requester_id' : 'requestee_id';
      $this_user = user_load(array('uid' => $relation->$this_user));

      $rows[] = array(
        theme('username', $this_user),
        $relation->name,
        $this_user->access > $online_interval ? t('online') : t('not online'),
        $edit_access ? theme('user_relationships_remove_link', $viewed_user->uid, $relation) : ' ',
      );
    }

here the ternary condition is the main culprit , this results in displaying the relationships for which the viewer is both the requestee and the requester . It can be replaced with the following code :

    $relationship_count_for_record = 0;// need this variable otherwise the no relationships found is displayed erronously
    while ($relation = db_fetch_object($result)) {
/**
 * The module should display only the relationships for which the viewer is the requestee .
 * so commented the below condition and put a condition where only requester_id is asigned
 * to $this_user .
 */

      /*$this_user = $user->uid == $relation->requestee_id ? 'requester_id' : 'requestee_id';*/
/****************************************/
    if($user->uid == $relation->requestee_id){
      $relationship_count_for_record ++ ;
      $this_user = 'requester_id';
/****************************************/
      $this_user = user_load(array('uid' => $relation->$this_user));

      $rows[] = array(
        theme('username', $this_user),
        $relation->name,
        $this_user->access > $online_interval ? t('online') : t('not online'),
        $edit_access ? theme('user_relationships_remove_link', $viewed_user->uid, $relation) : ' ',
      );
/**********/}/*********/
else {
    if($relationship_count_for_record != 1)
         $output .= t('No relationships found');
  }
    }

The file in user_relationships_theme.inc with the required changes has been attached with this node .
I am really doubtful whether this is an optimal tweak , as the changes have been done to the presentation part of the module (ie theming part) , may be the same can be achieved by making changes to the database query used to retrieve the data .
Note:The user_relationship module after making the changes has also been attached .

AttachmentSize
user_relationships-5.x-2.8.zip77.5 KB
user_relationships_theme.inc7.03 KB
  • Article Type:
  • Drupal Version: