From 7be2eb16735f7bbdce51a3411756fa54975a247a Mon Sep 17 00:00:00 2001
From: jordojuice <jordan.halterman@gmail.com>
Date: Thu, 9 Jun 2011 20:43:09 -0700
Subject: [PATCH] Issue #622152: Invite Rules integration.

---
 invite.module    |   15 +++++++++++++++
 invite.rules.inc |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 invite.module
 create mode 100755 invite.rules.inc

diff --git a/invite.module b/invite.module
old mode 100644
new mode 100755
index 4856412..90ed83b
--- a/invite.module
+++ b/invite.module
@@ -534,6 +534,11 @@ function invite_process($invite, $account) {
   $args = array('invitee' => $account, 'inviter' => $invite->inviter, 'roles' => &$roles);
   module_invoke_all('invite', 'escalate', $args);
 
+  // Invoke rules event "Invitation was accepted".
+  if (module_exists('rules')) {
+    rules_invoke_event('invite_accept_event', user_load($invite->inviter->uid), $account);
+  }
+
   return $roles;
 }
 
@@ -1118,6 +1123,11 @@ function invite_form_submit($form, &$form_state) {
       if (!$form_state['values']['resent']) {
         $args = array('inviter' => $invite->inviter, 'email' => $invite->email, 'code' => $invite->code);
         module_invoke_all('invite', 'invite', $args);
+
+        // Invoke Rules event "Invitation was sent".
+        if (module_exists('rules')) {
+          rules_invoke_event('invite_invite_event', user_load($invite->inviter->uid));
+        }
       }
 
       $num_succeeded++;
@@ -1280,6 +1290,11 @@ function invite_cancel_submit($form, &$form_state) {
   // Notify other modules.
   $args = array('inviter' => $invite->inviter, 'email' => $invite->email, 'code' => $invite->reg_code);
   module_invoke_all('invite', 'cancel', $args);
+
+  // Invoke Rules event "Invitation was cancelled".
+  if (module_exists('rules')) {
+    rules_invoke_event('invite_cancel_event', user_load($invite->inviter->uid));
+  }
 }
 
 /**
diff --git a/invite.rules.inc b/invite.rules.inc
new file mode 100755
index 0000000..2cecdca
--- /dev/null
+++ b/invite.rules.inc
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * @file
+ * Provides Rules integration for Invite module.
+ */
+
+/**
+ * Implementation of hook_rules_event_info().
+ *
+ * @ingroup rules
+ */
+function invite_rules_event_info() {
+  return array(
+    'invite_invite_event' => array(
+      'label' => t('Invitation was sent'),
+      'module' => 'Invite',
+      'arguments' => array(
+        'inviter' => array('type' => 'user', 'label' => t('Inviting user')),
+      ),
+      'help' => 'This event is triggered when a user sends a new invitation.',
+    ),
+    'invite_cancel_event' => array(
+      'label' => t('Invitation was cancelled'),
+      'module' => 'Invite',
+      'arguments' => array(
+        'inviter' => array('type' => 'user', 'label' => t('Inviting user')),
+      ),
+      'help' => 'This event is triggered when an inviting user cancels an invitation.',
+    ),
+    'invite_accept_event' => array(
+      'label' => t('Invitation was accepted'),
+      'module' => 'Invite',
+      'arguments' => array(
+        'inviter' => array('type' => 'user', 'label' => t('Inviting user')),
+        'invited' => array('type' => 'user', 'label' => t('Invited user')),
+      ),
+      'help' => 'This event is triggered when a user has accepted an invitation.',
+    ),
+  );
+}
-- 
1.7.4

