You are here

function flag_flag::access in Flag 7.2

Same name and namespace in other branches
  1. 6.2 flag.inc \flag_flag::access()
  2. 7.3 includes/flag/flag_flag.inc \flag_flag::access()

Determines whether the user may flag, or unflag, the given content.

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

Parameters

$content_id: The content ID to flag/unflag.

$action: The action to test. Either 'flag' or 'unflag'. Leave NULL to determine by flag status.

$account: The user on whose behalf to test the flagging action. Leave NULL for the current user.

Return value

Boolean TRUE if the user is allowed to flag/unflag the given content. FALSE otherwise.

1 call to flag_flag::access()
flag_flag::flag in ./flag.inc
Flags, or unflags, an item.

File

./flag.inc, line 487
Implements various flags. Uses 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($content_id, $action = NULL, $account = NULL) {
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }
  if (isset($content_id) && !$this
    ->applies_to_content_id($content_id)) {

    // Flag does not apply to this content.
    return FALSE;
  }
  if (!isset($action)) {
    $uid = $account->uid;
    $sid = flag_get_sid($uid);
    $action = $this
      ->is_flagged($content_id, $uid, $sid) ? 'unflag' : 'flag';
  }

  // Base initial access on the user's basic permission to use this flag.
  $access = $this
    ->user_access($action, $account);

  // Check for additional access rules provided by sub-classes.
  $child_access = $this
    ->type_access($content_id, $action, $account);
  if (isset($child_access)) {
    $access = $child_access;
  }

  // Allow modules to disallow (or allow) access to flagging.
  $access_array = module_invoke_all('flag_access', $this, $content_id, $action, $account);
  foreach ($access_array as $set_access) {
    if (isset($set_access)) {
      $access = $set_access;
    }
  }
  return $access;
}