Hi guys, i would make a rule for sending an e-mail to a user when someone post a status on his profile.

But i would make it more complex, the rule must evaluate a cck field called status_mail and if it's active a mail is sended to the user who recieve the status.

But i can't accomplish it, because when i select User saves a status i need to apply a condition first

my condition is search inside a node the value of field status_mail turned on ON and next do the action Send a mail to a given user.

But under condition i cant configure nothing related the node i get this

The following conditions aren't available in this context because they require arguments that don't exist in your rule. If you want to use any of these conditions, you must first add some action that adds variables of this kind in a previous rule, or have an event that passes the required variables.

Field has value
Unavailable argument: Content

the same for the action i get this

Send a mail to a user
Unavailable argument: recipient

Someone has an idea how to accomplish this? I think a mail feature can be nice if someone post on your profile like facebook :)

CommentFileSizeAuthor
#2 first.png90.38 KBGolDRoger
#2 after.png72.35 KBGolDRoger

Comments

icecreamyou’s picture

Status: Active » Fixed

Use the "load node" action to load the node you want. Then you'll be able to use it in your condition.

GolDRoger’s picture

StatusFileSize
new72.35 KB
new90.38 KB

Thx Ice, you gave me a nice idea.

I started the rule with User saves a status.

Under actions i have selected:

Load the user account, putting in ID the token [status:recipient-id]

Load profile content

Arguments configuration
User, whose profile should be loaded: Loaded user

Content Profile Content Type: User profile

Finished actions I have added a condition: Exegute custom php code

and i inserted this script: if ('[profile_node:field_uprofile_statusmail-raw]' == 'Send me mails') { return TRUE; } else { return FALSE; }

and last step, under action

Send a mail to a user

Arguments configuration
recipient: loaded user

Maybe i'm doing small confusion... This doesn't work actually.

But most strange when i came back to modify the condition Exegute some custom php code, i can see only the token of the status and not like first time (like screenshots).

Sure i'm doing something wrong :/

GolDRoger’s picture

ops made a distraction error. I forgot the php tags included inside Exegute custom php code, wich shouldn't be inculded.

But removing them is the same thing, the rule isn't exeguted and no mail sended

GolDRoger’s picture

I made a progress, found what's wrong.

Load the user account, putting in ID the token [status:recipient-id]

this was wrong, instead of id I have changed in [status:recipient-name-raw] inside the user name field

and works, but i'm haviing troubles with the cck field [profile_node:field_uprofile_statusmail-raw]

tried to insert the above code inside a Exegute custom php or check a truth value but seems to not work.

:/ I cant understand if the script can't find the token or somewhat...

icecreamyou’s picture

Try putting drupal_set_message('[profile_node:field_uprofile_statusmail-raw]'); in the place where you have your PHP so you can check that the token has the value you expect.

GolDRoger’s picture

Tryied but nothing happens... :( and I'm becoming crazy. It seem he loose the variables.

So it can't recocknize the values. I've used all the week to set up it working with Notifications too but no luck.

Notifications sends me all the mail regarding creation / updating nodes but nothing when a status is created / updated, and i can't undestand why, because i made the subscription to every status ID and on User profile status.

There is a special configuration to do?

I will make a tutorial abiut this but first I have to make it working :)

GolDRoger’s picture

Ok... another update... this post just seems a diary...

Made the correct configuration of Notifications but... When I was closer to accomplih what I will:

Make user choice if recieve or not e-mail notifications on his stream, i found another blocked way.

Notifications has a add on called Notifications Add-On where inside there is the submodule Custom Notifications.

But.... Custom Notificantions don't accept Tokens...

And in your custom notification you can only add a user name where all the new user will auto subscribe. Instead using tokens and auto subscribing a user to own Stream, wich has more sense.

icecreamyou’s picture

If you have the Notifications Autosubscribe module installed and users enable auto-subscribing in their profile settings, they will automatically be subscribed to status updates they post or comment on.

GolDRoger’s picture

This works for me too Ice, but i can't add the autosubscrption of their user profile status. Now if someone post on my profile I don't get noticed by mail.
For doing this i need to subscribe to my own user profile status. In this case if someone post on my wall i Get the mail notification: user1 posted on Your profile.

But maybe some users don't want to be noticed, that's why i'm trying to' make it working with cck. Just for add option: i will recieve mails or i dont want recieve mails.

Notifications is perfect because an user can set if recieve notifications unlucky i can't add a default subscription with a token for example [status:owner]
So every user Who joins is auto subscribed to own stream and noticed for every user Who post :/

icecreamyou’s picture

Status: Fixed » Active

Interesting. I'll see if I have some time to work on this in the next few weeks.

GolDRoger’s picture

Nice :) and thx

By the way i will continue to work parallel to you :)

I'm sure I can grab with the lookup the node id behind the url alias, adding the id to a variabile and call the node load.
And then try to verify if the field status_mail has the value recieve mails and set a return true.

GolDRoger’s picture

Ice I've made it more or less.

GolDRoger’s picture

<?php

if ($user || (arg(0) == 'user' && arg(2) != 'edit')) {
   $system_path = arg(1);

   $viewed_user =  $system_path;
}

$profile_node = content_profile_load('uprofile', $viewed_user );


$cck_value = $profile_node->field_status_mail[0]['value'];

if($cck_value == 'yes'){
return TRUE;

} else{
return FALSE;
}

?>

With this script I was going to check the uid inside the url and inserting it in a variable called viewed_user.

Variable passed to $profile_node via content profile load.

In a block this works perfectly when i'm viewing a user profile and returns true.

Inside the rule this doesn't work, so i would use the [status:recipient-id]

but i cant find the variable name.

Is $status->recipient_id ?

GolDRoger’s picture

Ok finally maybe I have understood what is necessary to make this work.

When i start a rule for example : user saves a new status

under conditions I can do only few thisgs because are missing arguments.

The following conditions aren't available in this context because they require arguments that don't exist in your rule.

And that's true, for example I can't load a node to check if some fields have particular values because fbss is not related to nodes.

I have to see if I can make another condition to add at fbss rules for load a content profile using a token for example status:recipient-id.

In this case, loaded the content profile it's possible check cck values at inside

icecreamyou’s picture

You can use drupal_set_message(print_r($variable, TRUE)); to print out the structure of a variable. In the case of FBSS the properties of a status object correspond to the columns of the {facebook_status} table in the database so the recipient ID is in the "recipient" property.

Also you can probably use the "Load a user" action for a sender/recipient (make sure the recipient is actually a user) and then from there load the Content Profile node associated with it.

GolDRoger’s picture

Done Ice, nothing happens :/

Loaded user under actions, loaded content profile.

Under actions i can do all the things.

The probelm is conditions. The condition continue to' say true. I can't understand why... It seems to not be albe to find the user id and load the profile...

icecreamyou’s picture

Unfortunately I can't really help you with that -- it's pretty specific to the CCK field you're working with.

GolDRoger’s picture

Ice, solved. I don't know why but... maybe something in in system table of my db...

I have disabled and uninstalled the Rules module. Enabled another time, made all the experiments and now works... :D

I can't believe i wasted 7 days for this :/

Ok i made a tutorial for this Ice and I have exported my rule so anyone can use it.

I cann add a tutorial child page on book documentation? http://drupal.org/node/1135246

Or If u prefer i can add the tutorial here

icecreamyou’s picture

Nice. Please add it as a child page of the Tips & Tricks page: http://drupal.org/node/1202826

GolDRoger’s picture

Perfect :) tomorrow morning Ill do :)

icecreamyou’s picture

Status: Active » Closed (fixed)