You are here

function domain_views_access in Domain Views 7

Access callback for use with domain_views_plugin_access.

Parameters

$domains: An array of domain ids that may access this view.

$strict: Boolean value indicating if strict rules should be applied.

$member: Boolean value indicating if membership rules should be applied.

Return value

Boolean TRUE or FALSE.

1 call to domain_views_access()
domain_views_plugin_access::access in includes/domain_views_plugin_access.inc
Determine if the current user has access or not.
1 string reference to 'domain_views_access'
domain_views_plugin_access::get_access_callback in includes/domain_views_plugin_access.inc
Determine the access callback and arguments.

File

./domain_views.module, line 100
Provides a Views filter for the Domain Access module.

Code

function domain_views_access($domains, $strict = TRUE, $member = FALSE) {
  global $_domain, $user;
  $account = $user;
  $check = FALSE;

  // Apply membership rules?
  if ($member) {
    $grants['domain_id'] = domain_get_user_domains($account);
    if (isset($grants['domain_id'][-1])) {
      $grants['domain_id'][0] = 0;
      unset($grants['domain_id'][-1]);
    }
    $check = TRUE;
  }

  // Apply strict rules? These are harsher than membership and get applied last.
  if ($strict) {
    $grants = domain_views_get_grants();
    $check = TRUE;
  }

  // If no grants, stop.
  if ($check && (empty($grants['domain_id']) || !in_array($_domain['domain_id'], $grants['domain_id']))) {
    return FALSE;
  }
  elseif (!$check) {
    $grants['domain_id'] = array(
      $_domain['domain_id'],
    );
  }

  // Otherwise, convert and check.
  foreach ($grants['domain_id'] as $grant) {
    if ($grant == 0) {
      $grant = -1;
    }
    if (in_array($grant, $domains)) {
      return TRUE;
    }
  }
  return FALSE;
}