FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 deletions

View File

@@ -0,0 +1,62 @@
<?php
/**
* @file
* Role assignment product feature tests.
*/
/**
* Tests the role purchase functionality.
*/
class UbercartRolesTestCase extends UbercartTestHelper {
public static function getInfo() {
return array(
'name' => 'Roles',
'description' => 'Ensures that the purchase of roles functions correctly.',
'group' => 'Ubercart',
);
}
/**
* Overrides DrupalWebTestCase::setUp().
*/
function setUp() {
$modules = array('uc_payment', 'uc_payment_pack', 'uc_roles');
$permissions = array();
parent::setUp($modules, $permissions);
}
function testRolePurchaseCheckout() {
// Add role assignment to the test product.
$rid = $this->drupalCreateRole(array('access content'));
$this->drupalLogin($this->adminUser);
$this->drupalPost('node/' . $this->product->nid . '/edit/features', array('feature' => 'role'), t('Add'));
$edit = array(
'uc_roles_role' => $rid,
'end_override' => TRUE,
'uc_roles_expire_relative_duration' => 1,
'uc_roles_expire_relative_granularity' => 'day',
);
$this->drupalPost(NULL, $edit, t('Save feature'));
// Check out with the test product.
$this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
$order = $this->checkout();
uc_payment_enter($order->order_id, 'other', $order->order_total);
// Test that the role was granted.
$account = user_load($order->uid);
$this->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.');
// Test that the email is correct.
$mail = $this->findMail('/Ubercart: ' . preg_quote($account->roles[$rid]) . ' role granted/');
// Delete the user.
user_delete($order->uid);
// Run cron to ensure deleted users are handled correctly.
$this->drupalLogout();
$this->cronRun();
}
}

View File

