Rules integration

mansspams - May 21, 2009 - 03:36
Project:User Relationships
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:mansspams
Status:needs review
Issue tags:actions, rules
Description

Is there a plan for integration with rules module?

What does "Not required" mean in User Relationship API vs Friendslist API wiki page (http://groups.drupal.org/node/14625)?

#1

alex.k - May 21, 2009 - 07:58
Status:active» by design

I'm not planning to integrate with Rules, as it's not a priority. FL needs Rules to send out emails, while UR has the Mailer submodule to take care of that. So for UR, Rules would be more of an add-on than a necessity.

#2

mansspams - June 1, 2009 - 08:50
Assigned to:Anonymous» mansspams
Status:by design» active

thanks for info alex. for me rules seems to be necessity so ill try to come up with nice and clean ur.rules.inc file and I hope you could at least take a look at code and comment on it when its ready...

my idea is that rules (via flags and tokens) may provide a way for commenter and node author to establish relationships with one click on node page (well, the other way around in my case). first draft is working well.

also user_relationships_api.actions.inc has large part of code for actions commented out and it seems it contains reusable material. what happened to that code? any history? is this code animated, does it do something?

#3

alex.k - June 1, 2009 - 14:39

This would be a great addition, let's see what you come up with.

also user_relationships_api.actions.inc has large part of code for actions commented out and it seems it contains reusable material. what happened to that code? any history? is this code animated, does it do something?

Somebody asked me this a while ago as well... The code was commented out when I inherited it from the original author - so I don't know what state it is in. It does look pretty good at a glance. Please uncomment it, and see how it works. It would certainly be advantageous to use actions, rather than one-off code.

#4

mansspams - June 2, 2009 - 07:34

I have a question about

user_relationships_delete_relationship(&$relationship, &$deleted_by, $op = 'remove');

and in particular about $relationship. It has to be "object of the relationship". How do I load such object if I have 2 UIDs. Handbook (http://drupal.org/node/203396) says i could use

user_relationships_load($param = array(), $count = FALSE, $sort = 'rid', $order = NULL, $limit = NULL, $include_user_info = FALSE)

and that special key array("between" => array($uid1, $uid2)) will return all relationships between the two user ids. Im trying to get it to work but not with much luck so far. Ideally id like to receive only relationships of particular type.

Is handbook up to date? Maybe you could write some EXAMPLE parameters of that you THINK should work?

#5

alex.k - June 2, 2009 - 07:56

If you already know the relationship type id, then you could simply add it to the $param array, like so:

<?php
$relationships
= user_relationships_load(array('between' => array($uid1, $uid2), 'rtid' => $rtid));
$relationship = $relationships[$rtid][0];
?>

The book pages you reference are for 5.x-2.x, actually... I added a note in them. The most up to date documentation on the API are comments in front of each function in user_relationships_api.api.inc

#6

mansspams - June 2, 2009 - 19:59

Thanks for the tip. Im getting error with this code:

warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\test02\sites\all\modules\user_relationships\user_relationships_api\user_relationships_api.api.inc on line 36.

It looks like first line does the magic and I get $relationships =

Array ( [26] => stdClass Object ( [rid] => 26 [requester_id] => 1 [requestee_id] => 3 [rtid] => 1 [approved] => 1 [created_at] => 1243971262 [updated_at] => 1243971262 [flags] => 0 [name] => friend [plural_name] => friends [is_oneway] => 0 [requires_approval] => 0 [expires_val] => 0 ) )

maybe second line $relationship = $relationships[$rtid][0]; does not work?

Any ideas?

#7

najibx - June 23, 2009 - 04:34

without Rules modules, could UR send email only to his manager (already established one way relationship) when he submitted a node, for his manager's approval? i.e change cck field from draft to live state?

Or else, without using Rules, could this be achieve with workflow module as well? Or friendlist is better option?

#8

msmccask - July 10, 2009 - 21:51

Hey - I have run into a situation where rules integration into user relationships would help me as well. Just curious if you were able to make any headway on this type of thing. If so, I'd be happy to help test/move forward.

Thanks.

#9

mansspams - July 12, 2009 - 23:10

yes, i need it too, but there is something not right, as explained in #6

#10

trupal218 - July 14, 2009 - 00:06

I would truly appreciate Rules integration with User Relationships as well. Currently working on a website and I have hit a roadblock that requires this integration. Thank you.

#11

mansspams - July 14, 2009 - 07:21

Now iv got some time on my hands and will try to look into this.

with just first line of #5 code i get error warning: Attempt to assign property of non-object in C:\xampp\htdocs\test02\sites\all\modules\user_relationships\user_relationships_api\user_relationships_api.api.inc on line 257.

#12

mansspams - July 14, 2009 - 09:58

first steps in rules integration - adding and deleting relationships

It's alive!

attached you will find .zip file, expand it in user_relationships_api folder in user_relationships module folder (there are 2 files in archive). You will need token and rules modules of course. This will give you new actions in rules - "Request relationships between users" and "Delete relationships between users".

I created flag "Add author as friend" and if node is flagged with it action "Request relationships between users" happens and if node is unflagged action "Delete relationships between users" happens.

As for configuration of ADD actions I set [flagging_user:user-id] as Requester, [node:author-uid] as Requestee, 1 as Relationship type (maybe this can be made into drop down list with proper relationship type names), something as Message (for elaboration, you can use tokens for all kinds of custom messages, does not work yet, i think) and Require confirmation checkbox if it is needed (does not work yet, i think). For DELETE action I set remove as Op.

Voila! When you flag node, you become friend with its author, unflag and your friendship is gone with wind.

here is code, please suggest how to make it better, you know i am not coder :)

<?php
function user_relationships_api_action_delete_relationship($settings) {

 
// setting $deleted_by
 
$deleted_by = user_load(array('uid' => $settings['requester']));
 
// getting relationship object
 
$relationships = user_relationships_load(array('between' => array($settings['requester'], $settings['requestee']), 'rtid' => $settings['relationship_type']));
 
// finding rid - this method can probably be made better
 
$relationship_rid = array_keys($relationships);
 
// preparing $relationship with rid
 
$relationship = $relationships[$relationship_rid[0]];
 
 
// voila...
 
user_relationships_delete_relationship(&$relationship, &$deleted_by, $op = 'remove');
 
}
?>

AttachmentSize
user_relationships_api__rules.zip 1.92 KB

#13

mansspams - July 14, 2009 - 18:16
Category:support request» feature request
Status:active» needs review

#14

electricmonk - September 7, 2009 - 08:27

Hi all,

We've had a need for hooking into the different UR events, so we've taken the patch above, made it a full module (user_relationship_rules) and added event integration for request/approve/deny/remove actions.

This module is far from complete, for instance lacking a condition to narrow the relationship type, but it's a start. I strongly suggest that it be committed into the UR codebase.

- Shai

AttachmentSize
user_relationships_rules.tar_.gz 1.84 KB

#15

mitkoru - September 13, 2009 - 19:18

Subscribe

#16

mansspams - September 13, 2009 - 20:40

thanks monk,i definetly have no skills yet to take it that far. great job.

#17

lasac - September 27, 2009 - 18:01

I to would love this , UR and rules. When a members registers you can imidalty make a friendship with the admin. What i also would love to see is that when a member registers they imidiatly get a PM message

#18

alex.k - September 27, 2009 - 18:04

@lasac

Have you tried the module in #14? Please test and comment with your feedback. Thanks!

#19

lasac - September 27, 2009 - 18:06

Yes i have seen it and am going to test. Will get back to you asap.

#20

lasac - September 27, 2009 - 18:23

First off.

This is exactly what i need! Keep on developing!

First thing:
1) I created a relationship, gave it the requester and requestee id and the id for the relationship. When the user has registered it shows the ids in the message
96
115
1
You have reggisterd for more info look at email etc etc etc...

