You are here

function uc_roles_ca_predicate in Ubercart 6.2

Implements hook_ca_predicate().

File

uc_roles/uc_roles.ca.inc, line 32
This file contains the Conditional Actions hooks and functions necessary to make the roles-related entity, conditions, events, and actions work.

Code

function uc_roles_ca_predicate() {
  $predicates = array();

  // Renew all the roles on an order when the status matches what's set in the roles admin settings.
  $predicates['uc_role_renewal'] = array(
    '#title' => t('Grant or renew purchased roles'),
    '#description' => t('Grant or renew purchased roles if the order status matches.'),
    '#class' => 'renewal',
    '#trigger' => 'uc_order_status_update',
    '#status' => 1,
    '#conditions' => array(
      '#operator' => 'AND',
      '#conditions' => array(
        array(
          '#name' => 'uc_order_status_condition',
          '#title' => t('If the updated order status is payment received.'),
          '#argument_map' => array(
            'order' => 'updated_order',
          ),
          '#settings' => array(
            'order_status' => 'payment_received',
          ),
        ),
      ),
    ),
    '#actions' => array(
      array(
        '#name' => 'uc_roles_order_renew',
        '#title' => t('Update all role expirations for this order.'),
        '#argument_map' => array(
          'order' => 'updated_order',
        ),
        '#settings' => array(
          'message' => FALSE,
        ),
      ),
    ),
  );
  $order_args = array(
    'order' => 'order',
    'expiration' => 'expiration',
  );
  $user_args = array(
    'account' => 'account',
    'expiration' => 'expiration',
  );

  // Notify the user when a role is granted.
  $predicates['uc_role_notify_grant'] = array(
    '#title' => t('Notify customer when a role is granted'),
    '#description' => t('Notify the customer when they have had a role granted on their user.'),
    '#class' => 'notification',
    '#trigger' => 'uc_roles_notify_grant',
    '#status' => 1,
    '#actions' => array(
      array(
        '#name' => 'uc_roles_order_email',
        '#title' => t('Send an e-mail to the customer'),
        '#argument_map' => $order_args,
        '#settings' => array(
          'from' => uc_store_email_from(),
          'addresses' => '[order-email-raw]',
          'subject' => uc_get_message('uc_roles_grant_subject'),
          'message' => uc_get_message('uc_roles_grant_message'),
          'format' => 1,
        ),
      ),
    ),
  );

  // Notify the user when a role is revoked.
  $predicates['uc_role_notify_revoke'] = array(
    '#title' => t('Notify customer when a role is revoked'),
    '#description' => t('Notify the customer when they have had a role revoked from their user.'),
    '#class' => 'notification',
    '#trigger' => 'uc_roles_notify_revoke',
    '#status' => 1,
    '#actions' => array(
      array(
        '#name' => 'uc_roles_user_email',
        '#title' => t('Send an e-mail to the customer'),
        '#argument_map' => $user_args,
        '#settings' => array(
          'from' => uc_store_email_from(),
          'addresses' => '[mail]',
          'subject' => uc_get_message('uc_roles_revoke_subject'),
          'message' => uc_get_message('uc_roles_revoke_message'),
          'format' => 1,
        ),
      ),
    ),
  );

  // Notify the user when a role is renewed.
  $predicates['uc_role_notify_renew'] = array(
    '#title' => t('Notify customer when a role is renewed'),
    '#description' => t('Notify the customer when they have had a role renewed on their user.'),
    '#class' => 'notification',
    '#trigger' => 'uc_roles_notify_renew',
    '#status' => 1,
    '#actions' => array(
      array(
        '#name' => 'uc_roles_order_email',
        '#title' => t('Send an e-mail to the customer'),
        '#argument_map' => $order_args,
        '#settings' => array(
          'from' => uc_store_email_from(),
          'addresses' => '[order-email-raw]',
          'subject' => uc_get_message('uc_roles_renew_subject'),
          'message' => uc_get_message('uc_roles_renew_message'),
          'format' => 1,
        ),
      ),
    ),
  );

  // Notify the user when a role is about to expire.
  $predicates['uc_role_notify_reminder'] = array(
    '#title' => t('Notify customer when a role is about to expire'),
    '#description' => t('Notify the customer when they have had a role that is about to expire.'),
    '#class' => 'notification',
    '#trigger' => 'uc_roles_notify_reminder',
    '#status' => 1,
    '#actions' => array(
      array(
        '#name' => 'uc_roles_user_email',
        '#title' => t('Send an e-mail to the customer'),
        '#argument_map' => $user_args,
        '#settings' => array(
          'from' => uc_store_email_from(),
          'addresses' => '[mail]',
          'subject' => uc_get_message('uc_roles_reminder_subject'),
          'message' => uc_get_message('uc_roles_reminder_message'),
          'format' => 1,
        ),
      ),
    ),
  );
  return $predicates;
}