From 6d65f9217bf6d3950eb4d3aae7442759e53f4cc7 Mon Sep 17 00:00:00 2001 From: Chris Oden Date: Fri, 2 Mar 2012 09:40:21 -0500 Subject: [PATCH] Issue #1464054: Condition for which role is being granted. --- uc_roles/uc_roles.ca.inc | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-) diff --git a/uc_roles/uc_roles.ca.inc b/uc_roles/uc_roles.ca.inc index f924771..99e8b56 100644 --- a/uc_roles/uc_roles.ca.inc +++ b/uc_roles/uc_roles.ca.inc @@ -453,3 +453,51 @@ function uc_roles_action_order_renew_form($form_state, $settings = array()) { return $form; } + +function uc_roles_ca_condition() { + $conditions['uc_roles_condition_role'] = array( + '#title' => t('Check the role being granted'), + '#description' => t('Returns TRUE if the role being granted matches any of those specified below.'), + '#category' => t('Order: Roles'), + '#callback' => 'uc_roles_condition_role', + '#arguments' => array( + 'order' => array( + '#entity' => 'uc_order', + '#title' => t('Order'), + ), + 'expiration' => array( + '#entity' => 'uc_roles_expiration', + '#title' => t('Role expiration'), + ), + ), + ); + return $conditions; +} + +/** + * Checks the role being granted. + * + * @param $order + * The order as passed by uc_roles_notify_* + * @param $expiration + * The role and expiration data as passed by uc_roles_notify_* + * @param $settings + * Settings as generated by uc_condition_role_form(). + * + * @see uc_roles_condition_role_form() + */ +function uc_roles_condition_role($order, $expiration, $settings) { + $roles = array_filter($settings['roles']); + return isset($roles[$expiration->rid]); +} + +/** + * Settings form for checking the role being granted. + * + * @see uc_roles_condition_role() + */ +function uc_roles_condition_role_form($form_state, $settings = array()) { + $form = ca_condition_user_roles_form($form_state, $settings); + $form['operator']['#access'] = FALSE; + return $form; +} -- 1.7.3.4