Integration with Rules, Notifications and Action/Trigger

ballerjones - May 21, 2009 - 01:56
Project:Bookings API
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:tirsales
Status:closed
Description

Is there a way to specify a role/user that gets an email after any booking is requested? This way, any user with role "bookingsmanager(for example)" would receive an email notifying them of a new booking being made and a link to the administration screen. This would be an extremely useful addition to your already very useful module.

#1

tirsales - May 21, 2009 - 07:17

For a short fix (simple email address) please see #463534: Strange Log after creation of a new booking - I will add this feature, but it might take a while.

#2

tirsales - May 22, 2009 - 14:11
Project:Public Bookings» Bookings API
Version:6.x-1.x-dev» 6.x-1.x-dev

The newest version of Bookings API adds a new submodule "Bookings API Trigger". This submodule adds some triggers that are called, whenever a booking is changed/added/deleted or a resource is changed/added/deleted (not important whether via Bookings API or Public Bookings).
You can add actions (e.g. send mail or use the module http://drupal.org/project/action_email_role ) to do something on those occasions.

If you want to write your own actions, you can start your research here. $object will contain $user, $context will be

<?php
  $context
= array(
   
'hook' => 'bookingsapi_trigger',
   
'op'   => $op,
   
'user' => $user,
   
'data' => $data,
   
'config'=> $config,
  );
?>
. Two additional parameters are available: Parameter 1 will be the record or resource, Parameter 2 will be the corresponding configuration (normally empty) (see $data and $config).

A better notification implementation will be developed, but actions provide some (easy to setup) way to react to booking or resource changes. Alternatively it is possible to add a custom module that utilizes the hooks provided by Bookings API. The most important hooks for this occasion are:

<?php
hook_bookingsapi_booking
($op, $data, $config = NULL)
?>

Gets called when a booking has been changed or added. (Not called when an email-confirmation-link was activated). E.g. adding a new booking, changing a booking via the administration menu or deleting a booking.

<?php
hook_bookingsapi_record_status
($op, $data, $config = NULL)
?>

Gets called whenever a booking changes its status (e.g. confirmation email confirmed, status changed by the admin)

<?php
hook_bookingsapi_resource
($op, $data, $config = NULL)
?>

Gets called whenever a resource is added, changed or deleted.

#3

ballerjones - May 22, 2009 - 16:23

Is it possible to have Rules make use of Bookings API triggers? So far it isn't listed anywhere (not events or in triggers).

How would I send an email notification without writing my own actions?

#4

tirsales - May 22, 2009 - 16:19
Assigned to:Anonymous» tirsales

The notifications module so far cannot use the Bookings API triggers. You can add an Action "Send Email" that sends an information mail (w/o any specific resource/booking information) to a specified address (or user role) and you can add multiple of those to a single trigger. Its within admin/settings/actions after adding the Actions module.
Oh and the current dev-release does not contain the newest change ... I dont know why, but I guess the branch-tag disappeared (again...). My CVS client is kinda annoying (shows sticky tag "Drupal-6--1", but the Drupal CVS messages dont register the tag). You could get a CVS-copy.

I will add some kind of Notifications-event support or triggering, but I will have to test it first ;)

#5

ballerjones - May 25, 2009 - 01:29

Thanks. I will wait for that. I think I'm too much of a noob to be messing around with CVS.

When will the dev include that trigger?

#6

tirsales - May 26, 2009 - 14:10

The triggers should now be contained in the dev-release, the Notification-modules part is planned for this week (or next week).

#7

ballerjones - June 3, 2009 - 18:26

any progress? thanks btw

#8

tirsales - June 4, 2009 - 09:37

I apologize - but a couple of problems at work barred me from continuing writing on this in the last week ... With some luck I might be able to continue today, otherwise it will be tomorrow. But the trigger itself should allow you to send mails to arbitrary email addresses.
One problem (or additional to-do) is the need for a token-integration in order to allow meaningful status mails via the notifications framework .. But this will only serve to add more functionality, so I wont complain.

#9

ballerjones - June 4, 2009 - 16:22

Ideally, notification (of a new booking made) emails would depend on the resource being booked. This way, those people that manage a certain room will only be notified when their resource is booked. Fully-fleshed out (already very close), this module is ridiculously useful. Anyone looking to provide a network with an intranet needs public bookings.

#10

tirsales - June 4, 2009 - 16:45

Hmm, I'll have to have a more detailed look into notifications in order to tell whether "resource dependent" notifications would be possible - but I guess this would have to wait till node-based resources are available :(

Thanks for the nice words and the feedback :)

#11

ballerjones - June 4, 2009 - 17:24

Maybe integration with the Rules module is wise. Rules is already capable of 1. Knowing when content has just been created, 2. See what values are in a specified field, and 3. Sending an email when these conditions are met.

For example(this assumes a booking is node-based content, which I thought it was):

A booking is made--> Resource: Lavatory, From: 12:00, To: 12:30, By: Joe Boss.
The Rule searches for Resource = Lavatory, sees that the content (booking) has just been made and sends an email to the lavatory manager for notification.

Rules can already do this with other content types. If only it was possible to include "bookings" in its content type directory.

#12

tirsales - June 5, 2009 - 09:08

Neither bookings nor resources are node-based at the moment. This will be changed in the next major version of Bookings API - but its a major change that requires a near-complete rewrite of the API.

I will have a look at the Rules module, but I fear this too will have to wait for node-based resources (adding too much now will delay rewriting the API). Thanks for the proposition :)

#13

tirsales - June 5, 2009 - 10:48

A small Rules-integration has been added (some Events, datatypes Booking and Resource) and will be available in the next dev-release.

