You are here

block_access.db.inc in Block Access 6.2

Same filename and directory in other branches
  1. 6 block_access.db.inc
  2. 7 block_access.db.inc

File

block_access.db.inc
View source
<?php

/* 
 * @file block_access.db.inc
 * DB interface for block_access module
 */
function block_access_delete_roles($module, $perm, $delta = null) {
  $sql = "\n    DELETE FROM {block_access_roles} \n    WHERE module = '%s'\n    AND   permission = '%s'\n  ";
  $args = array(
    $module,
    $perm,
  );
  if ($delta !== null) {
    $sql .= "AND delta = '%s'";
    $args[] = $delta;
  }
  else {
    $sql .= "AND delta = ''";
  }
  db_query($sql, $args);
}
function block_access_add_role($rid, $module, $perm, $delta = null) {
  db_query("\n    INSERT INTO {block_access_roles}\n    (\n      rid,\n      module,\n      delta,\n      permission\n    )\n    VALUES\n    (\n      %d,\n      '%s',\n      '%s',\n      '%s'\n    )", $rid, $module, $delta, $perm);
}
function block_access_get_roles($module, $perm, $delta = null) {
  $ret = array();
  $sql = "\n    SELECT rid\n    FROM {block_access_roles}\n    WHERE module = '%s'\n    AND   permission = '%s'\n    AND   delta = '%s';\n  ";
  $result = db_query($sql, $module, $perm, $delta);
  while ($rid = db_result($result)) {
    $ret[] = $rid;
  }

  // If we didn't find any for the delta, use the module defaults
  if (empty($ret)) {
    $result = db_query($sql, $module, $perm, '');
    while ($rid = db_result($result)) {
      $ret[] = $rid;
    }
  }
  return $ret;
}
function block_access_get_module($module) {
  $sql = "\n    SELECT rid, permission\n    FROM {block_access_roles}\n    WHERE module = '%s'\n    AND   delta = ''";
  $result = db_query($sql, $module);
  $ret = array();
  while ($ob = db_fetch_object($result)) {
    if (isset($ret[$ob->rid])) {
      $ret[$ob->rid][] = $ob->permission;
    }
    else {
      $ret[$ob->rid] = array(
        $ob->permission,
      );
    }
  }
  return $ret;
}