You are here

function block_access_get_roles in Block Access 7

Same name and namespace in other branches
  1. 6.2 block_access.db.inc \block_access_get_roles()
  2. 6 block_access.db.inc \block_access_get_roles()

fetch roles defined for a given module/perm/block

@returns array of role IDs

Parameters

$module - the name of the module:

$perm - the permission:

$delta - optional block delta:

2 calls to block_access_get_roles()
block_access_fieldset in ./block_access.module
block_access_user_access in ./block_access.module

File

./block_access.db.inc, line 51

Code

function block_access_get_roles($module, $perm, $delta = NULL) {
  $ret = array();
  if ($delta) {
    $query = db_select('block_access_roles', 'b')
      ->fields('b', array(
      'rid',
    ))
      ->condition('module', $module, '=')
      ->condition('permission', $perm, '=')
      ->condition('delta', $delta, '=');
    $result = $query
      ->execute();
    foreach ($result as $record) {
      $ret[] = $record->rid;
    }
  }

  // If we didn't find any for the delta, or there is no delta
  // then use the module defaults
  if (empty($ret)) {
    $query = db_select('block_access_roles', 'b')
      ->fields('b', array(
      'rid',
    ))
      ->condition('module', $module, '=')
      ->condition('permission', $perm, '=')
      ->condition('delta', '', '=');
    $result = $query
      ->execute();
    foreach ($result as $record) {
      $ret[] = $record->rid;
    }
  }
  return $ret;
}