- Debug rule evaluation
- Show fixed rules and rule sets
Above are turned off.

2) The relationship is not active even though i have NOT checked Require confirmation.
(Maybe because the relationship settings need confirmation? I would like relationships to set without needing to confirm when activating a relationship trough rules)

3) A e-mail is being send with the aproval link for the relationship. This is confusing. Because members gets two email first is activation for account and second for relationship. Make it a option to send the email? Or automaticly not send a email when the above (2) is done. So when the relationship doesnt need confirmation then just dont send the email.

4) The PM is not recieved. Look like it even isn't send out. PM settings for new users are accept PM from everybody, so that can;t be the problem.

Al with all. the module doesnt quite work YET. When more testing is needed contact me. I will be following this topic.

#21

geraldito - October 25, 2009 - 00:07

Thanks electricmonk for this patch. Works for my approach to detect new UR approve event and create a new node using the $requester->uid as node author.

#22

mortenson - October 28, 2009 - 13:52

Is there a way I can send email to my related users when content is created?
I tried with rules and actions but it seems not possible.

thanks for you work!

#23

lasac - November 17, 2009 - 00:16

alex.k any news on this???

#24

Hamster5 - November 29, 2009 - 05:27

hi mortenson

i have did it, but i don't know if is the best way to do it (i'm not a coder), if somebody can find a better way please post it. I have 2 types of relationships, two way (friends) and one way (followers), so when a user create new content an e-mail is sent to all his followers.

