You are here

function checklistapi_checklist_access in Checklist API 7

Same name and namespace in other branches
  1. 8 checklistapi.module \checklistapi_checklist_access()

Access callback: Checks the current user's access to a given checklist.

Parameters

string $id: The checklist ID.

string $operation: (optional) The operation to test access for. Accepted values are "view", "edit", and "any". Defaults to "any".

Return value

bool Returns TRUE if the current user has access to perform a given operation on the specified checklist, or FALSE if not.

2 calls to checklistapi_checklist_access()
ChecklistapiChecklist::userHasAccess in lib/Drupal/checklistapi/ChecklistapiChecklist.php
Determines whether the current user has access to the checklist.
checklistapi_permission in ./checklistapi.module
Implements hook_permission().
1 string reference to 'checklistapi_checklist_access'
checklistapi_menu in ./checklistapi.module
Implements hook_menu().

File

./checklistapi.module, line 24
An API for creating fillable, persistent checklists.

Code

function checklistapi_checklist_access($id, $operation = 'any') {
  $all_operations = array(
    'view',
    'edit',
    'any',
  );
  if (!in_array($operation, $all_operations)) {
    throw new Exception(t('No such operation "@operation"', array(
      '@operation' => $operation,
    )));
  }
  $access['view'] = user_access('view any checklistapi checklist') || user_access('view ' . $id . ' checklistapi checklist');
  $access['edit'] = user_access('edit any checklistapi checklist') || user_access('edit ' . $id . ' checklistapi checklist');
  $access['any'] = $access['view'] || $access['edit'];
  return $access[$operation];
}