You are here

function commerce_registration_defer_defer_registration_access in Commerce Registration 7.2

Implements hook_registration_access().

Checks if a user has access to defer a given registration.

1 call to commerce_registration_defer_defer_registration_access()
commerce_registration_defer_commerce_registration_order_ops_alter in modules/commerce_registration_defer/commerce_registration_defer.module
Implements hook_commerce_registration_order_ops_alter().
1 string reference to 'commerce_registration_defer_defer_registration_access'
commerce_registration_defer_menu in modules/commerce_registration_defer/commerce_registration_defer.module
Implements hook_menu().

File

modules/commerce_registration_defer/commerce_registration_defer.module, line 342
Module file for commerce_registration_defer.

Code

function commerce_registration_defer_defer_registration_access($op, $registration, $account = null) {
  $account = isset($account) ? $account : $GLOBALS['user'];
  if ($op === 'defer') {

    // Don't allow deferral if the registration is already deferred.
    if ($registration->state === 'deferred') {
      return FALSE;
    }

    // Allow other modules to provide access grants for the 'defer' op through
    // hook_registration_access(). If no module explicitly denies access and at
    // least one grants it then return true.
    $entity_access = entity_access('defer', 'registration', $registration, $account);
    if (!is_null($entity_access)) {
      return $entity_access;
    }
    if (user_access('defer any registration', $account)) {
      return TRUE;
    }
    $type = $registration
      ->bundle();
    $wrapper = entity_metadata_wrapper('registration', $registration);
    $author = $wrapper->author
      ->value();
    $account_own = $author && $author->uid == $account->uid;
    return $account_own && user_access("defer own {$type} registration", $account) || user_access("defer any {$type} registration", $account);
  }
}