Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex.k’s picture

That'd be a nice addition. Will try to work it into the module, but I would need to figure out how to add the field to the users table (since that's where it belongs), given the fact that users table is defined in views core.

tayzlor’s picture

subscribing

Liliplanet’s picture

subscribe, thx!

MisterSpeed’s picture

Assigned: Unassigned » MisterSpeed
MisterSpeed’s picture

Category: feature » bug
Status: Active » Fixed
FileSize
2.49 KB

The facility is implemented the listing of other user's relationship is listed and user can send the request to that users.
Please see the patch file for this facility.

jaydub’s picture

Category: bug » feature
Status: Fixed » Needs review

you don't mark an issue as fixed when all you've done is submit a patch!

You have to let the project developers look at your patch and if it's committed to CVS at some later time or in some other form then the issue can be set as 'fixed'...

MisterSpeed’s picture

Hello,

I am the PM here at 63reason. We are new to Drupal.org collaboration (we've been developing our own private modules for years now but never shared back before) and find the process a bit frictional. Namely:

1) We haven't found any good documentation on Drupal.org (at least as visible through Google) on the steps to perform to submit a patch -- in fact the best we found was a document by webchick found here: http://drupalcampmontreal.com/node/14 This should really be integrated into the site here with links easily found.

2) My developer here made a best guess about social norms by using a status that was available to him; if the status isn't acceptable, it shouldn't be listed, period.

I am sharing this comment as I've found the process of collaborating here to be sometimes very frustrating; it seems as if we are to discover by trial and error which social norms prevail. We've had a contributor yesterday decide to get vitriolic with my employees over a different project (the man was sharing bug reports of the "this doesn't work" type without further details, and was resorting to cynicism and negativity as a way to correct his own failed documentation process); this makes the process of learning to enter this community very difficult. If seasoned (formerly closed-source or non-sharing, save for a few exceptions) developers feel that way, I can only guess how many less devoted collaborators feel the same way too.

My criticism is directed at the process and not at you.

That being said, thank you for correcting this and other entries.

jaydub’s picture

http://drupal.org/node/317
Use the issue queue

http://drupal.org/node/156119
Understanding the issue status fields

Please review all the above pages and ask here if you aren't clear on what to do.

Basically the main problem with your actions here is that you were setting a lot of issues as 'fixed' but all you had done is post a patch. For an issue to be marked as 'fixed' - and that should be done by the developers of the module only - it needs to have been committed to CVS if it's a patch or the question asked has been answered to everyone's satisfaction.

The reason it's really important to mark the status properly is because if you marked as 'closed', then people will no longer see the issue on the default view and if you mark as 'fixed' then people who are interested in the issue will assume the module code has been changed to reflect that even though nothing has in fact been added to CVS. And 'fixed' issues will disappear after 2 weeks as they automatically become 'closed'.

Sorry if you feel you're being harshly criticized but marking issues as 'fixed' when they are not requires action to correct so that the issue queue truly reflects the state of the module. If your developers were not clear as to what to do they should have asked first rather than changed statuses w/o being sure of what the status means.

MisterSpeed’s picture

(post #7 was edited and changed while #8 was made)

alex.k’s picture

Assigned: MisterSpeed » Unassigned
Status: Needs review » Active

There are two issues here that I see.
* @63reasons this issue is about http://drupal.org/project/views support. So the patch solves a different problem. Appreciate your help, but in this case we will have to come back to it. Sorry.

* @jaydub thanks for catching. You are factually correct, no question... the wording however leaves room for interpretation, positive or negative. Let us stick to leading by example, don't want to create too steep of a learning curve for contributors.

tayzlor’s picture

@63 reasons :
the documentation here might be of help if you are having trouble with submitting patches - http://drupal.org/patch

andrenoronha’s picture

subscribing

Liliplanet’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs work » Active

Hi,

Does the patch work, and will it be implemented in UR views? Would love this capability, thanx!

k3vin’s picture

+1

Liliplanet’s picture

Hi,

Please can the patch in #5 be included in the next release? That is an action link to be available in views ..

Users can see other users relationships, and then the action to add or remove to their own relationships, much like Facebook does.

Thank you so much for your amazing module!

Lilian

alex.k’s picture

No, the patch does not work for Views, unfortunately.

Liliplanet’s picture

Hi Alex,

Thank you for your quick reply. Alex, will this be forthcoming in user relationships at some time?

It just creates a more quick way for users to add friends to their relationships (ala Facebook), instead of visiting each profile to add the person.

Look so forward to this possible enhancement :)

alex.k’s picture

Yes, I think so. If there is someone familiar Views, for whom it'd be easy to add this, I would be happy to accept a patch. Otherwise this will have to take a backseat to outstanding bug reports :(

Liliplanet’s picture

Just downloaded the latest version, thank you so much!

I don't see an action link in views, which would be amazing, as currently we have to rely on the path /relationships. I would just like other users not to visit a profile to add a relationship, but to see a certain user relationships in a view, and then 'add to my friends' as an action link.

Looking forward to any reply, and thank you again for this tremendous module.

kvvnn’s picture

Manually adding an "Add Friend" link as a Views field

1) Assume we have a view of all of the sites users

2) Add a field for this view of [uid]

3) Rewrite the output of the field as "Add as Friend"

4) Output the field as a link
- The following path would copy the link path that appears on a user's node profile

relationship/[uid]/request/[rid]?destination=user/[uid]

-[uid] should be typed as "[uid]". It is a Views field reference to the user the view is currently spitting out (this is a list of the site's users).

-[rid] should be typed as "1" or "2" or "{your-relationship-id}". It is the id of the "Friend" relationship. You can find it in phpmyadmin under the user_relationships type table. With only the "Friend" relationship created, my id was "1".

-the string after "destination=" is where the user will be directed after successfully creating a friend request. I have it set back to "users", where my list of users is.

If you are looking for a reply from me, please use my personal contact form as well as posting here.

Cheers!

P.S. I am working on making this appear for non-friends only, reply will come soon.

Edit : fixed the url by removing the '/' in the beginning. Thanks to Liliplanet for the mention

Bilmar’s picture

smashinelephant -

Thank you for your post. This will be very helpful once I am able to create this link in views.
I am having some issues with trying to get the Add a Friend link to work.
Currently, the link only sends me the to user's account page.

1. I confirmed that '1' should be used for the [nid] mentioned above.
2. Any Relationships or Arguments needed for this to work?

Thank you and I appreciate your support.

Liliplanet’s picture

That is stunning, works fabulously ..

Just a note the

/relationship/[uid]/request/[nid]?destination=user/[nid]

should be without the first slash /, so

relationship/[uid]/request/[nid]?destination=user/[nid]

Wish we could now pull in the 'remove' from friends as well, but this is great, thank you!

kvvnn’s picture

{ previously smashingelephant }

One, my link was off (I fixed it in #20). Lily's point as well as another regarding the default destination. Here is what the default user_relationship "Add Friend" link is :

relationship/[uid]/request/[rid]?destination=user/[uid]

Where [uid] and [rid] are explained in #20

Two, ensure that this link is the same for you by checking it on node-profile or user profile.

Let us know.

kvvnn’s picture

{previously smashingelephant}

To Remove a Friend in a Views List (unfinished)

Please look below, this advice was all wrong.

alex.k’s picture

Appreciate the great tips, folks. Views integration has not changed between beta10 and rc1 aside from some wording, so this approach will still work. Hopefully I will have time to implement it within UR. Thanks!

kvvnn’s picture

I think that the following module is necessary in order to have both [current user id] and [other's user id's] both as fields: http://drupal.org/project/views_or

Bilmar’s picture

Thank you for all of your support!

kvvnn’s picture

Did you get it working Trupal?

kvvnn’s picture

Removing a Friend from any page that has the friend's ID passed as an argument

http://drupal.org/node/188433#comment-1824164

Bilmar’s picture

kvBushi-

I was able to get it to work with your instructions above.
Trying to now see if this method will work for 'send message to user' with privatemsg.
If you have any ideas please pm me.

Thanks!

kvvnn’s picture

Differentiating between Friends and Non-Friends in Views

1) This code uses Views Custom Field module - http://drupal.org/project/views_customfield
This allows us to write PHP within a Views field

2) My goal was to show site users in the View, exclude them, and then use a PHP field to determine whether they are the logged in user's friend or not. If they are friends, I output their name as a link to their profile (a panel page). If they are not friends, I display a "Send Friend Request" link.

