You are here

function _homebox_can_view_block in Homebox 6.2

Same name and namespace in other branches
  1. 6.3 homebox.module \_homebox_can_view_block()
  2. 7.3 homebox.module \_homebox_can_view_block()
  3. 7.2 homebox.module \_homebox_can_view_block()

Determine if user has access to view a block

Parameters

$block: A block object

$user: Optional user object, use current user if not provided

Return value

Boolean value of user's access to the block

1 call to _homebox_can_view_block()
homebox_prepare_block in ./homebox.module
Prepare a block for rendering with theme('homebox_block').

File

./homebox.module, line 747
Homebox main file, takes care of global functions settings constants, etc.

Code

function _homebox_can_view_block($block, $user = NULL) {

  // Use current user if non provided
  if (!$user) {
    global $user;
  }

  // Check for roles set at the block level
  $allowed_roles = db_query("SELECT rid FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $block->module, $block->delta);

  // Indicate whether or not role restrictions were set on the block
  $role_set = FALSE;

  // Iterate all available block roles
  while ($role = db_fetch_object($allowed_roles)) {
    if (isset($user->roles[$role->rid])) {
      return TRUE;
    }
    $role_set = TRUE;
  }

  // We checked available roles, and didn't match any
  if ($role_set) {
    return FALSE;
  }

  // Block created with Views, check access
  if ($block->module == 'views') {
    if (!_homebox_check_views_block_access($block)) {
      return FALSE;
    }
  }

  // If here, user has access
  return TRUE;
}