Include an add to friends link in views

hamaldus - March 21, 2009 - 15:53
Project:User Relationships
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

The views support in User relationships should include an option to add a field for the display of an "add to friends" link.
That way, users may brows other user's relationships lists, and optionally add friends right from the list (like facebook).

#1

alex.k - March 27, 2009 - 08:44

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.

#2

tayzlor - March 30, 2009 - 11:19

subscribing

#3

Liliplanet - April 9, 2009 - 10:04

subscribe, thx!

#4

63reasons - April 13, 2009 - 11:33
Assigned to:Anonymous» 63reasons

#5

63reasons - April 30, 2009 - 09:48
Category:feature request» bug report
Status:active» fixed

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.

AttachmentSize
users_relationship-409432.patch 2.49 KB

#6

jaydub - May 7, 2009 - 06:24
Category:bug report» feature request
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'...

#7

63reasons - May 7, 2009 - 20:34

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.

#8

jaydub - May 7, 2009 - 20:22

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.

#9

63reasons - May 7, 2009 - 20:28

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

#10

alex.k - May 7, 2009 - 23:35
Assigned to:63reasons» Anonymous
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.

#11

tayzlor - May 8, 2009 - 09:04

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

#12

a.luiz.n - May 11, 2009 - 19:00

subscribing

#13

Liliplanet - May 20, 2009 - 19:09

Hi,

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

#14

bit7 - May 21, 2009 - 15:37

+1

#15

Liliplanet - June 10, 2009 - 12:09

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

#16

alex.k - June 10, 2009 - 12:53

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

#17

Liliplanet - June 10, 2009 - 13:25

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 :)

#18

alex.k - June 10, 2009 - 13:37

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 :(

#19

Liliplanet - July 8, 2009 - 14:26

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.

#20

kevin riggen - July 13, 2009 - 15:42

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

#21

trupal218 - July 13, 2009 - 22:53

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.

#22

Liliplanet - July 13, 2009 - 09:18

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!

#23

kevin riggen - July 13, 2009 - 15:45

{ 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.

#24

kevin riggen - July 17, 2009 - 20:34

{previously smashingelephant}

To Remove a Friend in a Views List (unfinished)

Please look below, this advice was all wrong.

#25

alex.k - July 13, 2009 - 16:04

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!

#26

kevin riggen - July 14, 2009 - 00:02

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

#27

trupal218 - July 14, 2009 - 00:05

Thank you for all of your support!

#28

kevin riggen - July 14, 2009 - 04:46

Did you get it working Trupal?

#29

kevin riggen - July 17, 2009 - 20:35

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

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

#30

trupal218 - July 18, 2009 - 13:10

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!

#31

kevin riggen - July 20, 2009 - 00:58

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 :

<?php
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!

#32

kevin riggen - July 18, 2009 - 15:46

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!

#33

kevin riggen - July 18, 2009 - 16:06

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

#34

kevin riggen - July 20, 2009 - 00:58

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.

#35

chaosprinz - July 20, 2009 - 05:30

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.

#36

kevin riggen - July 22, 2009 - 22:16

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.

#37

ataxia - July 24, 2009 - 15:06

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:

<?php
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

#38

kevin riggen - July 24, 2009 - 20:37

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

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

#39

trupal218 - September 2, 2009 - 08:59

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!

#40

kevin riggen - September 2, 2009 - 15:11

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

#41

trupal218 - September 2, 2009 - 22:57

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!

#42

trupal218 - September 2, 2009 - 23:17

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!

#43

trupal218 - September 4, 2009 - 11:35

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!

#44

hamaldus - September 9, 2009 - 12:41

trupal218, could you post your working code?

#45

trupal218 - September 9, 2009 - 14:43

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!

#46

a.luiz.n - September 17, 2009 - 15:31

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);

#47

trupal218 - September 17, 2009 - 17:36

Hi a.luiz.n

Where did you print the above code?
thanks!

#48

a.luiz.n - September 17, 2009 - 20:15

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.

#49

kevin riggen - September 25, 2009 - 18:25

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 :)

#50

dima700 - October 1, 2009 - 12:55

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

#51

dima700 - October 1, 2009 - 14:00

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

#52

kevin riggen - October 1, 2009 - 20:07

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.

#53

trupal218 - October 18, 2009 - 13:14

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!

#54

truelove-nl - November 2, 2009 - 20:16

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

<?php
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.

#55

Jaizhanju - November 3, 2009 - 17:03

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! :)

#56

truelove-nl - November 3, 2009 - 17:28

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);

 
 

Drupal is a registered trademark of Dries Buytaert.