Hello Antonio -

Not sure if I should start a new issue or if you want to move it back to http://drupal.org/node/919316

I have learned a bit more about Rules and Proximity and am wondering what I still need to understand.

The goal is to alert user based on OpenLayer location contained in user profile, when a new node of a different type is created.

Attached is a screen shot from the View. It filters by distance and node type. The field is only there because View requires it for Default display.

Attached are two screen shots from the Rule. The Rule seems very logical and simple unless I am missing something.

From your prior comment "Notify nodes based on geographic proximity" means to notify author of the nodes based on new content location, so I would think the proper Rule would send an email to the user, which did not happen.

Thanks for any advice.

Comments

ademarco’s picture

Try, in the filter settings, to select "Get location from a node" and let me know how it goes.

itserich’s picture

StatusFileSize
new3.3 KB

Thanks Antonio, that makes sense.

The first time I tried it I got this error upon saving the node: "Unable to send e-mail. Please contact the site administrator if the problem persists."

I think I saved it as a user who should have received notice, but not sure it is related. Cron failed, I reinstalled a backup, got the same error, but then Cron did not fail again and is not failing. The error seems to come up only once.

Then when I try to create more nodes there is no error message or notification.

ademarco’s picture

That means that the rule action is fired correctly, I think. I would go more in the direction of checking if the email is sent to an actual email address, maybe rules token doesn't get substituted with an email address? Could you tell me how you configured the rule action that sends the email?

itserich’s picture

I think you are right. What confused me is when the error did not happen repeatedly, but apparently I deletd the Rule at some point.

I did not have any email configured. This must be the problem. It wanted to send a mail but had no directions.

There are two options.

One is to add a second action, so that there are two actions in the same Rule, "Notify nodes based on geographic proximity" and "Send a mail to..."

Second is to set up a subsequent Rule, with the event as "Node is notified based on geographic proximity.

I am going to try option one because the system must have tried to send an email, and I will try to configure who should receive that.

Thank you.

itserich’s picture

Edit Please ignore this entire rambling comment. Think I figured it out!

Thank you!

itserich’s picture

StatusFileSize
new45.27 KB

I started receving alerts, but two problems: they go to just one user (I have 3 fake profiles set up to test) and they go regardless of the distance.

So I probably just set it up to send an email whenever a node is created, but who knows.

View: Filter - Node type A & Proximity Great Circle < 20 miles

Rule 1 - Event: Saving New Content
Condition: If content type B created
Action: Notify Nodes Based on geographic Proximity

Rule 2 - Event: Node is notified based on geographic proximity
Condition: none
Action: Send Email to [nodeB:author-mail]

One question: When I set up the view filter proximity "get location by node" it prompts for "Node where to start to search from." I set it to start at a user profile, and that is the user profile which is also always notified.

It is the only user profile available in the Node: selection box, though there are other profiles set up. I don't understand why it asks for a place to start search but it seems it may be related to why that user is the only one notified.

Attached is the screen shot of the filter.

I think I am getting closer to accurate but don't know. Thank you.

scalp’s picture

I'm having the same issue as is mentioned in #6. I'm required to enter a starting node in the filter. That is the only node that ever gets notified if a new node is published within x miles of it. Seems like the proximity module should be overwriting whatever that node in the filter is with the node that has been created. I've added a rule to display a message whenever a new node is posted to show what other nodes have been notified which is how I confirmed that no other node's can get notified when this filter is set to "Get location from a node". If I set it to "Get location from a string" it doesn't seem to pass anything to the filter either. It just notifies all nodes of the new node's creation. Entering a postal code directly into the view's exposed filter does filter the results as expected.

scalp’s picture

Spent the day trying to get this to work with no success. I've been trying to implement what is discussed here: http://drupal.org/node/968984 to pass the $nodeA->nid to the exposed filter in openlayers_proximity.rules.inc. All I could figure out was that $filter->value['node'] = $nodeA->nid; on line 47 does do what it sets out to do by changing the value of that variable to nodeA's nid. Unfortunately, the filter on the view that is called still seems to go to the default value that it was assigned in the view edit form. This is why I was thinking that there may be a better way to pass it to the view on build, but couldn't get it to work. I'd be happy to test anything out that you can come up with.

