You are here

function flag_flag::access_multiple in Flag 7.3

Same name and namespace in other branches
  1. 6.2 flag.inc \flag_flag::access_multiple()
  2. 7.2 flag.inc \flag_flag::access_multiple()

Determine access to multiple objects.

Similar to user_access() but works on multiple IDs at once. Called in the pre_render() stage of the 'Flag links' field within Views to find out where that link applies. The reason we do a separate DB query, and not lump this test in the Views query, is to make 'many to one' tests possible without interfering with the rows, and also to reduce the complexity of the code.

This method typically should not be overridden by child classes. Instead they should implement type_access_multiple(), which is called by this method.

Parameters

array $entity_ids: The array of entity IDs to check. The keys are the entity IDs, the values are the actions to test: either 'flag' or 'unflag'.

stdClass $account: (optional) The account for which the actions will be compared against. If left empty, the current user will be used.

Return value

array An array whose keys are the object IDs and values are booleans indicating access.

See also

hook_flag_access_multiple()

File

includes/flag/flag_flag.inc, line 546
Contains the flag_flag class. Flag type classes use an object oriented style inspired by that of Views 2.

Class

flag_flag
This abstract class represents a flag, or, in Views 2 terminology, "a handler".

Code

function access_multiple($entity_ids, $account = NULL) {
  $account = isset($account) ? $account : $GLOBALS['user'];
  $access = array();

  // First check basic user access for this action.
  foreach ($entity_ids as $entity_id => $action) {
    $access[$entity_id] = $this
      ->user_access($entity_ids[$entity_id], $account);
  }

  // Check for additional access rules provided by sub-classes.
  $child_access = $this
    ->type_access_multiple($entity_ids, $account);
  if (isset($child_access)) {
    foreach ($child_access as $entity_id => $entity_access) {
      if (isset($entity_access)) {
        $access[$entity_id] = $entity_access;
      }
    }
  }

  // Merge in module-defined access.
  foreach (module_implements('flag_access_multiple') as $module) {
    $module_access = module_invoke($module, 'flag_access_multiple', $this, $entity_ids, $account);
    foreach ($module_access as $entity_id => $entity_access) {
      if (isset($entity_access)) {
        $access[$entity_id] = $entity_access;
      }
    }
  }
  return $access;
}