3) This code tests if the [current user] and [user in views] have ANY relationship together. As my site only has a Friends relationships, this is perfect for me.

My Exact Fields
- Uid (excluded)
- Content Profile : First Name (excluded)
- Content Profile : Last Name (excluded)
- Customfield : Php Code

The Customfield has the following code in it :

global $relationships;
global $user;

//if users are friends and relationship has been approved
if ($relationships = user_relationships_load(array('between' => array($user->uid, $data->users_uid),'approved' => 1))) { 
print "This is a friend";
}

//if a friend request has been made between the users, but hasn't been approved
else if ($relationships = user_relationships_load(array('between' => array($user->uid, $data->users_uid),'approved' => 0))) { 
print "You have a pending friend request with this user";
}

else { 
print "This is not a friend, and no request has been made";
} 

Explanation :

global $relationships;
global $user;


$relationships lets you test whether the logged in user and the user currently in the Views list are friends or not
$user lets you use the current user's ID

//if users are friends and relationship has been approved
if ($relationships = user_relationships_load(array('between' => array($user->uid, $data->users_uid),'approved' => 1))) {
print "This is a friend";
}

$data->users_uid is the Views "User: Uid" field. It will be different for you. Notice its not the same as a Views replacement (like [uid]).

The way you find what the uid is for you is by creating PHP Customfield with this in it : print var_export($data, TRUE);. This outputs all of the available fields as variables. You simple do $data -> "some field variable listed by var_export".

$user->uid is the currently logged in user.

My links on "if/else" output also uses the PHP Views field variables, as I print profile links that are set up with a URL argument of user ID.

This IF statement is testing if the two users have a relationships together and if its approved. It does not check for a specific kind of relationship.

//if a friend request has been made between the users, but hasn't been approved
else if ($relationships = user_relationships_load(array('between' => array($user->uid, $data->users_uid),'approved' => 0))) {
print "You have a pending friend request with this user";
}

This tests if their is a pending relationship between the users.

-------------

Good luck! I am usually on irc.freenode.net #drupal-support as "kvn" or "kvnBushi" or something but feel free to PM me here.

Cheers!

kvvnn’s picture

Trupal218, I would LOVE if you figured that out before I get to it!

I will be messing with privatemsg very soon (at least by Monday the 20).

Come on IRC and we'll chat about it : irc.freenode.net #drupal-support , I am kvn.

Post if you get it! Cheers!

kvvnn’s picture

#31 is ugly with exposed filters. Trying to figure out what to do now.

kvvnn’s picture

Also, the code in #31 does not take into consideration whether the Friend request has been approved. With 1 way relationships this shouldn't be an issue. Will post a fix later.

Edited and tested.

chaosprinz’s picture

Hi,
i try to build links in views for approving/disapproving so i think my issue is similar to this one.
What i did:
Created two fields of kind uid. One i gave the relationship 'User relationships: Requestee user' and the other got 'User relationships: Requester user'
Ok, cool. I have the uid of the requested person and the uid of the requesting person.
No i take a look on how the approve-link is build. Its something like this user/1/relationships/requested/3/approve?destination=user/4
The first part 'user/1/' is ok, cause i have all uids i need. The same to the last part 'approve?destination=user/4'
The problem is the center-part 'relationships/requested/3/'
What is this 3 ? Its not the rid, cause the rid is 1. If you could tell me what this is, i could create a third field of custom kind, which prints out this number.

kvvnn’s picture

Read this http://drupal.org/node/188433#comment-1824164

"rid" is the relationship ID unique to the two users. Ickz posted about that earlier in the thread, and I made the code work on a panel page, but haven't tried in Views. It should work fine.

ataxia’s picture

chaosprinz -

I struggled with that also, and eventually created a Views Customfield (for PHP Code) with this code to determine the relationship id (rid). I was then able to plug the rid values into another custom field to create the links:

global $relationships;
global $user;
user_relationships_load(array('between' => array($user->uid, $data->users_uid), 'rtid' => 1));
return $data->rid;

(I'm assuming you already know how to set up the Relationships and Arguments settings, but let me know if you need more info)

Here are the links I created (another custom field) in different Views using the rid that I extracted. The rid value is the [phpcode] token below:

approve:
user/[uid]/relationships/requested/[phpcode]/approve?destination=relationships%2Frequests

disapprove:
user/[uid_1]/relationships/requested/[phpcode]/disapprove?destination=relationships%2Frequests

remove:
/user/[uid_1]/relationships/[phpcode]/remove?destination=relationships%2Frequests

cancel:
user/[uid]/relationships/requested/[phpcode]/cancel?destination=relationships%2Frequests

Hope that helps, if you haven't figured it out already.

- Ataxia

kvvnn’s picture

You should also check if the relationships has been approved or not, ataxia, assuming its a 2 way relationship.

"...rtid => 1, 'approved' => 1"

Bilmar’s picture

Thank you to everyone that has supported this thread.

Ataxia - if you have a chance, could you please provide details for the arugments and relationships setup which you mentioned in #37. I apologize but I am not familiar with the setup at this time =(

Thank you very much in advance!

kvvnn’s picture

Trupal, have you not got it working yet? IM me on aim : tokian00mlf

Bilmar’s picture

Hi kvnbushi-

I haven't been able to get this to work yet =(
Thank you for your AIM screenname and I may have to take up the offer and send you an IM.
However, I am currently living in Tokyo and so our time difference may be pretty big.

If someone could please provide an explanation of the setup process it would be very much appreciated. As noted in #38, I am using a 2-way 'Friend' relationship and may require that validation.

Thank you all very much in advance!

Bilmar’s picture

If possible - would a text paste of the Views export into this thread be possible which I could import in my Views / then study how it all works?

Thanks again!

Bilmar’s picture

I finally got it to work! I watched many screencasts and read tutorials and began to understand what was going on.
Oh man, when it all clicked it felt very good!
Going to continue to play with it more =)

Thank you!

farald’s picture

trupal218, could you post your working code?

Bilmar’s picture

It was the exact code mentioned by ataxia in #37
I just took time to understand how view customfields & tokens worked.
After spending more time reading drupal.org resources it all hit me =)

Thanks again for the support ataxia and kvnn!

andrenoronha’s picture

thanks!

I checked how the module creates the link and copied to use that ajax thing...
so that's my code:

print theme('user_relationships_pending_request_approve_link', $user->uid, $data->rid);
print ' | ';
print theme('user_relationships_pending_request_disapprove_link', $user->uid, $data->rid);
Bilmar’s picture

Hi a.luiz.n

Where did you print the above code?
thanks!

andrenoronha’s picture

In a custom field of my pending requests block.
So it has a field for the username, a field for the user picture, a field with the php code at #37 to get the RID ($data->rid) and the custom field to print the accept or reject relationship links.

kvvnn’s picture

dc1258 messaged me the following. I post my response here for others. #31 above is the post he is referring to.

I am a very new Drupal user and am trying to make a basic website. Quite honestly, all I have the ability to do is upload modules and modify user profiles.

Okay. You need a very good grasp of the Views module to get this to work. As a new user to Drupal, its important you understand there is a steep learning curve in the beginning.