Provided datatypes:

Resource:

stdClass Object
(
[resource_id] => [ResourceID of this resource, internal ID)
[parent] => [ResourceID of this resources parent]
[name] => [Name of this resource]
[location] => [Location of this resource]
[description] => [Description of this resource]
[default_availability] => [Default availability, internal ID]
[disabled] => [TRUE if this resource is disabled]
)

Booking:

stdClass Object
(
[record_id] => [Internal ID of this booking]
[resource_id] => [ID of the booked resource]
[start] => [DATETIME in the format YYYY-MM-DD HH:MM:SS]
[end] => [DATETIME]
[name] => [string]
[description] => [string]
[rrule] => [repeat-rule]
[rrule_until] => [last repeat date]
[priority] => 0
[status] => [booking status, internal id]
)

#14

ballerjones - June 8, 2009 - 19:24

Thanks for adding this!

In a rule (new booking made), how do I add the condition: resourceid= x?

My options for condition are:

  • Execute PHP
  • Check Truth Value
  • Numeric Comparison
  • Text Comparison
  • I'm guessing I have to make a truth value and have resourceid= x(whatever resource I need it to be)

    I will look around on how to do this, but if you already know, that would be of tremendous helo.

    amazing progress.

    #15

    tirsales - June 8, 2009 - 19:33

    ATM the rules integration is not complete (e.g. conditions are missing). I tried to get it working, but ATM its not working (havent found out how to hand the parameters to the condition, ATM I always get the condition, not the paremeter) - but the integration will get better in the course of this week.

    You could use something like "Execute PHP" with (untested)

    <?php
    return $booking->resource_id == $searched_resource_id;
    ?>

    I haven't had a look at "Check Truth Value", so it might be possible with this too.

    #16

    ballerjones - June 10, 2009 - 16:05

    I will try that "Execute PHP" command. What is $searched-resource-id? Does this compare the bookings resource ID with an already specified one?

    I just need the condition to be for any resource id that is 1,2, or 3.

    #17

    tirsales - June 10, 2009 - 17:59

    $searched-resource-id should be replaced with the resource-id you are actually searching. To search for multiple IDs use

    <?php
    return in_array($booking->resource_id, array(1,2,3));
    ?>

    or something like that.

    #18

    ballerjones - June 11, 2009 - 15:55

    I tried it. No dice. Does this maybe need to be an If-Else statement? If resource = 1,2,3 then return True, Else = return False

    maybe? thanks for the your help

    #19

    tirsales - June 12, 2009 - 14:12

    Add a new condition "Execute PHP-Code" that includes:

    <?php
    return in_array($resource->resource_id, array(5));
    ?>

    (WITHOUT those <?php and ?> statements ... So include only

    return in_array($resource->resource_id, array(5));

    (assuming you want to check for Resource-ID 5. For 1,2,3 use array(1,2,3), etc

    #20

    tirsales - June 13, 2009 - 15:59
    Title:role/user update notification» Integration with Rules, Notifications and Action/Trigger

    There will be a new dev-release of Bookings API as soon as the script constructed it (it's already committed). This release will contain a condition that allows to check which resource(s) is/are affected.

    Feel free to propose more conditions if you need/want them.

    #21

    tirsales - June 16, 2009 - 13:40

    My apologies - I forgot to add bookingsapi_rules.forms.inc ... Its added now and should be working (again: use a dev-release of the 16th of June or later)

    #22

    tirsales - June 16, 2009 - 14:29

    Added a condition that allows to check the status (pending, finalized, etc) of a booking.

    --edit (16:26): Added a condition that allows to check the priority (Low, Normal, High) of a booking.
    Fixed the status-condition (to be more exact: Added a second condition, so that the priority of a booking can be checked whether it was changed or not).

    Already committed into CVS, the next DEV-release should contain the new conditions. Propositions for new conditions or actions are welcome!

    #23

    ballerjones - June 16, 2009 - 17:27

    When I got the new dev release, the new condition was there, but there was no option to select a(or multiple) resources for comparison. In the meantime, I have tested your correction for the PHP Execute code and it has worked. Btw, what is the $resource trait that prints the name? i.e. if in the email I were to enter:

    <?php
    print $resource->name
    ?>
    would this print the resource's name?

    #24

    tirsales - June 16, 2009 - 18:49

    The current dev-release does not include the forms-file .. I've uploaded the fixes and files into CVS, but I cannot start a new dev-release (this happens automatically once a day). You will have to get the CVS-release or wait for the new dev - sorry.

    Yes, $resource->name contains the resource name - but please, open a new support request for further questions :) (Dont hesitate to do so - start as many issues as you want!)

    #25

    ballerjones - June 17, 2009 - 16:04
    Status:active» reviewed & tested by the community

    thanks for all your help

    #26

    tirsales - June 19, 2009 - 10:21

    At the moment it is NOT possible to change a booking or a resource via an action - sorry. This is a result of Drupals module_invoke-method and I need to find a way to circumvent this...

    #27

    tirsales - June 19, 2009 - 10:40

    It's fixed.. You can now edit resources and bookings in a rules-action.

    #28

    tirsales - June 26, 2009 - 09:38
    Status:reviewed & tested by the community» fixed

    I'm setting this to fixed - the new ALPHA4-release contains the current implementation. Please feel free to add new issues with support requests, features requests or proposals (e.g. propositions for events, actions, etc) and bugs.

    #29

    System Message - July 10, 2009 - 09:40
    Status:fixed» closed

    Automatically closed -- issue fixed for 2 weeks with no activity.

     
     

    Drupal is a registered trademark of Dries Buytaert.