@@ -0,0 +1,152 @@
<?php
/**
* @file
* Roles administration menu items.
*/
/**
* Creates the header for the table/pager.
*/
function _uc_roles_expiration_header() {
return array(
array('data' => t('Username'), 'field' => 'u.name'),
array('data' => t('Role'), 'field' => 'e.rid'),
array('data' => t('Expiration date'), 'field' => 'e.expiration', 'sort' => 'asc'),
array('data' => t('Operations'), 'colspan' => 2),
);
}
/**
* Menu callback for viewing expirations.
*/
function uc_roles_expiration($form, &$form_state) {
// Create the header for the pager.
$header = _uc_roles_expiration_header();
// Grab all the info to build the pager.
$query = db_select('uc_roles_expirations', 'e')->extend('PagerDefault')->extend('TableSort')
->fields('e')
->limit(50)
->orderByHeader($header);
$query->join('users', 'u', 'e.uid = u.uid');
$query->fields('u');
$result = $query->execute();
// Stick the expirations into the form.
foreach ($result as $row) {
$account = user_load($row->uid);
$name = check_plain(format_username($account));
$form['name'][$row->uid . ' ' . $row->rid] = array(
'#theme' => 'username',
'#account' => $account,
'#name' => $name,
);
$form['role'][$row->uid . ' ' . $row->rid] = array('#markup' => check_plain(_uc_roles_get_name($row->rid)));
$form['expiration'][$row->uid . ' ' . $row->rid] = array('#markup' => format_date($row->expiration, 'short'));
$form['edit'][$row->uid . ' ' . $row->rid] = array('#markup' => l(t('edit'), 'user/' . $row->uid . '/edit', array('fragment' => 'role-expiration-' . $row->rid, 'query' => array('destination' => 'admin/people/expiration'))));
$form['delete'][$row->uid . ' ' . $row->rid] = array('#markup' => l(t('delete'), 'admin/people/expiration/delete/' . $row->uid . '/' . $row->rid));
}
return $form;
}
/**
* Themes user role expiration page.
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_uc_roles_expiration($variables) {
$form = $variables['form'];
$header = _uc_roles_expiration_header();
$rows = array();
if (isset($form['name'])) {
foreach (element_children($form['name']) as $key) {
$rows[] = array(
drupal_render($form['name'][$key]),
drupal_render($form['role'][$key]),
drupal_render($form['expiration'][$key]),
drupal_render($form['edit'][$key]),
drupal_render($form['delete'][$key]),
);
}
}
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
'empty' => t('No expirations set to occur'),
));
$output .= theme('pager');
$output .= drupal_render_children($form);
return $output;
}
/**
* Form builder for role expirations.
*
* @see uc_roles_deletion_form_submit()
* @ingroup forms
*/
function uc_roles_deletion_form($form, &$form_state, $account, $rid) {
$expiration = db_query("SELECT expiration FROM {uc_roles_expirations} WHERE uid = :uid AND rid = :rid", array(':uid' => $account->uid, ':rid' => $rid))->fetchField();
if ($expiration) {
$role_name = _uc_roles_get_name($rid);
$form['user'] = array('#type' => 'value', '#value' => format_username($account));
$form['uid'] = array('#type' => 'value', '#value' => $account->uid);
$form['role'] = array('#type' => 'value', '#value' => $role_name);
$form['rid'] = array('#type' => 'value', '#value' => $rid);
$form = confirm_form(
$form,
t('Delete expiration of %role_name role for the user !user?', array(
'!user' => theme('username', array(
'account' => $account,
'name' => check_plain(format_username($account)),
'link_path' => 'user/' . $account->uid,
)),
'%role_name' => $role_name,
)),
'admin/people/expiration',
t('Deleting the expiration will give !user privileges set by the %role_name role indefinitely unless manually removed.', array(
'!user' => theme('username', array(
'account' => $account,
'name' => check_plain(format_username($account)),
'link_path' => 'user/' . $account->uid,
)),
'%role_name' => $role_name,
)),
t('Yes'),
t('No')
);
}
else {
$form['error'] = array(
'#markup' => t('Invalid user id or role id.'),
);
}
return $form;
}
/**
* Submission handler for uc_roles_deletion_form().
*
* @see uc_roles_deletion_form()
*/
function uc_roles_deletion_form_submit($form, &$form_state) {
uc_roles_delete(user_load($form_state['values']['uid']), $form_state['values']['rid']);
drupal_goto('admin/people/expiration');
}

View File

@@ -0,0 +1,16 @@
name = Roles
description = Assigns permanent or expirable roles based on product purchases.
dependencies[] = uc_product
dependencies[] = uc_order
package = Ubercart - core (optional)
core = 7.x
; Test cases
files[] = tests/uc_roles.test
; Information added by Drupal.org packaging script on 2013-12-17
version = "7.x-3.6"
core = "7.x"
project = "ubercart"
datestamp = "1387304010"

View File

