I am having a lot of trouble with getting a View that filters out all users that the current logged in user has a relationship with.

I can filter out users I have a relationship with where I was the requester using a relationship.
I can filter out users I have a relationship with where I was the requestee using a relationship.

Is there a easy way to just filter out all users that the user currently has a relationship with (even if the logged in user was the requester or the requestee?)

Thanks!

Comments

YK85’s picture

hello again,
I was wondering if someone would be able to give me some pointers.

I am not able to find an easy way to show all pending requests for the logged in user (requests user has sent and requests user has received) into one view page.

thank you

dc1258’s picture

Hi!

I am going to pay for the development of a mutual friends block, friend of a friend (people you might know) feature and a feature which will show all users that a user is not friends with. The last feature you would probably be able to use! Let me know if you'd be interested in sharing the cost of it!

YK85’s picture

Are the above listings you mention new features that need to be developed into the core User Relationships module?
If so, is there an estimated cost you are thinking of? thanks!

dc1258’s picture

I would much rather not discuss numbers and such on an open forum. I will email you to discuss.

Just as an FYI for everyone else, once the code is developed it will not be posted or inserted into the module. This is just so I can, hopefully, recoup the cost of development (but not to make a profit.)

pedrofaria’s picture

I guess this feature is solved with #866400: Views filter patch for current user issue too...

YK85’s picture

Hi pedrofaria,

I'm having trouble with this one =/

It seems like all the UR filters, once applied, removes all users who are not in the UR database (requestee/requester). So I can get users with No relationship to current user, but these users all have some kind of relationship with other users. All users without any relationship to anyone are not included.

pedrofaria’s picture

hmmm i agree you...

I can't figure out how to solve this one... I don't know if views can handler sql EXISTS clauses in query builder...

YK85’s picture

Category: support » feature

I'm looking at the field "User relationships: Relationship status" which shows the current logged in user's status with the user as Pending or Approved in the column. Maybe it would be helpful to have a 'No relationship' status as well?

Next I went to the filter "User relationships: Relationship status" which also allows the options Pending or Approved. If I select 'is not Pending' then only Approved is shown, and if 'is not Approved' then only Pending is shown. With a 'No relationship' status, if 'is not Pending' filter and 'is not Approved' filter is selected then 'No relationship' can be shown.

So I guess this is a feature request =)

rafinskipg’s picture

+1 to this feature. I really need it. I can' do it making two filters for 'is not Pending' and 'is not Approved' , and make it work.

I only want to show my non-friends users, so I'll could add them to my friends list.

NathanM’s picture

+2 Subscribing.

capellic’s picture

I also spent quite a bit of time trying to do this through Views UI, but with no luck. I resorted to building a module which uses hook_views_query_alter to alter the query before it's run. Here's the cod that I used:

/**
 * Implementation of hook_query_alter
 *
 * Allows us to alter the query before views executes it. This is good for
 * doing complicated queries that Views UI can't support.
 */
function mymodule_views_query_alter(&$view, &$query) {

  // The view name.
  if ($view->name == 'myview') {
	
    // Build an array of UIDs that the logged-in user already has a
    // relationship with because we want to exclude them from the friend
    // search.
    $remove_uids = _mymodule_get_relationship_uids();
    if ($remove_uids) {
      $query->where[0]['clauses'][] = 'node.uid NOT IN (' . implode(',', $remove_uids) . ')';
    }
  }	
}

/** 
 * 
 * _mymodule_get_relationship_uids
 * 
 * Filters out any users with whom the given user already has a relationship.
 * This could be expanded to allow for specific types of relationships.
 */
function _mymodule_get_relationship_uids($uid=0) {

  if ($uid == 0) {
    global $user;
    $uid = $user->uid;
  }
	
  if ($uid == 0) {
    return array();
  }

  $result = db_fetch_array(db_query("SELECT requestee_id, requester_id FROM user_relationships WHERE requester_id = %d OR requester_id = %d", $uid));			

  if ($result) {
    foreach ($result as $v) {
      $v = intval($v);
      $remove_uids[$v] = $v;
    }
  }

  return $remove_uids;
}

You should also consider putting some help text in the Views UI for any view you override like this. You can do it by adding the following function to the same module.

/**
 * Implementation of hook_help
 *
 * Informs the user of Views UI that this view is being overridden.
 */
function mymodule_help($path, $arg) {

  foreach ($arg as $k => $v) {
    if ($v == '') {
      unset($arg[$k]);
    }		
  }
  $arg_string = implode('/', $arg);

  switch ($arg_string) {
    case 'admin/build/views/edit/myview':
				
      return "<p>" . t('This view is being altered in the "mymodule" module
      to filter out members that the user is already friends with as well as 
      themselves.') . "</p>";		
      break;
  }
}

Reference:
http://api.freestylesystems.co.uk/api/drupal/contributions--views--docs-...

konrad1811’s picture

I just tried this today but no luck :/

I use UR both with OG and have a list of OG members that a user can have relationship [Chat relationship] so that they can chat - have instant online talk...

konrad1811’s picture

Actually I think this could be possible using Action block modification - but I'm not specialist to do that.

I think easiest way is to pass user list [ some view] to some kind of code like Relationship Action and create "invite relationship" links for each who yet does not have such relationship with current user.

I use OG and would like to pass members ID.

diego.pasc’s picture

subscribing

mrf’s picture

Status: Active » Closed (won't fix)

Please have a look at User Relationship Locator.

My aim there is to provide a relevant list of people you may know on the site that you don't currently have a relationship with, and I think that would answer the need here.

If I'm missing something about the use case behind this particular request please just set the status back, and provide what exactly needs to be changed about our current views integration to make this possible.

diego.pasc’s picture

Hi mrf
sounds interesting.
Is it only for Drupal 7? No Drupal6 version?

mrf’s picture

No D6 version, but there is already an issue open discussing that #1399710: please provide ver 6!

mrf’s picture

If you just want to provide a list of everyone you don't have a relationship with without any further filtering or ranking (warning this query may crash your site on larger user lists) try this query.

SELECT users.uid, users.name, ur.rtid from users LEFT OUTER JOIN user_relationships AS ur ON (users.uid = ur.requestee_id AND ur.requester_id = 1) WHERE ur.rtid IS NULL;

Replace ur.requester_id = 1 with the uid you are interested in.

diego.pasc’s picture

Thanks mrf,
I was already aware of that query.... but your module sounds smarter. In any case thanks for your effort :)
Anyway, we are going a bit off thread here.