itserich’s picture

I have not yet figured this out.

The geography modules are confusing, and I was not experienced with Rules at the time. I have not tried it again recently.

I hope someone is able to figure it out and document it.

scalp’s picture

StatusFileSize
new1.32 KB

I've got this working! To give credit where due, I borrowed what I found here about building a view and setting its filters.

The patch I've created has some restrictions.
1) It will only work on a great circle filter not a square
2) It is set to only work on the 'default' display id of the view
3) The distance is hard-coded to 30 miles.
These things should be easy enough for anyone to change in the code. I guess the end goal should be to make them available to a UI. I haven't played with whether or not leaving those settings out of the code will allow them to be set in the view's UI. Based on merlinofchaos' comments in the thread I linked to in my last comment, I'm pretty sure that all settings of a filter must be set in the build. I'll play with it a little when I get a minute and post a new patch if it's possible to only set the nid and let the other values be set in the views UI.

scalp’s picture

Status: Needs review » Active
StatusFileSize
new1.27 KB

Okay. Turns out you can submit just the one value for nid to the filter. This patch also adds a $view->pre_execute(); just before building the view to ensure that more than 10 results are given. So to sum up this patch works for me, but will only work with the circle filter and on the default display of the selected view.

EDIT: DO NOT USE THIS PATCH. SEE #14.

scalp’s picture

I should note that the "Force Single" must be unchecked in the filter's options as mentioned here: http://drupal.org/node/977212 for this to work. Would be a good addition to this patch. I don't have the time right now, but will try to get to it at some point if someone doesn't beat me to it.

chuckbar77’s picture

Status: Active » Needs review
scalp’s picture

StatusFileSize
new1.37 KB

Sorry for all the confusion, but the patch in #11 doesn't work. The one in #10 does. For some reason I can build a view and get the exposed filter to work by entering just one piece of the filter (as is in the patch in #11) other places, but when you try to do it through rules it needs to contain ALL the info for the filter (as in the patch in #10). Please use this patch. It still has the restrictions mentioned in #10 as well as the one mentioned in #11, but it includes the $view->pre_execute(); needed to make sure results aren't limited to only 10.

Restrictions:
1) It will only work on a great circle filter not a square
2) It is set to only work on the 'default' display id of the view
3) The distance is hard-coded to 30 miles.
4) You need to expose the filter in views, select "Get location from a node", select "Unlock Node", and uncheck "Force single".

Things that would make this patch better:
1) Set the "Get location from node", "Unlock node", and uncheck "Force single"
2) Figure out a way that the distance doesn't have to be hard-coded into it.

itserich’s picture

Status: Active » Needs review

Hello -

Scalp, I am wondering if you are still working on Rules + Proximity.

I have been compiling lists of users to contact by running a Proximity filter in Views, and eventually it will be much easier to automate that, to send email automatically when a new node is created within X distance of a user.

It is not clear to me exactly what this patch does. Are you still using it?

On another note, I recently noted this new module to Geocode a node when a Rule is processed. Have not gotten it to work yet.

http://drupal.org/project/rules_geocoder

scalp’s picture

itserich,

I am still using the patch. Looking at that module it seems like you'd need to set up far too many rules to make it work (one for each city presumably). The action you're trying to achieve is pretty much exactly what I'm doing. It requires setting up a couple of rules and a rules set.