@@ -0,0 +1,210 @@
<?php
/**
* @file
* Install, update and uninstall functions for the uc_roles module.
*/
/**
* Implements hook_schema().
*/
function uc_roles_schema() {
$schema['uc_roles_products'] = array(
'description' => 'Maps purchasable roles to Ubercart products.',
'fields' => array(
'rpid' => array(
'description' => 'Primary key: the role-product id.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'pfid' => array(
'description' => 'The {uc_product_features}.pfid of the product feature this is attached to.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'description' => 'The {node}.nid of the node this role feature is attached to.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'model' => array(
'description' => 'The product model.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'rid' => array(
'description' => 'The {role}.rid that is purchased with the attached product.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
// Start of expiration period
// Not actually implemented yet, this is a placeholder.
'start_override' => array(
'description' => 'Override the store default start time? 1 => Yes. 0 => No.',
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
'default' => 0,
),
'start_time' => array(
'description' => 'Role expiration start time. 0 signifies to start at product purchase.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
),
// End of expiration period
'end_override' => array(
'description' => 'Override the default end time? 1 => Yes. 0 => No.',
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
'default' => 0,
),
'end_time' => array(
'description' => 'Role expiration end time. 0 signifies to use a relative expiration.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
),
'duration' => array(
'description' => 'The duration of the granted role, using the value of granualarity.',
'type' => 'int',
'size' => 'small',
),
'granularity' => array(
'description' => 'The units of time of duration.',
'type' => 'varchar',
'length' => 32,
),
'shippable' => array(
'description' => 'Is this role feature shippable? 1 => Yes. 0 => No.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'by_quantity' => array(
'description' => 'Multiply any relative expiration by the quantity purchased? 1 => Yes. 0 => No.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'nid' => array('nid'),
'model' => array('model'),
'rid' => array('rid'),
),
'primary key' => array('rpid'),
'foreign keys' => array(
'uc_product_features' => array(
'table' => 'uc_product_features',
'columns' => array('pfid' => 'pfid'),
),
'uc_products' => array(
'table' => 'uc_products',
'columns' => array('nid' => 'nid'),
),
'role' => array(
'table' => 'role',
'columns' => array('rid' => 'rid'),
),
),
);
$schema['uc_roles_expirations'] = array(
'description' => 'Store expiration dates of purchased roles.',
'fields' => array(
'reid' => array(
'description' => 'Primary key: the unique expiration id.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The {users}.uid owning the role.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'rid' => array(
'description' => 'The {role}.rid of the purchased role.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'expiration' => array(
'description' => 'The Unix timestamp indicating when the role will be removed from the user account.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'notified' => array(
'description' => 'A flag indicating that the user was warned that the role will be removed soon.',
'type' => 'int',
'size' => 'tiny',
),
),
'indexes' => array(
'uid' => array('uid'),
'rid' => array('rid'),
),
'primary key' => array('reid'),
'foreign keys' => array(
'users' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'role' => array(
'table' => 'role',
'columns' => array('rid' => 'rid'),
),
),
);
return $schema;
}
/**
* Implements hook_update_last_removed().
*/
function uc_roles_update_last_removed() {
// 7.x-3.0-beta2 and earlier were installed with schema version 0,
// which causes update.php to fail.
return drupal_get_installed_schema_version('uc_roles') == 0 ? 0 : 6004;
}
/**
* Implements hook_uninstall().
*/
function uc_roles_uninstall() {
db_delete('uc_product_features')
->condition('fid', 'role')
->execute();
db_delete('variable')
->condition('name', 'uc_roles_%', 'LIKE')
->execute();
}
/**
* Remove unused variables.
*/
function uc_roles_update_7300() {
variable_del('uc_roles_default_expiration_header');
variable_del('uc_roles_default_expiration_message');
variable_del('uc_roles_default_expiration_title');
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,383 @@
<?php
/**
* @file
* Rules hooks for uc_roles.module.
*/
/**
* Implements hook_rules_data_info().
*
* An entity is defined in order to get role expiration tokens in the email.
*/
function uc_roles_rules_data_info() {
// CA entity for a role expiration object.
$entities['uc_roles_expiration'] = array(
'label' => t('Ubercart role expiration'),
'wrap' => TRUE,
'token type' => 'uc_role',
'property info' => array(
'reid' => array(
'type' => 'integer',
'label' => t('Role expiration ID'),
'description' => t('Primary key for role expirations.'),
),
'uid' => array(
'type' => 'integer',
'label' => t('User ID'),
'description' => t('The user account ID.'),
),
'user' => array(
'type' => 'user',
'label' => t('User'),
'description' => t('The user account that has the role.'),
'getter callback' => 'uc_roles_get_expiration_properties',
'setter callback' => 'uc_roles_set_expiration_properties',
),
'rid' => array(
'type' => 'integer',
'label' => t('Role ID'),
'description' => t('The granted role.'),
),
'expiration' => array(
'type' => 'date',
'label' => t('Expiration time'),
'description' => t('The time the role will be removed from the user.'),
),
'notified' => array(
'type' => 'boolean',
'label' => t('Notified'),
'description' => t('Indicates the user has been warned that the role will be removed soon.'),
),
),
);
return $entities;
}
/**
* Callback for getting role expiration properties.
*
* @see entity_metadata_node_entity_info_alter()
*/
function uc_roles_get_expiration_properties($expiration, array $options, $name, $entity_type) {
switch ($name) {
case 'user':
return $expiration->uid;
}
}
/**
* Callback for setting role expiration properties.
*
* @see entity_metadata_node_entity_info_alter()
*/
function uc_roles_set_expiration_properties($expiration, $name, $value) {
if ($name == 'user') {
$expiration->uid = $value;
}
}
/**
* Implements hook_rules_action_info().
*/
function uc_roles_rules_action_info() {
// Renew a role expiration.
$actions['uc_roles_order_renew'] = array(
'label' => t('Renew the roles on an order.'),
'group' => t('Renewal'),
'base' => 'uc_roles_action_order_renew',
'parameter' => array(
'order' => array(
'type' => 'uc_order',
'label' => t('Order'),
),
'message' => array(
'type' => 'boolean',
'label' => t('Display messages to alert users of any new or updated roles.'),
),
),
);
$email_args = array(
'expiration' => array(
'type' => 'uc_roles_expiration',
'label' => t('Role expiration'),
),
'from' => array(
'type' => 'text',
'label' => t('Sender'),
),
'addresses' => array(
'type' => 'text',
'label' => t('Recipients'),
),
'subject' => array(
'type' => 'text',
'label' => t('Subject'),
),
'message' => array(
'type' => 'text',
'label' => t('Message'),
),
'format' => array(
'type' => 'text',
'label' => t('Message format'),
'options list' => 'uc_roles_message_formats',
),
);
// Send an email to an order with a role expiration
$actions['uc_roles_order_email'] = array(
'label' => t('Send an order email regarding roles.'),
'group' => t('Notification'),
'base' => 'uc_roles_action_order_email',
'parameter' => array(
'order' => array(
'type' => 'uc_order',
'label' => t('Order'),
),
) + $email_args,
);
// Send an email to a user with a role expiration
$actions['uc_roles_user_email'] = array(
'label' => t('Send a user an email regarding roles.'),
'group' => t('Notification'),
'base' => 'uc_roles_action_user_email',
'parameter' => array(
'account' => array(
'type' => 'user',
'label' => t('User'),
),
) + $email_args,
);
return $actions;
}
/**
* Options list callback for message formats.
*/
function uc_roles_message_formats() {
global $user;
$options = array();
$formats = filter_formats($user);
foreach ($formats as $format) {
$options[$format->format] = $format->name;
}
return $options;
}
/**
* Implements hook_rules_event_info().
*/
function uc_roles_rules_event_info() {
$order = array(
'type' => 'uc_order',
'label' => t('Order'),
);
$account = array(
'type' => 'user',
'label' => t('User'),
);
$expiration = array(
'type' => 'uc_roles_expiration',
'label' => t('Role expiration'),
);
$events['uc_roles_notify_grant'] = array(
'label' => t('E-mail for granted roles'),
'group' => t('Notification'),
'variables' => array(
'order' => $order,
'expiration' => $expiration,
),
);
$events['uc_roles_notify_revoke'] = array(
'label' => t('E-mail for revoked roles'),
'group' => t('Notification'),
'variables' => array(
'account' => $account,
'expiration' => $expiration,
),
);
$events['uc_roles_notify_renew'] = array(
'label' => t('E-mail for renewed roles'),
'group' => t('Notification'),
'variables' => array(
'order' => $order,
'expiration' => $expiration,
),
);
$events['uc_roles_notify_reminder'] = array(
'label' => t('E-mail for role expiration reminders'),
'group' => t('Notification'),
'variables' => array(
'account' => $account,
'expiration' => $expiration,
),
);
return $events;
}
/**
* Send an email with order and role replacement tokens.
*
* The recipients, subject, and message fields take order token replacements.
*
* @see uc_roles_action_order_email_form()
*/
function uc_roles_action_order_email($order, $role_expiration, $from, $addresses, $subject, $message, $format) {
$settings = array(
'from' => $from,
'addresses' => $addresses,
'subject' => $subject,
'message' => $message,
'format' => $format,
);
// Token replacements for the subject and body
$settings['replacements'] = array(
'uc_order' => $order,
'uc_role' => $role_expiration,
);
// Replace tokens and parse recipients.
$recipients = array();
$addresses = token_replace($settings['addresses'], $settings['replacements']);
foreach (explode("\n", $addresses) as $address) {
$address = trim($address);
// Remove blank lines
if (!empty($address)) {
$recipients[] = $address;
}
}
// Send to each recipient.
foreach ($recipients as $email) {
$sent = drupal_mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_language($email), $settings, $settings['from']);
if (!$sent['result']) {
watchdog('uc_roles', 'Attempt to e-mail @email concerning order @order_id failed.', array('@email' => $email, '@order_id' => $order->order_id), WATCHDOG_ERROR);
}
}
}
/**
* Send an email with order and role replacement tokens.
*
* The recipients, subject, and message fields take order token replacements.
*
* @see uc_roles_action_user_email_form()
*/
function uc_roles_action_user_email($account, $role_expiration, $from, $addresses, $subject, $message, $format) {
$settings = array(
'from' => $from,
'addresses' => $addresses,
'subject' => $subject,
'message' => $message,
'format' => $format,
);
// Token replacements for the subject and body
$settings['replacements'] = array(
'user' => $account,
'uc_role' => $role_expiration,
);
// Replace tokens and parse recipients.
$recipients = array();
$addresses = token_replace($settings['addresses'], $settings['replacements']);
foreach (explode("\n", $addresses) as $address) {
$address = trim($address);
// Remove blank lines
if (!empty($address)) {
$recipients[] = $address;
}
}
// Send to each recipient.
foreach ($recipients as $email) {
$sent = drupal_mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_language($email), $settings, $settings['from']);
if (!$sent['result']) {
watchdog('uc_roles', 'Attempt to e-mail @email concerning role notification failed.', array('@email' => $email), WATCHDOG_ERROR);
}
}
}
/**
* Renews an order's product roles.
*
* This function updates expiration time on all roles found on all products
* on a given order. First, the order user is loaded, then the order's products
* are scanned for role product features. If any are found, the expiration time
* of the role is set using the feature settings to determine the new length of
* time the new expiration will last. An order comment is saved, and the user
* is notified in Drupal, as well as through the email address associated with
* the order.
*
* @param $order
* An Ubercart order object.
* @param $message
* If TRUE, messages will be displayed to the user about the renewal.
*/
function uc_roles_action_order_renew($order, $message) {
// Load the order's user and exit if not available.
if (!($account = user_load($order->uid))) {
return;
}
// Loop through all the products on the order.
foreach ($order->products as $product) {
// Look for any role promotion features assigned to the product.
$roles = db_query("SELECT * FROM {uc_roles_products} WHERE nid = :nid", array(':nid' => $product->nid));
foreach ($roles as $role) {
// Product model matches, or was 'any'.
if (!empty($role->model) && $role->model != $product->model) {
continue;
}
$existing_role = db_query("SELECT * FROM {uc_roles_expirations} WHERE uid = :uid AND rid = :rid", array(':uid' => $account->uid, ':rid' => $role->rid))->fetchObject();
// Determine the expiration timestamp for the role.
$expiration = _uc_roles_product_get_expiration($role, $product->qty, isset($existing_role->expiration) ? $existing_role->expiration : NULL);
// Leave an order comment.
if (isset($existing_role->expiration)) {
$op = 'renew';
$comment = t('Customer user role %role renewed.', array('%role' => _uc_roles_get_name($role->rid)));
// Renew the user's role.
uc_roles_renew($account, $role->rid, $expiration, !$message);
}
else {
$op = 'grant';
$comment = t('Customer granted user role %role.', array('%role' => _uc_roles_get_name($role->rid)));
// Grant the role to the user.
uc_roles_grant($account, $role->rid, $expiration, TRUE, !$message);
}
// Get the new expiration (if applicable)
$new_expiration = db_query("SELECT * FROM {uc_roles_expirations} WHERE uid = :uid AND rid = :rid", array(':uid' => $account->uid, ':rid' => $role->rid))->fetchObject();
if (!$new_expiration) {
$new_expiration = new stdClass();
$new_expiration->uid = $account->uid;
$new_expiration->rid = $role->rid;
$new_expiration->expiration = NULL;
}
uc_order_comment_save($order->order_id, $account->uid, $comment);
// Trigger role email.
rules_invoke_event('uc_roles_notify_' . $op, $order, $new_expiration);
}
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* @file
* Default Rules configurations for uc_roles.module.
*/
/**
* Implements hook_defualt_rules_configuration().
*/
function uc_roles_default_rules_configuration() {
$configs = array();
// Renew all the roles on an order when the status matches what's set
// in the roles admin settings.
$rule = rules_reaction_rule();
$rule->label = t('Grant or renew purchased roles');
$rule->active = TRUE;
$rule->event('uc_order_status_update');
$rule->condition('data_is', array('data:select' => 'updated_order:order-status', 'value' => 'payment_received'))
->action('uc_roles_order_renew', array('order:select' => 'updated_order', 'message' => FALSE));
$configs['uc_role_renewal'] = $rule;
$order_args = array(
'order:select' => 'order',
'expiration:select' => 'expiration',
);
$user_args = array(
'account:select' => 'account',
'expiration:select' => 'expiration',
);
// Notify the user when a role is granted.
$rule = rules_reaction_rule();
$rule->label = t('Notify customer when a role is granted');
$rule->active = TRUE;
$rule->event('uc_roles_notify_grant');
$rule->action('uc_roles_order_email', array(
'order:select' => 'order',
'expiration:select' => 'expiration',
'from' => uc_store_email_from(),
'addresses' => '[order:email]',
'subject' => uc_get_message('uc_roles_grant_subject'),
'message' => uc_get_message('uc_roles_grant_message'),
'format' => filter_default_format(),
));
$configs['uc_role_notify_grant'] = $rule;
// Notify the user when a role is revoked.
$rule = rules_reaction_rule();
$rule->label = t('Notify customer when a role is revoked');
$rule->active = TRUE;
$rule->event('uc_roles_notify_revoke');
$rule->action('uc_roles_user_email', array(
'account:select' => 'account',
'expiration:select' => 'expiration',
'from' => uc_store_email_from(),
'addresses' => '[account:mail]',
'subject' => uc_get_message('uc_roles_revoke_subject'),
'message' => uc_get_message('uc_roles_revoke_message'),
'format' => filter_default_format(),
));
$configs['uc_role_notify_revoke'] = $rule;
// Notify the user when a role is renewed.
$rule = rules_reaction_rule();
$rule->label = t('Notify customer when a role is renewed');
$rule->active = TRUE;
$rule->event('uc_roles_notify_renew');
$rule->action('uc_roles_order_email', array(
'order:select' => 'order',
'expiration:select' => 'expiration',
'from' => uc_store_email_from(),
'addresses' => '[order:email]',
'subject' => uc_get_message('uc_roles_renew_subject'),
'message' => uc_get_message('uc_roles_renew_message'),
'format' => filter_default_format(),
));
$configs['uc_role_notify_renew'] = $rule;
// Notify the user when a role is about to expire.
$rule = rules_reaction_rule();
$rule->label = t('Notify customer when a role is about to expire');
$rule->active = TRUE;
$rule->event('uc_roles_notify_reminder');
$rule->action('uc_roles_user_email', array(
'account:select' => 'account',
'expiration:select' => 'expiration',
'from' => uc_store_email_from(),
'addresses' => '[account:mail]',
'subject' => uc_get_message('uc_roles_reminder_subject'),
'message' => uc_get_message('uc_roles_reminder_message'),
'format' => filter_default_format(),
));
$configs['uc_role_notify_reminder'] = $rule;
return $configs;
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* @file
* Theme functions for the uc_roles module.
*/
/**
* Themes the roles dialog on the account edit page.
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_uc_roles_user_new($variables) {
$form = $variables['form'];
// Render the expiration tables first.
$output = drupal_render($form['expirations']);
$output .= '<div class="expiration">';
$output .= drupal_render($form['new_role']);
$output .= drupal_render($form['new_role_add']);
$output .= drupal_render($form['new_role_add_for']);
$output .= drupal_render($form['new_role_add_qty']);
$output .= drupal_render($form['new_role_add_granularity']);
$output .= '</div>';
return $output;
}
/**
* Themes the role expiration table on the account edit page.
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_uc_roles_user_expiration($variables) {
$form = $variables['form'];
$header = array(
array('data' => t('Make permanent')),
array('data' => t('Role')),
array('data' => t('Expiration')),
array('data' => t('Add/remove time')),
);
$rows = array();
// The expiration table.
foreach ((array)$form['table'] as $rid => $expiration) {
// We only want numeric rid's
if (!is_numeric($rid)) {
continue;
}
// Make sure the renders actually touch the elements.
$data = &$form['table'][$rid];
$rows[] = array(
array('data' => drupal_render($data['remove'])),
array('data' => check_plain($data['name']['#value'])),
array('data' => format_date($data['expiration']['#value'], 'short')),
// Options to adjust the expiration.
array('data' => '<a name="role-expiration-' . $rid . '">' .
'<div class="expiration">' .
drupal_render($data['polarity']) . drupal_render($data['qty']) . drupal_render($data['granularity']) .
'</div></a>'),
);
}
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
'caption' => t('Below you can add or remove time to the expiration dates of the following roles.'),
'empty' => t('There are no pending expirations for roles this user.'),
));
$output .= drupal_render_children($form);
return $output;
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* @file
* Token hooks for the uc_roles module.
*/
/**
* Implements hook_token_info().
*/
function uc_roles_token_info() {
$type = array(
'name' => t('Role promotions'),
'description' => t('Tokens related to purchased, temporary roles.'),
'needs-data' => 'uc_role',
);
$tokens['expiration'] = array(
'name' => t('Expiration'),
'description' => t('The date the role will expire.'),
'type' => 'date',
);
$tokens['name'] = array(
'name' => t('Role'),
'description' => t('The associated role name'),
);
return array(
'types' => array('uc_role' => $type),
'tokens' => array('uc_role' => $tokens),
);
}
/**
* Implements hook_tokens().
*/
function uc_roles_tokens($type, $tokens, $data = array(), $options = array()) {
$language_code = NULL;
if (isset($options['language'])) {
$language_code = $options['language']->language;
}
$sanitize = !empty($options['sanitize']);
$replacements = array();
if ($type == 'uc_role' && !empty($data['uc_role'])) {
$object = $data['uc_role'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'expiration':
$replacements[$original] = format_date($object->expiration, 'medium');
break;
case 'name':
$replacements[$original] = $sanitize ? check_plain(_uc_roles_get_name($object->rid)) : _uc_roles_get_name($object->rid);
break;
}
}
if ($expiration_tokens = token_find_with_prefix($tokens, 'expiration')) {
$replacements += token_generate('date', $expiration_tokens, array('date' => $object->expiration), $options);
}
}
return $replacements;
}