Keeping that in mind I have been trying to find a way to show "friends" and "friends of friends" as separate links on the website and had almost given up, until I saw your post! Just to clarify I would like users to be able to click a link and have it show ONLY friends of friends.

There is actually no way to show "Friends of Friends" in a View as far as I know. It might be possible but I haven't tried. Showing Friends in a View has some issues as well, which #31 addresses. Specifically, you have to consider first WHICH relationship type you want to show, and what to do with different relationship statuses (pending or approved).

How does your idea show up on the website? When you click "my relationships" would it then have tabs for "all" "friends" "pending" and then "friends of friends?" Would it be a block which I would have to place somewhere on the site?

One of my Views shows all users of the website, but prints different HTML depending on if a member is a friend, a pending friend, or not a friend to the logged in user. The other is strictly a list of approved friends of the logged in user.

Either way, I see the code on your post but I have no idea how to implement it and get it to work on the site. Would you be able to give me some instruction? Keep in mind I have very limited knowledge on the issue so I may need "instructions for dummies."

My instructions :
1) Learn Views (this has prerequisites you will find naturally). I HIGHLY recommend lullabot.com's instructional videos (they cost money, and much less of it than a university would charge for less applicable knowledge).
2) Understand what PHP is and how it can control HTML.
3) Understand what variables User Relationships uses for relationship type / pending / approved and review my code in #31 regarding how to get these and how they help you.
4) Learn Views Customfield module and how you can use Views $data objects to print out your HTML values.
5) Message me / post here when you've completed the above, and we'll continue :)

dima700’s picture

@kvnn,
Can you please explain which relationships, arguments and filters you use in view in #31

dima700’s picture

It is clear now. I copied your code as is without changing $data->users_uid. Im my case I have to change to $data->uid
In my case the view works on overrided user page as Panel Page so the argument is User: UID from user page URL
Thank you kvnn

kvvnn’s picture

Yeah, the trick is definitely finding how to reference the values in $data. I posted in the Views_customfield module "starter" issue on how to do that.

Bilmar’s picture

Hello,

I was using #37 before but now facing problems with my new setup using Panels + Views Content Panes to show a list of my friends.

Could someone please assist in getting Request, Remove, Cancel links to work?
dima700 - did you have to do any specific setup for the panels?

Thank you!

altparty’s picture

Just want to share our code with those who are (also) struggling...

global $relationships;
global $user;

//if users are friends and relationship has been approved
if ($relationships = user_relationships_load(array('between' => array($user->uid, $data->uid),'approved' => 1))) {
print "<a href=\"/messages/new/$data->uid\">message</a>";
}

//if a friend request has been made between the users, but hasn't been approved
else if ($relationships = user_relationships_load(array('between' => array($user->uid, $data->uid),'approved' => 0))) {
print "<a href=\"/messages/new/$data->uid\">message</a>|<a href=\"/relationships/requests\">pending</a>";
}

else {
print "<a href=\"/messages/new/$data->uid\">message</a>|<a href=\"/relationship/$data->uid/request/1?destination=user/$data->uid\">add buddy</a>";
}

...where our rid=1.

Jaizhanju’s picture

Hi.. I would like to use customfields to make a field where you the "Add as friend" link if you don't have a relationship and a "Remove from friends" link if you have a relationship.

But I can't seem to get it right, any ideas of how the php would look for such a field?

EDIT: It seems that #54 has much of what I'm looking for, but it doens't work for me. :/
I get a 404 when clicking the link ( relationship//request1?destination=user/ )
so something is wrong with the user varible?

EDIT 2: oh wow.. I can't belive I solved it. I'm still very new to php.

replace "$data->uid" with "$data->users_uid"

Also, thanks for the template! :)

altparty’s picture

In addition to #54

The $data variable is different for every view.
Just try to find out by adding this line to your code: print var_export($data, TRUE);

karc2008’s picture

Hi, I just have a question, on how get started with all of this in views.

I will rewirte this, because i asked to find the unapproved relationships. I found those now.

But i´m still troubled and don´t know, how to do it.

I set up the view as follows:

(If some step is wrong - please tell me (I´m just testing this by trial and error) - but sometimes its possible, that I don´t even see the error, because i´m still very new to drupal and it´s my first site, I want to build with drupal.)

My goal: a view that shows new requests on the profile page. (or better in a tab of the profile page)

I put in at relationships: requester user, requestee user and RTID.

Next I put in the filter Relationship status = 0 with no relationship to anything.

Now I put in two fields User ID (with relationship requester and one with the relationship requestee) this showed up all pending requests, along with the related user ID´s of the source and target.

