You are here

function commerce_coupon_access in Commerce Coupon 7.2

Same name and namespace in other branches
  1. 7 commerce_coupon.module \commerce_coupon_access()

Checks coupon access for various operations.

Parameters

string $op: The operation being performed. One of 'view', 'update', 'create', 'redeem' or 'delete'.

object $coupon: Optionally a coupon to check access for. If nothing is given access permissions for all coupons are returned.

object $account: The user to check for. Leave it to NULL to check for the current user.

Return value

bool Whether or not we are granting access.

2 calls to commerce_coupon_access()
commerce_coupon_current_user_may_redeem in ./commerce_coupon.rules.inc
Rules condition callback.
commerce_coupon_handler_field_coupon_link::check_access in includes/views/handlers/commerce_coupon_handler_field_coupon_link.inc
Overrides parent::check_access().
3 string references to 'commerce_coupon_access'
commerce_coupon_entity_info in ./commerce_coupon.module
Implements hook_entity_info().
commerce_coupon_menu in ./commerce_coupon.module
Implements hook_menu().
commerce_coupon_views_data_alter in includes/views/commerce_coupon.views.inc
Alter the views data to enable some additional features for coupons in views.

File

./commerce_coupon.module, line 437
Provides coupon functionality for Drupal Commerce.

Code

function commerce_coupon_access($op, $coupon = NULL, $account = NULL) {

  // If there are modules that implement the coupon access hook:
  $hook = 'commerce_coupon_access_' . $op;
  $modules = module_implements($hook);
  if ($modules) {
    foreach ($modules as $module) {

      // Last module wins.
      $access = module_invoke($module, $hook, $coupon, $account);
    }
    return $access;
  }

  // Otherwise route to defaults.
  switch ($op) {
    case 'view':
    case 'update':
    case 'create':
    case 'delete':
      return commerce_entity_access($op, $coupon, $account, 'commerce_coupon');
    case 'redeem':

      // If the user can redeem all coupons of this type:
      return user_access('redeem coupons of type ' . $coupon->type) || user_access('redeem any coupon');
  }
}