i think this is the userid of the user you want to add. are you using nodeprofile with a template file or what? If you do, you should try to print out get_defined_vars(); there you could find every link.
ah, i aprreciate your work...but i think i cant use it... because I'm trying to remove the original link of user relationship block, but this link brings other things like a "waiting approve cancel link"...
i just wanted to get the original link out of the html ul list tag...
I needed a more universal theme function so I could add in links where i needed them. This takes the arguments of viewer (optional, assumes global $user), and friend_uid, which is the user id you want to create the links for. I also created a template file to theme the actual "link set". It uses the user_relationships_ui module theme functions to create the links, which you can also use. the tirck is knowing which to use, and that's what this theme function does. Hope it's helpfule to someone else. I 'd like to see somethign like this in the module itself. I basically adapted this from it's existing functions, but they weren't generic enough, and were private functions :(
/*
* Implementation of theme_preprocess_HOOK().
*
* Return the relationships and links between the logged in user and the potential friend to the theme template.
*/
function matador_preprocess_relationship_links(&$vars) {
if (!$vars['viewer']) {
global $user;
$viewer = $user;
}
$friend_uid = $vars['friend_uid'];
if($friend_uid && user_access('can have relationships', $user) && module_exists('user_relationships_ui')) {
$relationships = user_relationships_load(array('between' => array($viewer->uid, $friend_uid)), array('include_user_info' => TRUE));
dpm($relationships);
if ($relationships) {
//there are 1 or more relationships
$list = array();
foreach ($relationships as $i => $relationship) {
//not sure if we have to check for requires approval here
if($relationship->approved) {
//this relationship is active
$relationship->status = 'approved';
//can override these theme functions if needed as well.
$relationship->actions['remove'] = theme('user_relationships_remove_link', $viewer->uid, $relationship->rid);
}
else {
//this relationship is waiting for approval..
if ($user->uid == $relationship->requester_id) {
//from another user
$relationship->status = 'sent';
$relationship->actions['cancel'] = theme('user_relationships_pending_request_cancel_link', $viewer->uid, $relationship->rid);
}
else {
//from the logged in user
$relationship->status = 'received';
$relationship->actions['approve'] = theme('user_relationships_pending_request_approve_link', $viewer->uid, $relationship->rid);
$relationship->actions['disapprove'] = theme('user_relationships_pending_request_disapprove_link', $viewer->uid, $relationship->rid);
}
}
$list[$relationship->rtid] = $relationship;
}
}
//any relationships not already taken? (assumes there are not multiple realtionships of the same type)
$all_relationship_types = user_relationships_types_load();
foreach ($all_relationship_types as $rtid => $relationship_type) {
if ($list[$rtid]) {
continue;
}
//check this type can be requested
if (!user_relationships_api_can_request($viewer, $relationship_type)) {
continue;
}
$new_relationship = NULL;
$new_relationship->rtid = $rtid;
$new_relationship->name = $relationship_type;
$new_relationship->requester = $user;
$new_relationship->requestee = user_load(array('uid' => $friend_uid));
$new_relationship->status = 'new';
$new_relationship->actions['request'] = theme('user_relationships_request_relationship_direct_link', $new_relationship->requestee, $relationship_type);
$list[$rtid] = $new_relationship;
}
}
$vars['relationship_links'] = $list;
dpm($vars);
}
Removing a Friend from any page that has the friend's ID passed as an argument
// 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>";
To confirm - is the above php code something we should be able to put into Views Custom Field? I have tried but currently not able to get the 'Remove this user as a friend' link to work properly in Views.
I can't seem to get the php code working in the Views Custom Field. I tried adding arguments in the Views which results in No Query Run. Could someone please help test creating a field in Views with the PHP code?
Are arguments and relationships required? And how should they be set up?
It would be very very helpful if someone could provide a views export which I could load to learn/study from.
Hi Kevin-
I added the attached code to a custom php field in views but the field came up blank for users that I have friends and non-friends relationships. Could I possibly have more direction on how to implement this feature?
Thank you very much in advance!
To display some type of user data, you need to replace the "node_data_field_avatar_field_firstname_value" part of that with whatever field you want to display.
You find out what that field is named on YOUR view by first making a Custom PHP field with the following :
print var_export($data, TRUE);
This shows you all of your field names. Remember in the PHP field you want to show a user's field in to include the $data=> before this value.
Comments
Comment #1
sprsquish commentedUser Relationships: Actions block will do what you need
Comment #2
andrenoronha commentedand if I want a custom link?
the only thing I need is to figure out what is this number in the path:
/user/[logged in user]/relationships/[misterious number]/remove?destination=user%2F[viewing user]
This misterious number is driving me wild.....I cant find a pattern...
any help?
Comment #3
IckZ commentedi think this is the userid of the user you want to add. are you using nodeprofile with a template file or what? If you do, you should try to print out get_defined_vars(); there you could find every link.
Comment #4
Plazmus commented[Edit]
I checked and that [misterious number] is the id of relationship, see user_relationships table this is rid field.
Comment #5
IckZ commentedI found that number you can get it with :
global $user;
$current_relationships = user_relationships_load(array('between' => array($user->uid, arg(1))), array('sort' => 'rtid'));
$friend_rid = $current_relationships['1']['0']->rid;
Comment #6
andrenoronha commentedi'm using content profile with no template files.
look these links:
to add user 29 as a friend:
/relationship/29/request/1?destination=user%2F29
everything is right.
now to remove a friend:
remove user 35 from my friend list
/user/32/relationships/32/remove?destination=user%2F35
now remove user 3
/user/35/relationships/23/remove?destination=user%2F3
now remove user 29
/user/35/relationships/27/remove?destination=user%2F29
now remove user 5 from user 3's list
/user/3/relationships/4/remove?destination=user%2F5
crazy numbers....
Comment #7
andrenoronha commented@ IckZ
it worked! thanks!
but what kind of id is it anyway?
ah, i aprreciate your work...but i think i cant use it... because I'm trying to remove the original link of user relationship block, but this link brings other things like a "waiting approve cancel link"...
i just wanted to get the original link out of the html ul list tag...
Comment #8
frankcarey commentedI needed a more universal theme function so I could add in links where i needed them. This takes the arguments of viewer (optional, assumes global $user), and friend_uid, which is the user id you want to create the links for. I also created a template file to theme the actual "link set". It uses the user_relationships_ui module theme functions to create the links, which you can also use. the tirck is knowing which to use, and that's what this theme function does. Hope it's helpfule to someone else. I 'd like to see somethign like this in the module itself. I basically adapted this from it's existing functions, but they weren't generic enough, and were private functions :(
The template file: relationship_links.tpl.php
Comment #9
andrenoronha commentedis this a hook? is it about my question above?
I couldnt implement it...
Comment #10
kvvnn commentedRemoving a Friend from any page that has the friend's ID passed as an argument
Thanks to IckZ for the php code.
Comment #11
Bilmar commentedTo confirm - is the above php code something we should be able to put into Views Custom Field? I have tried but currently not able to get the 'Remove this user as a friend' link to work properly in Views.
Thank you.
Comment #12
kvvnn commentedYes it should work with views. I haven't used a "remove friend" in views but I have used the $relationship object and that is all you should need.
Comment #13
Bilmar commentedI can't seem to get the php code working in the Views Custom Field. I tried adding arguments in the Views which results in No Query Run. Could someone please help test creating a field in Views with the PHP code?
Are arguments and relationships required? And how should they be set up?
It would be very very helpful if someone could provide a views export which I could load to learn/study from.
Thank you very much in advance.
Comment #14
kvvnn commentedHere is the view I use which calls some User Relationships functions in a custom php field (from the module, see above).
It is a list of all users on the site. The custom PHP field determines whether each user is a Friend, Not a friend, or in the pending process.
Comment #15
Bilmar commentedHi Kevin-
I added the attached code to a custom php field in views but the field came up blank for users that I have friends and non-friends relationships. Could I possibly have more direction on how to implement this feature?
Thank you very much in advance!
Comment #16
kvvnn commentedtrupal,
In my example, the Custom PHP field has values like this :
To display some type of user data, you need to replace the "node_data_field_avatar_field_firstname_value" part of that with whatever field you want to display.
You find out what that field is named on YOUR view by first making a Custom PHP field with the following :
This shows you all of your field names. Remember in the PHP field you want to show a user's field in to include the $data=> before this value.