You are here

function civicrm_entity_op_access in CiviCRM Entity 7.2

Granular per-entity CRUD access control

Parameters

$op:

$entity_type:

null $entity:

null $account:

Return value

TRUE|FALSE

1 call to civicrm_entity_op_access()
civicrm_entity_access in ./civicrm_entity.module
Entity access callback.
2 string references to 'civicrm_entity_op_access'
CivicrmEntityUIController::hook_menu in ./civicrm_entity_ui_controller.inc
Provides definitions for implementing hook_menu().
civicrm_entity_menu in ./civicrm_entity.module
Implements hook_menu().

File

./civicrm_entity.module, line 216

Code

function civicrm_entity_op_access($op, $entity_type, $entity = NULL, $account = NULL) {
  if (is_null($account)) {
    global $user;
    $account = $user;
  }
  $civicrm_entity_info = civicrm_entity_get_supported_entity_info();
  $enabled_entities = _civicrm_entity_enabled_entities();
  if (empty($enabled_entities[$entity_type])) {
    return FALSE;
  }
  if (isset($civicrm_entity_info[$entity_type]['permissions'][$op])) {
    $permissions = $civicrm_entity_info[$entity_type]['permissions'][$op];
    if (!empty($civicrm_entity_info[$entity_type]['permissions']['access callback'])) {
      $access_callback = $civicrm_entity_info[$entity_type]['permissions']['access callback'];
      return call_user_func($access_callback, $op, $entity_type, $entity, $account, $permissions);
    }
    elseif (!empty($permissions)) {
      if (is_array($permissions)) {
        if (count($permissions)) {
          foreach ($permissions as $permission) {
            if (!user_access($permission, $account)) {
              return FALSE;
            }
          }
          return TRUE;
        }
        else {
          return user_access('administer CiviCRM', $account);
        }
      }
      else {
        return user_access($permissions, $account);
      }
    }
  }
  return user_access('administer CiviCRM', $account);
}