You are here

function masquerade_context_condition::is_masquerading in Masquerade Extras 7

Same name and namespace in other branches
  1. 6.2 masquerade_context/plugins/condition/masquerade_context.inc \masquerade_context_condition::is_masquerading()
  2. 7.2 masquerade_context/plugins/condition/masquerade_context.inc \masquerade_context_condition::is_masquerading()

Evaluates if the account is masquerading as someone else.

@returns TRUE if the account is posing as someone else. FALSE otherwise. @retval bool

Parameters

stdClass $account: The user account to evaluate.

1 call to masquerade_context_condition::is_masquerading()
masquerade_context_condition::execute_is_masquerading in masquerade_context/plugins/condition/masquerade_context.inc
Evaluates if the account is masquerading.

File

masquerade_context/plugins/condition/masquerade_context.inc, line 150
Expose masquerade as a customizable context condition.

Class

masquerade_context_condition
@file Expose masquerade as a customizable context condition.

Code

function is_masquerading($account) {
  global $user;

  // If the account is our own, check the user session.
  if ($account->uid == $user->uid) {
    return isset($_SESSION['masquerading']) && is_numeric($_SESSION['masquerading']);
  }

  // You can override this query with:
  // hook_query_context_is_masquerading_alter().
  // @see hook_query_TAG_alter()
  $query = db_select('masquerade', 'm')
    ->addTag('context_is_masquerading')
    ->fields('m', array(
    'uid_as',
  ))
    ->condition('uid_from', $account->uid, '=')
    ->range(0, 1)
    ->execute();
  $result = $query
    ->fetchCol();
  return !empty($result);
}