I put it an argument (User relationships: Requestee user: ID from current logged in user - if validation fails show empty text) to correct this. The result was what I needed. My UID (because i´m currently logged in with the user, to which the request was sent to and the UID, of the user, who sent the request.

Next I put in the field, relationship type.

I know, I should rewrite the ouput and theoretically I got all the data I need, but here i´m stuck, because I´m :

  1. not at all sure, that all I did isn´t a bunch of sh..
  2. the result got displayed 5 times (the number of the users I created for testing), but of course it should be displayed just once. (solved, by setting up the view as relationship)

So at last my questions:

  1. Is all, what I did nonsense?
  2. Why is the result displayed 5 times (like the number of my users, i created for testing)? Should there be another filter active to get rid of it? (this is solved, I started the setup as node beofre, now as relationship)
  3. But how do print the ID. I tried the code at #37 and also other codes on this page, but none of them showed me the "rid". WHat is missing in my view-settings?

Thanks for any help on this,
Marc

karc2008’s picture

deleted

andrenoronha’s picture

karc2008,

use the argument User: uid with a relationship with requestee... that's the way i did it.

karc2008’s picture

HI,

it was already in. - (requestee) User: Uid - (is this correct?)

I see all the data, that is needed. Requester ID, Requestee ID, Releationship "TYPE" ID and relationship status.

Also nothing is doubled anymore (since I set up the view as a relationship-view), also I just see unapproved relationship of the current logged in user. SO this seems to be 100% correct.

But, I just can´t get the request ID, that is needed to approve. I tried all php in this thread one by one, without a result.

if its not in, you will just get the message "approve a request from Guest, because it doesn´t know the request and its connections.

I think from the request ID it also gets the user, who send the request.

Is there another way to approve users? By directly putting in the requesters uid and the requestee uid, without using rid? Because to get the user data is not a big problem.

Once again: I can show, that the request (which needs approval) was made. I can show who sent it and who received it (by uids) and also limit this view to the current logged in user.

Thanks again,
Marc

andrenoronha’s picture

karc2008

I created a field to get the RID:

<?php
  global $relationships;
  global $user;
  user_relationships_load(array('between' => array($user->uid, $data->users_uid), 'rtid' => 1));
  return $data->rid;
?>

and the links to aprove/disaprove:

<?php
  global $user;
  print '<div class="links">';

  print theme('user_relationships_pending_request_approve_link', $user->uid, $data->rid);
  print ' | ';
  print theme('user_relationships_pending_request_disapprove_link', $user->uid, $data->rid);

  print '</div>';
?>
karc2008’s picture

I tried it with your code, but still just shows a link like this:

".../user/1/relationships/requested/%252Fapprove?destination=..."

I guess, there must be something wrong with my view or is it the version of user relationships. I´m using rc3. Which version is installed at your drupal?

I also tried putting in the relationships link. With the same negative outcome. No rid.

Perhaps, if someone is able to understand it, I exported my view to show it. Perhaps some relationship is missing or some data. I tried a lot already (along with putting in all available relationship fields and the link/PHP-Codes at the end.

$view = new view;
$view->name = 'onceagain';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'user_relationship_types';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Standards', 'default');
$handler->override_option('relationships', array(
  'rtid' => array(
    'id' => 'rtid',
    'table' => 'user_relationships',
    'field' => 'rtid',
  ),
  'requestee_id' => array(
    'id' => 'requestee_id',
    'table' => 'user_relationships',
    'field' => 'requestee_id',
  ),
  'requester_id' => array(
    'id' => 'requester_id',
    'table' => 'user_relationships',
    'field' => 'requester_id',
  ),
));
$handler->override_option('fields', array(
  'requestee_id' => array(
    'label' => 'Requestee user',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'text' => '',
    'exclude' => 0,
    'id' => 'requestee_id',
    'table' => 'user_relationships',
    'field' => 'requestee_id',
    'relationship' => 'none',
  ),
  'requester_id' => array(
    'label' => 'Requester user',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'text' => '',
    'exclude' => 0,
    'id' => 'requester_id',
    'table' => 'user_relationships',
    'field' => 'requester_id',
    'relationship' => 'none',
  ),
  'rtid' => array(
    'label' => 'RTID',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'set_precision' => FALSE,
    'precision' => 0,
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => '',
    'exclude' => 0,
    'id' => 'rtid',
    'table' => 'user_relationship_types',
    'field' => 'rtid',
    'relationship' => 'none',
  ),
  'requires_approval' => array(
    'label' => 'Requires approval',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'type' => 'yes-no',
    'not' => 0,
    'exclude' => 0,
    'id' => 'requires_approval',
    'table' => 'user_relationship_types',
    'field' => 'requires_approval',
    'relationship' => 'none',
  ),
  'is_oneway' => array(
    'label' => 'Typ',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'is_oneway',
    'table' => 'user_relationship_types',
    'field' => 'is_oneway',
    'relationship' => 'none',
  ),
  'status_link' => array(
    'label' => 'Status link',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'status_link',
    'table' => 'user_relationships',
    'field' => 'status_link',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'uid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'Alle',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'current_user',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'empty',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
    'relationship' => 'requestee_id',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
    ),
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_image_size' => '_original',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'webform' => 0,
      'blog' => 0,
      'poll' => 0,
      'activitystream' => 0,
      'image' => 0,
      'usernews' => 0,
      'forum' => 0,
      'bali' => 0,
      'bildergalerie' => 0,
      'community' => 0,
      'dynamic_slide' => 0,
      'geschichte_indonesiens' => 0,
      'images' => 0,
      'indonesien_allgemein' => 0,
      'indonesien_allgemein_artikel' => 0,
      'intro_pic' => 0,
      'medien' => 0,
      'page' => 0,
      'politik_indonesien' => 0,
      'profile' => 0,
      'service' => 0,
      'slider' => 0,
      'story' => 0,
      'transport' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'image_size' => array(
      '_original' => '_original',
      'thumbnail' => 'thumbnail',
      'preview' => 'preview',
    ),
    'validate_argument_is_member' => 0,
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'approved' => array(
    'operator' => '=',
    'value' => '0',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'approved',
    'table' => 'user_relationships',
    'field' => 'approved',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('block', 'weiterer test', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
robby.smith’s picture

I am experiencing the same issue mentioned in #62 for instructions given at #61.

When I click the 'approve' link shown in views it takes me to this URL:
www.example.com/user/1/relationships/requested/%252Fapprove?destination=...

And the page says:
"Are you sure you want to approve the relationship request from Guest?" [Yes] [No]
Where it should say:
"Are you sure you want to approve the relationship request from User2?" [Yes] [No]

Would anyone be able to help in getting this to work?

andrenoronha’s picture

karc2008 and robby.smith,

the problem is in the rid.
check your $data variable to look for the user id. mine was '$data->users_uid' but yours can be different.

somewhere in the phpcode of the links put this:

print check_plain(print_r($data));

it will print all the data stored into the array $data.

and look at the result to find the user account id (not the logged user id)

YK85’s picture

hello a.luiz.n

I was able to get your code to work with the kind explanation in #64
I have looked at the $data object and found $data->user_relationships_rid to be used.
I believe this data is available as I added User Relationship in the views relationship.

however, on the page I am getting the below warning=>

warning: Invalid argument supplied for foreach() in /home/example/public_html/sites/all/modules/user_relationships/user_relationships_api/user_relationships_api.module on line 43.

Can anyone help?

YK85’s picture

i continued to try to get it to work and now I dont even see $data->user_relationships_rid in the object

i used print check_plain(print_r($data)); and see [uid] in the array so using $data->uid at the user_relationships_load code in #61
is this correct?

the code below is not outputting anything for me at the moment

<?php
  global $relationships;
  global $user;
  user_relationships_load(array('between' => array($user->uid, $data->uid), 'rtid' => 1));
  return $data->rid;
?>

my view type is User and I created a relationship with Content Profile to display fields

YK85’s picture

This is the output I get=>

PHP code RID test:  Array ( [42] => stdClass Object ( [rid] => 42 [requester_id] => 1 [requestee_id] => 8 [rtid] => 1 [approved] => 0 [created_at] => 1266155196 [updated_at] => 1266155196 [flags] => 0 [name] => Friend [plural_name] => Friends [is_oneway] => 0 [is_reciprocal] => 0 [requires_approval] => 1 [expires_val] => 0 ) ) 1

with this code in a custom field:

<?php
  global $relationships;
  global $user;
  $a = user_relationships_load(array('between' => array($user->uid, $data->uid_1), 'rtid' => 1));
  print check_plain(print_r($a));
?>

print $data->rid nor $a->rid doesnt seem to work

Bilmar’s picture

try the below code to print the rid

<?php
  global $relationships;
  global $user;
  $a = user_relationships_load(array('between' => array($user->uid, $data->uid_1), 'rtid' => 1));
  $rid = key($a);
  print $rid;
?>
YK85’s picture

awesome it worked! (#61 with #68)
many thanks!

YK85’s picture

printing the rid worked..but I'm still getting this error on the page when clicking the link to accept a relationship:

warning: Invalid argument supplied for foreach() in /home/example/public_html/sites/all/modules/user_relationships/user_relationships_api/user_relationships_api.module on line 43.

EDIT: recreating the view made it work. thank you!

esbite’s picture

Here is a modified version of #54 that I use for our site. It's for a view based on user_relationships_browser, adding a relation to content profile so that this code always gets an accurate uid for the user being viewed. Otherwise pending friendships eithier only shows requestees or reqesters depending on the argument you're using.

This was ridicously hard to get to work. It would be great if the view could provide this kind of field, dynamically showing Add/Remove/Approve/Decline/Cancel.

global $user;

// Get the currently viewed users id via content profile relation in the view
if(is_numeric($data->node_users_user_relationships__users_uid)) {
	$uid = $data->node_users_user_relationships__users_uid;
} else {
	$uid = $data->node_users_user_relationships_1__users_uid;
}

//if users are friends and relationship has been approved
if ($relationships = user_relationships_load(array('between' => array($user->uid, $uid),'approved' => 1))) {
	// The array is keyed by rid, so use array_shift to get the first one
	$rel = array_shift($relationships);
	print theme('user_relationships_remove_link', $user->uid, $rel->rid);
}

//if a friend request has been made between the users, but hasn't been approved
else if ($relationships = user_relationships_load(array('between' => array($user->uid, $uid),'approved' => 0))) {
	// The array is keyed by rid, so use array_shift to get the first one
	$rel = array_shift($relationships);
	if($rel->requester_id != $user->uid) {
		// The other user sent this request, show approve links
	  print theme('user_relationships_pending_request_approve_link', $user->uid, $rel->rid);
	  print ' | ';
	  print theme('user_relationships_pending_request_disapprove_link', $user->uid, $rel->rid);
	}else{
		// The current user sent this request, show cancel link
		print theme('user_relationships_pending_request_cancel_link', $user->uid, $rel->rid);
	}
}

else {
	// If were not watching ourselves, print add contact link
	if($user->uid != $uid) {
		// Can't get this theme call to work, print link manually
		//print theme('user_relationships_request_relationship_direct_link', $uid, 1);
		print "<a href=\"/relationship/$uid/request/1?destination=user/$uid\">".t('Add contact')."</a>";
	}
}
YK85’s picture

Any chance someone here is willing to kindly help improve UR-Views integration? I am not sure what is needed (ie UR views handlers etc) but there are many issues with UR-Views usage reported in the issue queue.

I (and the community) would appreciate it very much!

Thank you

dc1258’s picture

I tried this code in Views using the Views PHP Filter module (http://drupal.org/project/viewsphpfilter) but all it does is take you to this link: http://localhost/relationship//request/1?destination=user/ and it does not show anything. Does anyone know why this is or if the above code works? If it works how should I implement it?

Thanks!

drupalina’s picture

Subscribing.
I think it is essential that User Relationships module has a working solution for "Request relationship" filed in Views, as well as working with one-way reciprocal relationships which do not require approval.

Until then, can someone please post a code for 1-way relationship (Follow) using the Views and Custom PHP filed?

drupalina’s picture

Thanks to the maintainers of this thread!
Since the maintainers of UR are not planning to incorporate a working "UR actions" field for Views, I (and I'm sure, many others who will be banging their heads against the wall in the future) would appreciate if someone could post a working solution (or snippets and tutorial) for others users who have the increasingly popular Twitter-style 1-way reciprocal relationships, and wish to print theme('user_relationships_request_relationship_direct_link($relate_to, $relationship_type)) function from UR, which links to the AJAX popup.

In my case, I have a Twitter-style 1-way follow/following relationships, so there is no approve/disapprove workflow. People just follow each other. In the views listings of other people's followers I want to display a Follow or Following/Un-follow links (depending on whether the logged in user is following that user or not).

In my custom field I've typed print var_export($data, TRUE); and this is the data variables that I get:
stdClass::__set_state(array(
'rid' => '128',
'users_user_relationships_1_picture' => '',
'users_user_relationships_1_uid' => '115',
'users_user_relationships_1_name' => 'Random Name',
'users_user_relationships_1_mail' => 'random@yahoo.com',
'user_relationships_requestee_id' => '161',
'user_relationships_requester_id' => '115',
'user_relationships_approved' => '0',
'user_relationships_rtid' => '3',
'users_user_relationships_1__user_relationships_created_at' => NULL, ))

So far I have the following code

<?php
  global $user;
  print theme('user_relationships_request_relationship_direct_link', $data->users_user_relationships_1_uid, $data->user_relationships_rtid);
?>

but for the most bizarre reason it produces a link that looks like
http://example.com/en/relationship/%252Frequest?destination=user%2F161%2...
whereas it should be
http://example.com/en/relationship/115/request/3?destination=user/161/fo...

When I say print $data->users_user_relationships_1_uid; it prints the user id of that user with no problem. My relationship id is 3. But for some reason these do not get incorporated into the URL.

the same returns with the following code that I constructed using postings from this thread:

<?php
global $relationships;
global $user;
user_relationships_load(array('between' => array($user->uid, $data->user_relationships_requester_id), 'rtid' => 3));
// return $data->user_relationships_requester_id;

  print theme('user_relationships_request_relationship_direct_link', $users_user_relationships_1_uid, $user_relationships_rtid);
?>

but if I do a manual link <a href="/relationship/<?php print $data->user_relationships_requester_id ?>/request/3">Follow this user</a> then it produces a simple link with the correct URL structure (but then you can't have the AJAX popup which comes with ?=destination, and you can't have the mechanism for checking if the logged in user is already following this user or not)

Can someone please (!) post the correct code to input into the custom field? I've been trying to solve this for many days now. Please! You'll be doing a lot of people a big favor!

Many thanks in advance!

dimitriz1’s picture

I cannot believe that this issue is still outstanding. After all the great work that has gone into the user relationships module this most basic, yet essential, feature is still missing - Being able to add/remove friends in a field in a view. Look at Facebook, you click 'See all' on the friends block and they show a 'view' of all the users friends with an Add as Friend link beside everyone.

Could one of the maintainers please finally add this feature so it can save all the users of UR like myself hours of banging our heads against the wall trying to get the workaround posted above working. It seems UR already has alot of views integration I dont understand what the problem is that makes this feature so hard to add? This feature will be highly appreciated.

manoz_79’s picture

I have tried every suggestion given in this thread, and some other threads, I give up... I am pasting my views code below, can someone point the mistake i am making, it would be of tremendous help. I want to display a link to 'Remove Friends', the view shows my exiting friends.

$view = new view;
$view->name = 'user_relationships_my_friends';
$view->description = 'My Friends';
$view->tag = 'friends';
$view->view_php = '';
$view->base_table = 'user_relationships';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'requestee_id' => array(
'label' => 'requestee',
'required' => 0,
'id' => 'requestee_id',
'table' => 'user_relationships',
'field' => 'requestee_id',
'relationship' => 'none',
),
'requester_id' => array(
'label' => 'requester',
'required' => 0,
'id' => 'requester_id',
'table' => 'user_relationships',
'field' => 'requester_id',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'rtid' => array(
'label' => 'rtid',
'required' => 0,
'id' => 'rtid',
'table' => 'user_relationships',
'field' => 'rtid',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'uid' => array(
'label' => 'Uid',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_user' => 0,
'exclude' => 1,
'id' => 'uid',
'table' => 'users',
'field' => 'uid',
'relationship' => 'requestee_id',
'override' => array(
'button' => 'Override',
),
),
'picture' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'exclude' => 0,
'id' => 'picture',
'table' => 'users',
'field' => 'picture',
'relationship' => 'requestee_id',
),
'markup_1' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'value' => 'Only local images are allowed. print base_path();sites/all/themes/iiwy/img/freind_small_icon.png" alt="friend">',
'format' => '3',
'exclude' => 0,
'id' => 'markup_1',
'table' => 'customfield',
'field' => 'markup',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'name' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_user' => 1,
'overwrite_anonymous' => 0,
'anonymous_text' => '',
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'requestee_id',
),
'markup' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => 'Ask a question',
'make_link' => 1,
'path' => 'messages/new/[uid]?destination=user/[uid]',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '_blank',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'value' => 'Only local images are allowed. print base_path();sites/all/themes/iiwy/img/ask_question_2.png" alt="ask a friend">',
'format' => '3',
'exclude' => 0,
'id' => 'markup',
'table' => 'customfield',
'field' => 'markup',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'markup_3' => array(
'label' => 'RID',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'value' => '

  global $relationships;
  global $user;
  $a = user_relationships_load(array(\'between\' => array($user->uid, $data->uid_1), \'rtid\' => 1));
  $rid = key($a);
  print $rid;

',
'format' => '3',
'exclude' => 0,
'id' => 'markup_3',
'table' => 'customfield',
'field' => 'markup',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'markup_2' => array(
'label' => 'url_rid',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'value' => '


// Remove Friend Default Link is
// /user/[currently logged in user ID]/relationships/[unique relationship ID]/remove?destination=user/[uid]
// [unique relationship ID] is NOT the same as the "Friend" relationship type ID, it is a unique ID between these two users

global $user;
// get an array of the relationships between [logged in user] and [user ID]
// in this example [user ID] is found by looking at the URL argument #1, which lies at site.c0m/arg0/arg1
// this array is being sorted by relationship-type-ID
$current_relationships = user_relationships_load(array(\'between\' => array($user->uid, arg(1))), array(\'sort\' => \'rtid\'));

// this looks at the first relationship-type-ID given by the above, and grabs its unique ID
// since my "Friend" relationship has an ID of 1, the first argument here contains a 1
$friend_rid = $current_relationships[\'1\'][\'0\']->rid;

// this prints Remove Friend link using the Remove Friend default syntax, with a custom destination
print "<a href=/user/" . $user->uid . "/relationships/" . $friend_rid . "/remove?destination=/home>Remove This User as a Friend</a>";

',
'format' => '3',
'exclude' => 0,
'id' => 'markup_2',
'table' => 'customfield',
'field' => 'markup',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'approved' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'approved',
'table' => 'user_relationships',
'field' => 'approved',
'relationship' => 'none',
),
'rtype' => array(
'operator' => 'in',
'value' => array(
'0' => '1',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => 'rtype_op',
'label' => 'User relationships: Relationship type',
'use_operator' => FALSE,
'identifier' => 'rtype',
'remember' => FALSE,
'single' => TRUE,
'optional' => TRUE,
'reduce' => FALSE,
),
'id' => 'rtype',
'table' => 'user_relationships',
'field' => 'rtype',
'relationship' => 'none',
),
'uid_current' => array(
'operator' => '=',
'value' => '0',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'uid_current',
'table' => 'users',
'field' => 'uid_current',
'relationship' => 'requestee_id',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'my friends');
$handler->override_option('style_plugin', 'grid');
$handler->override_option('style_options', array(
'grouping' => '',
'columns' => '2',
'alignment' => 'horizontal',
'fill_single_line' => 1,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'my-friends');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);

Shadlington’s picture

Subscribing

miaoulafrite’s picture

sub

gateway69’s picture

Can this be used in a theme, I would like to theme certain nodes, and if not a friend in UR, then display add X as a friend, with maybe the thumb of the friend? , sorry to hijack but I have been looking for a solution for this

jrivelli’s picture

subscribe

troyl’s picture

Having this by default in views would be great, however for a site I am building we had to do this to get it working, to print just the "Add to friends link"

In a view which must have argument UID from the URL and add a field UID, however make sure you have not linked it to the user profile, and hide it's display or if you want to show the UID, that's up to you.

Then add a global text field and put this into it

<a href="/relationship/[uid]/request/1?destination=user%2F[uid]" class="user_relationships_popup_link">Add as Friend</a>

this will print ajax popup confirmation form for adding the user. However, it would not check if the user is a friend or not. so it will print it even if you are friends with the user. Because in my code the user gets "hidden" after adding as a friend, so it suits my needs, but may not yours.

However, the better approach is using the following code

However if you want to add both add and remove then use views customfield and create a field and add this,


//add link
global $user;
$account = user_load(%user:uid);
$actions = _user_relationships_ui_actions_between($user, $account);
if (count($actions)) {
  print theme('item_list', $actions);
}

//remove link
$actions = _user_relationships_ui_between($user, $account);
if (count($actions)) {
  print theme('item_list', $actions);
}

The argument should be UID from the URL, because user relationship takes the argument of the user id and rtid.

Hope this helps anyone

likewhoa’s picture

Subscribing.

mouse77e’s picture

Subscribing - Really need to be able to simply add friends on the site...

cbovard’s picture

Here is the code I used in a view (views-view-field.tpl.php) User:uid field override:

global $relationships;
global $user;
if ($relationships = user_relationships_load(array('between' => array($user->uid, $row->uid),'approved' => 1))) {
	//remove the friend
	//print "This is a friend";
	//------------------------
	print theme('user_relationships_remove_link', $user->uid, $row->uid);

}else if ($relationships = user_relationships_load(array('between' => array($user->uid, $row->uid),'approved' => 0))) {
	//if a friend request has been made between the users, but hasn't been approved
	//print "You have a pending friend request with this user";
	//--------------------------------------------------------
    if($rel->requester_id != $user->uid) {
        // The other user sent this request, show approve links
      print theme('user_relationships_pending_request_approve_link', $user->uid, $row->uid);
      print ' | ';
      print theme('user_relationships_pending_request_disapprove_link', $user->uid, $row->uid);
    }else{
        // The current user sent this request, show cancel link
        print theme('user_relationships_pending_request_cancel_link', $user->uid, $row->uid);
    }
}else{
	//no relationship add user as friend
	//print "This is not a friend, and no request has been made";
	//---------------------------------
	print "<a href=\"/relationship/$row->uid/request/1?destination=user/$row->uid\">".t('Add contact')."</a>";
}

Hope this helps someone.

Cheers
Chris Bovard
www.chrisbovard.com

parashutiki’s picture

subscribe

Drake’s picture

subscribe

youkho’s picture

sub

dawehner’s picture

Status: Active » Needs review
FileSize
2.47 KB

Here is a patch for this.

The naming of the field handler is not parallel to the other ones provided by user_relationship_views. This is how views suggests the naming.

dawehner’s picture

FileSize
2.47 KB

New version.

Even if you just add some help text you should still look whether the code works :)

BenK’s picture

Subscribing and will help test the latest patch.

AntiNSA’s picture

Priority: Normal » Critical

subscribing

BeaPower’s picture

Can someone tell me if the patch was applied- to dev or current stable 6.0 version?

AntiNSA’s picture

I really need this. I odont understand how to use the new git system to run patches.

AntiNSA’s picture

#90 does not work for me. do you need to add a relationship toget the link to appear or doanything other than run the patch, which creates one new fileand patches another?

AntiNSA’s picture

Status: Needs review » Needs work

I add User relationships: User relationship actions User relationship actions in my view, but no link appears.

Shadlington’s picture

I imagine you have to add a field. Just guessing though, really.

AntiNSA’s picture

I added the field "User relationships: User relationship actions" and there is no link visible.

mbasfour’s picture

the same as #98 subscribing

mordek’s picture

In the file: user_relationship_handler_field_user_relationship_actions.inc
Line 20
It`s: if (module_exists('user_relationship_ui')
Should be: if (module_exists('user_relationships_ui')

AntiNSA’s picture

Awesome/ This fixes it. I think status should be changed.

AntiNSA’s picture

I really need to get this in a dropdown menu.... or grouped.... starting a new issue...

I am using this http://drupal.org/node/409432#comment-4361388 to add an add friend link in views... and it is creating a huge billuted list which totally breaks my site layout...
Become 's Lover
Become 's Classmate
Become 's Boyfriend
Become 's Girlfriend
Become 's Teacher
Become 's Student
Become 's coworker
Become 's Boss
Become 's Mother
Become 's Father
Become 's Sister
Become 's Brother
Become 's spouse
Become 's Cousin
Become 's Aunt
Become 's Uncle
Become 's Nephew
Become 's Niece
Become 's Alumni
Become 's Associate
Become 's Fan of
Become 's Friend

is a huge bulleted list

If thus could be changed to an ajax popup, or dropdown menu or something that would be great. Otherwise I may have to remove all other relationship roles as only option.

I created an issue for this here:
http://drupal.org/node/1130562

AntiNSA’s picture

Also, how can this be change to use an icon, rather than textual link?

mbasfour’s picture

where is the file in the #100 comment

Sansui’s picture

Works once the typo mentioned in #100 is fixed. Still produces "Become 's relationship" - can't seem to get the username in there.

Ended up just overriding the theme function for that link to display as "Send a %rel_name request"

brunorios1’s picture

subscribing...

AntiNSA’s picture

Status: Needs work » Active

plase tell me how to use icon instead of a link?

AntiNSA’s picture

pleeeeaseeee icccon :)

AntiNSA’s picture

This creates a bulleted list with a
before... makes it very difficult to include in my theme. I really would like an icon, but thats another thread. how cna I remove the buillet and the
? THanks!

mbasfour’s picture

where is the file in the #100 comment i can't find it to fix it .

mrf’s picture

Priority: Critical » Normal
Status: Active » Needs review
FileSize
2.56 KB

Here's a reroll of dereine's patch from #90.

  • module name fix from #100 is in there.
  • updated variable names to match rest of module
  • passed in the user name to the action function

I'd like to do a separate patch to rename all these handlers to the views convention as mentioned in Dereine's comment, but might make sense to have this one follow UR's convention until then.

thomjjames’s picture

subscribing +1

thomjjames’s picture

Hi,

Adding a new patch which cleans up the name convention of the views handler & include file.

Not sure if the patch is formatted right? I followed http://drupal.org/node/1054616 using:

git format-patch origin/[version] --stdout >  [description]-[issue-number]-[comment-number].patch

Please let me know if there's an issue and i'll roll it out again.

Cheers
Tom

AntiNSA’s picture

so Im confused, is 113 in addition to 111, or is it a replacement?

thomjjames’s picture

@AntiNSA - #113 is meant to be a replacement of #111 (although code is basically the same minus same name conventions) but that kind of depends what people think works the best as both passed the bot test.

Cheers
Tom

AntiNSA’s picture

any chance this can be commited soon?

Liliplanet’s picture

subscribe thx!

AntiNSA’s picture

Is it possible to use the iicon which is diplayed under the users picture on the profilae page instead of a text link, and is it possible to not show a link for anonymous to be their friend?

AaronBauman’s picture

re #113: why user hook_views_data_alter()?
why not just put it into hook_views_data()?

otherwise works great

brunorios1’s picture

i applied the patch #113...

there's not a link to "remove" a user with relation already approved?

thanks...

Anonymous’s picture

+1 for D7

hlan’s picture

+1

Liliplanet’s picture

+1 for D7, thx!

Liliplanet’s picture

I've tried the patch but seems to be for D6, looking most forward to D7 ability to add a link in views, thank you :)

mrf’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
FileSize
1.91 KB

Here is a patch for D7.

Haven't tested this yet, but wanted to post what I think should be a working patch before I forget about it.

I moved the views_data definition to the data block with all the other fields as suggested above and dropped the line from hook_views_handlers since I couldn't find that for d7 and assume views changed.

Berdir’s picture

Status: Needs review » Needs work

- hook_views_handlers() doesn't exist anymore, that's correct, however, you need to add the new files to the files[] declaration in the .info file now.

+++ b/user_relationship_views/views_handler_field_user_relationships_actions.incundefined
@@ -0,0 +1,28 @@
+/**
+ * @file
+ * Provide field with available actions for a given uid ¶
+ */
+class views_handler_field_user_relationships_action_links extends views_handler_field {

Trailing space and missing .

Also, you should add a second docblock for the class (which can contain the same text).

+++ b/user_relationship_views/views_handler_field_user_relationships_actions.incundefined
@@ -0,0 +1,28 @@
+    global $user;
+    $requester =& $user;
+
+    $requestee = new stdClass();

No clue what this code is doing, but it *really* wrong. It overrides the global user object for now obvious reason? And it doesn't even change it back, which means that this changes the currently logged in user.

+++ b/user_relationship_views/views_handler_field_user_relationships_actions.incundefined
@@ -0,0 +1,28 @@
+    $requestee = user_load(array('uid' => $values->{$this->aliases['uid']}));

The argument to user_load() must now be a single uid, not an array with a uid key, that leads to fatal errors.

+++ b/user_relationship_views/views_handler_field_user_relationships_actions.incundefined
@@ -0,0 +1,28 @@
+    if (module_exists('user_relationships_ui') && $actions = _user_relationships_ui_actions_between($requester, $requestee, array('add' => 1, 'requested' => 1, 'received' => 1))) {
+      return theme('item_list', $actions);

We should at least also add the module_exists() check to the hook_views_data() declaration, so that the field doesn't show up if you haven't installed it.

Also, _user_relationships_ui_actions_between() has been renamed to user_relationships_ui_actions_between() (no _ prefix)

mrf’s picture

Yeah, this definitely needs some work.

Part of my motivation for moving this over to 7.x was that this patch on 6.x was not returning the expected actions in a predictable way, and I thought some changes outside of this patch might be necessary as well, but it is also quite possible the patch is the source of the problem.

I'll try to take another look at this soon.

Berdir’s picture

It's not as bad as I initially thought, I didn't notice that the upper code is $requester and the one below is $requestee, but still, it's weird and mostly unecessary.

BeaPower’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs work

Will this be committed into any of the releases?

Liliplanet’s picture

Hope this is not changing the thread, but I solved this by creating an action link (field) in views by:

'rewrite results' and 'output this field as a link'

relationship/[uid]/request/?destination=user/[uid]

Slight problem is that after you make your relationship request, it returns to the user page and gives error You are not permitted to create any more relationships with this user.

I've tried relationship/[uid]/request/?destination=home but still no joy ..

In the user template the return works fabulously :)

Please how would I setup the link in the field that would return to the previous page that you setup as a view for new relationship requests.

diego.pasc’s picture

Hi,

first of all thanks for the suggestions in this thread: very useful.

For me [Drupal 6.19, Views 2.11 and User Relationship with just one rid (rid=1)] the solution #31 works almost fine.

My problem is only on the javascript side:
I wanted the nice popup window to confirm a request. Then I added also the class "user_relationships_popup_link":


global $relationships;
global $user;

//if users are friends and relationship has been approved
if ($relationships = user_relationships_load(array('between' => array($user->uid, $data->uid),'approved' => 1))) {
// I do not want to print anything in this case
}

//if a friend request has been made between the users, but hasn't been approved
else if ($relationships = user_relationships_load(array('between' => array($user->uid, $data->uid),'approved' => 0))) {
// I do not want to print anything in this case
}

else {
// Print the link to "Add as Friend"
print "<a href='relationship/$data->uid/request/1?destination=my_own_destination' class='user_relationships_popup_link'>".t("Add as Friend")."</a>";
}

This pop-up appears and works as long as I don't not filter my view (with an ajaxified exposed filter) or I click on a pager item (which is also ajax).
Then clicking on "add as friend" does not popup anything but leads to the normal page to confirm a relationship request.

I understand why this is happening but I do know a nice and clean workaround to re-bind the click events
Ideas?

Thanks

Anonymous’s picture

until there will be a working solution i just manually removed all the titles from the "user_relationships-actions_block.tpl.php" and used css to put it to the place i want.

regards

wahn’s picture

Hi Liliplanet
I have the same issue with the destination for new relationship, did you manage to find a solution ?
Cheers

BeaPower’s picture

any updates?

mrf’s picture

Thinking #1443248: Re-implement actions as a field might be a better direction for this.

zuzu83’s picture

To add a link creation in relation to views will have one simple way:

1 - In addition to the "UID" and tick "exclude from display"
2 - Add a field "Global Text"
3 - In the text field write only the text to appear without code
4 - Always in "Global Text" go to "rewrite the result"
5 - Check the boxes "Display this field as a link" & "Use an absolute path"
6 - Insert the url "relationship/[uid]/request/1?destination=user/[uid]" in "Path to link"
7 - Add "user_relationships_popup_link" in "class of link" to show in popup
8 - And save the configuration

In step after -6 "....../request/1" change to the identifier of the relationship you want to view. "1" being my first relationship.

A little tinkering but it works very well

Anonymous’s picture

@ charlie...
that doesnt work...the [uid] wont assigned to the appropriated user.
and how could i hide or replace this field with an "remove friend" link if the relationships between users are approved? right now the link is always shown and if i click it there comes "this user does not exists"

grasmash’s picture

Status: Needs review » Needs work

I've created a patch to supply this feature, see:
http://drupal.org/node/1513726

*Update* posting patch below.

grasmash’s picture

Status: Needs work » Needs review
FileSize
5.66 KB

I've put together a preliminary patch to add a new Views field-- Create/Remove relationship link.

It may need a bit of subsequent work. If you'd grant me commit access to the module repository, I'd be happy to help maintain the Views submodule and ensure that this new feature is stable.

mrf’s picture

Status: Needs work » Needs review

If you are interested in helping with our views integration please have a look at http://drupal.org/project/issues/user_relationships?categories=bug&compo...

Both Berdir and I tend to work in patches, especially for any larger changes, so feel free to post patches wherever you find an issue that you would like to see fixed. After we have a chance to review some patches there is definitely enough work to bring on another co-maintainer.

grasmash’s picture

mrf’s picture

After a quick look at this comparing it to what was previously posted I think the main question is to decide whether to just go with madmatter's hard-coded approach to the links or to rely on user_relationships_ui_actions_between to provide the appropriate list.

One upside to the actions function is it also allows you to work with pending relationships, which I'm sure will be asked for eventually if we go with madmatter's patch.

I have a feeling that the actions function is one of the reasons the first patch behaves unpredictably, but I do like the idea of re-using what is provided elsewhere.

Maybe a separate patch to clean up actions_between and then use that here?

Berdir’s picture

Agree that re-using that function is the proper way.

To make it more predicatable, maybe do something like this:

- Add an additional argument to that function that allows it to be limited to selected relationship types, which is what the patch from madmatter allows (separate issue)
- Then we can expose both the action type (e.g. add/delete/approve... ) and the relationship type to the UI with either a multivalue select or checkboxes and make it much more predictable.

BeaPower’s picture

Is the patch going to be applied to the dev? When?

jyotisankar’s picture

Hi
It can be done very easily using the code that you need to use in your's view's template file. Following is am example which also includes, once you already have a friend from the list of users than in your search results either you can remove those users or you can mention that he/she is already your friend. Refer below for the code.

	
	$result=db_query("SELECT CASE WHEN uid=:uid THEN friend_uid ELSE uid END as ids FROM {flag_friend} WHERE friend_uid=:uid OR uid=:uid",array(":uid"=>$user->uid));
	
	$arrId = array();
	foreach($result as $rs){
		$arrId[] = $rs->ids;
	}
	  foreach ($rows as $row_count => $row): 
print implode(' ', $row_classes[$row_count]); ">
print $row['field_full_name'];
print $row['field_company_name1'];
print $row['name'];
print $row['field_chapter1'];
print $row['field_region1'];

if(!in_array($row['uid'],$arrId)){

print $row['uid'];?destination=user/ print $row['uid'];">Add Friend

}

endforeach;

grasmash’s picture

Status: Needs work » Needs review
FileSize
10.74 KB

@berdir

I've modified the patch to utilize user_relationships_ui_actions_between(). It required a number of subsequent changes, which may or may not be desirable.

  • user_relationships_ui_actions_between() must accept a new $rtids parameter
  • user_relationships_get_requestable_rtypes() should also accept new $rtids parameter, to allow limitation of return $action_types['add'] items. The alternative would be to duplicate much of user_relationships_get_requestable_rtypes(), which doesn't seem preferable
  • lastly, user_relationships_types_load() should also accept the $rtids parameter, unless we make a direct db call in user_relationships_get_requestable_rtypes().

I should also mention that by changing this approach, we're losing the ability to customize the link text via the Views UI, and the ability to demark the action type via a views-field css class.

By contrast, we're making the rendering of all action links consistent. One immediate benefit (as opposed to the old patch) is that ajax confirmation works with this approach.

Berdir’s picture

That is probably a yes to the first two points, but you can then simply loop over user_relationships_types_load($rtid) because that function is statically cached anyway.

Status: Needs review » Needs work

The last submitted patch, user_relationships-action_views_field-409432-146.patch, failed testing.

grasmash’s picture

Status: Needs review » Needs work

This patch failed testing, but I don't think it's due to patch itself. Seems like the failure is related to an internationalization problem. Maybe a recent commit created that issue?

@berdir: do you want me to change the patch to loop over user_relationships_types_load()? I liked the idea of being able to load a list of multiple, specified relationship types via user_relationships_types_load().

hedley’s picture

Have been testing this patch. in function user_relationships_ui_actions_between() adding the parameters to an array $params is causing some issues as depending on the context the $viewed and $viewer are different.

E.g in $action_types['requested']

'requester_id' => $viewer->uid, 'requestee_id' => $viewed->uid

But in isset($action_types['received']

'requester_id' => $viewed->uid, 'requestee_id' => $viewer->uid

Here's a re-factored patch without the $params which seems to work for me

mrf’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, user_relationships-action_views_field-409432-150.patch, failed testing.

hedley’s picture

Status: Needs work » Needs review
FileSize
10.16 KB

Forgot to add the new views_handler_field_user_relationships_action.inc file to the previous patch, created a new patch with the file added.

Status: Needs review » Needs work

The last submitted patch, user_relationships-action_views_field-40932-153.patch, failed testing.

BeaPower’s picture

any updates for this being committed?

Simon Georges’s picture

Component: Code » Views

Changing component.

drewish’s picture

Status: Needs work » Needs review
drewish’s picture

I don't think the changes to user_relationships_types_load() that hedley made in #146 make sense. It basically will get a partial list of relationships cached. We should be calling user_relationships_type_load() and passing in the rtid if we need a specific relationship type.

We definitely don't need to allow passing rtids to user_relationships_get_requestable_rtypes() since it's result are keyed by id so we can just do some simple array manipulation to find the specific ones.

I think in user_relationships_ui_actions_between() it would make the most sense to just request all the relationships between the two users up front in a single query then let each subcase look for the relevant records.

I didn't think it made sense to call user_relationships_type_load() on every call to render since it's basically just checking the id.

I added checkboxes to the option form for selecting the enabled actions.

Personally I'd love to be able to override these messages. I think it might be better to split up the logic for deciding which actions can take place between two users and the link/message building in user_relationships_ui_actions_between(). I'm not going to take that on here though.

drewish’s picture

Oh, I realized my patch doesn't include the tests checking in_array($relationship->rtid, $rtids).

drewish’s picture

Fixing a parse error.

I think I'm going to fork this view field handler for some custom functionality. I really need different messages and a much simpler usage.

ajmartin’s picture

any updates for this being committed?

Berdir’s picture

any updates on this being working? ;)

As soon as @drewish posted those patches (thanks!), this issue got immediately silent and not a single user confirmed this to be working or provided any sort of feedback.

franxo’s picture

#160 works for me

Thanks!!!!!

djween’s picture

I used the patch in #160 and receive warning message:

Notice: Undefined variable: rtid in user_relationships_ui_actions_between() (line 66 of /home/djween/public_html/sites/all/modules/user_relationships/user_relationships_ui/user_relationships_ui.module).

thanks

AntiNSA’s picture

any updates?

sol0matrix80’s picture

question what relationship is needed for this link to work i have tried adding all users relationships one by by one and still no link is being output what am i doing wrong? this is a view of users

jhedstrom’s picture

This is basically the same patch as #160, but I added the field to the User Relationships group, and fixed the notice that was mentioned in #164.

aalireza’s picture

Opps!!

i want add link in views.

what i gone be do ? which patch must be use ?

i need add Relationship in views?

please help.

jhedstrom’s picture

Updated #167 to include 2 additional notice fixes.

Neograph734’s picture

I know this it is an old topic, but patch applied flawless against dev and works as expected. (It only took me some time to figure out that both roles need permission to have relationships of a certain type.)

I'd say this is RTBC.

heylookalive’s picture

@jhedstrom sorry as it's been a while, will this patch take into account the addition of machine name to the UR type?

heylookalive’s picture

Status: Needs review » Fixed

Reviewing the patch this will work with the machine name change. On machine name there are lots of places to start looking at replacing (e.g. theming functions and URLs) Ids with machine names.

This issue has run 100+ comments and brings a new feature that will work. Committing the patch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.