Modules: rules, tokens.

You need to create a new rule with the following:

Condition: (Execute custom PHP code):

<?php
if($relationships = user_relationships_load(array('user' => $author->uid, 'rtid' => 2,'approved' => 1), array('count' => TRUE))){
return
TRUE;
}
?>

Action: (Execute custom PHP code):

<?php
$relationships
= user_relationships_load(array('user' => $author->uid, 'rtid' => 2,'requestee_id' => $author->uid, 'approved' => 1));

foreach(
$relationships as $rtid => $relationship){
   
$followers = user_load($relationship->requester_id);//there is a way to do it without calling user_load(), but i don't know how to use it, try include_user_info, of user_relationships_api

$body = 'Q onda '.$followers->realname.'[node:realname-link] ha publicado nuevo contenido en su blog.';

$headers = array(
'From' => 'site_mail@example.com',
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal'
);

$message = array(
 
'id' => 'mail_id',
 
'to' => $followers->mail,
 
'subject' => '[node:realname] ha publicado nuevo contenido en su blog.',
 
'body' => $body,
 
'headers' => $headers,
);

echo
drupal_mail_send($message);

}
?>

#25

DrakeRemory - November 30, 2009 - 16:15

I implemented a condition to check for a specific relationship type. I also added a drop down for selecting from the available types. I put the same form element in the already existing forms that were using this as well. There's still some work to do but this is getting close.

AttachmentSize
user_relationships_rules.zip 3.49 KB

#26

lasac - December 2, 2009 - 10:40

going to test it out, thanks drakeremory!

#27

trupal218 - December 3, 2009 - 13:00

DrakeRemory - thank you for the great work!

I tested your User Relationships Rules module and all the events worked perfectly!
Only request I have is for the 'request expired' event to be added.
For each relationship type there is 'Request expires in:' setting that is available. Would this event be possible?

Again, awesome work!

#28

DrakeRemory - December 6, 2009 - 11:11

I'm sorry but this couldn't be done easily at least not by using hook_user_relationships because there is no such operation as "expire". I'm not quite sure how expiration is implemented in user relationships (and I don't have the time right now to dig into this) but I'm guessing it is just done by limiting sql queries. Therefore the event doesn't exist.

#29

gallamine - December 21, 2009 - 22:15

Any status on getting this committed to the project, or perhaps turned into a completely separate project?

 
 

Drupal is a registered trademark of Dries Buytaert.