Apply the patch above. Use content profile on your user accounts to set a location to their content profile node (this may be able to be done by setting a location to the user account directly, but I'm not sure). When a new node is created you'll need a rule with the action "Notify nodes based on geographic proximity". This will need a view that will compile all of the user accounts (content profile nodes) that are to be notified based on the proximity you set. My patch sets it to 30 miles, but you can go into the code and change that if you want. Just notifying a node doesn't do anything by itself so you'll need another rule to email users who's content profile nodes have been notified. To do this setup a ruleset that contains a rule with an action to "send a mail to a user". Then setup a rule who's trigger is "Node is notified based on proximity", with an action to call that rullset.

node is created->rules notifies all content profile nodes in a defined proximity using a particular view->when a node is notified rules calls up the ruleset and emails the author of the content profile node

It's confusing I know, but hopefully when you start walking through it it will make more sense.

itserich’s picture

Hi scalp, Thank you. Following is what I tried. And, Rule 1 is always triggered, Rule 2 is never triggered. Any idea? Thank you and congrats for figuring it out.

View- Filter: my user id (no other filters or fields)

Rule 1-
Trigger - When Content is Changed.
Condition - Content = Node Type.
Action - Notify Nodes Based on Geographic Proximity, with the View Selected (it states 32.18688 miles from)
(also added an email be sent to me so I can see if this action is triggered)

Rule 2-
Trigger - When Node is notified based on geographic proximity.
Action - Rule Set
(also added an email be sent to me so I can see if this action is triggered)

Rule Set - Notify User

scalp’s picture

I think your only problem is your view. You need an exposed distance/proximity filter in there. Make sure you follow all of the restrictions mentioned in comment #14 above.

Also, it may be easier to use "show a configurable message" as opposed to sending an email for testing purposes. That way you can put in a snippet to see what nodes were notified.

itserich’s picture

Thank you, I had missed the Views configuration in Step 14.

I think I followed the steps as closely as possible, but for me the first triggered rule triggers the action every time the node is updated, whether the distance is less than or greater than 30 miles.

However, the second triggered rule is never triggered, and most oddly the second triggered rule does not have the option for the Rule Set in the action setting. When I choose Rule Set, that Rule Set is simply missing from the list of Rule Sets. I have checked other triggered rules and the Rule Set is available as a possible action.

scalp’s picture

If you can attach an export of your view and rules I can try to take a look at it.

itserich’s picture

Hello -

Here is a copy of the exported View. I have been testing this setup and oddly at some times I get 10 emails indicating the second Triggered Rule has been triggered, which is equal to the Items to Display in the View, but this is before the new node is even geocoded.

And, I have only geocoded one user profile, my own.

Why in the second Triggered Rule do you schedule a Rule Set, instead of using an Action to send the e-mail from the Triggered Rule?

$view = new view;
$view->name = 'Rules_and_Proximity';
$view->description = 'Rules_and_Proximity';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$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('fields', array(
  'distance' => array(
    'label' => 'Distance',
    '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' => 1,
    'empty_zero' => 0,
    'set_precision' => 1,
    'precision' => '2',
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => '',
    'location_provider' => 'circle',
    'exclude' => 0,
    'id' => 'distance',
    'table' => 'openlayers_proximity',
    'field' => 'distance',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'user' => 'user',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'circle' => array(
    'operator' => '<',
    'value' => array(
      'value' => '30',
      'min' => '',
      'max' => '',
      'location' => '',
      'node' => '194249',
      'unit' => 'miles',
    ),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_unit' => 0,
      'unit' => 'unit',
      'use_location' => 0,
      'location' => 'location',
      'use_node' => 1,
      'node' => 'node',
      'use_operator' => 0,
      'operator' => 'circle_op',
      'identifier' => 'circle',
      'label' => 'Proximity: Great-circle',
      'optional' => 1,
      'single' => 0,
      'remember' => 0,
    ),
    'location_as' => 'node',
    'id' => 'circle',
    'table' => 'openlayers_proximity',
    'field' => 'circle',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
  'relationship' => 'none',
  'build_mode' => 'full',
  'links' => 1,
  'comments' => 0,
));
scalp’s picture

The view looks good (assuming the content type you're filtering on is the content profile that you're setting the user's location on). You've got it limited to 10 results which you probably don't want. Try using fields instead of nodes and adding the distance/proximity field. That's the only other thing I saw.