You are here

public static function BookAccess::getRoleGrants in Book access 6.2

Same name and namespace in other branches
  1. 7.2 book_access.module \BookAccess::getRoleGrants()

Returns the role book grants.

Parameters

$bid: The book ID.

$roles: The variables where to store the value returned by user_roles().

$defaults: An array containing the default values for the grants.

Return value

An array of grants, in the format

$grants[$grant][$rid];

, where

$grant;

is a string between 'grant_view', 'grant_update', 'grant_delete', 'grant_admin_access', 'grant_add_child', 'grant_edit_outline', and

$rid;

is the role ID.

1 call to BookAccess::getRoleGrants()
book_access_ui_grants_form in ./book_access_ui.admin.inc
Form builder for the book access configuration page.

File

./book_access.module, line 402
Allows to set the access control for book nodes on a per book basis. It is based on forum_access.module and tac_lite.module.

Class

BookAccess
@file

Code

public static function getRoleGrants($bid, &$roles, array $defaults = array()) {
  $grants = array(
    'grant_view' => array(),
    'grant_update' => array(),
    'grant_delete' => array(),
    'grant_admin_access' => array(),
    'grant_add_child' => array(),
    'grant_edit_outline' => array(),
  );
  $roles = user_roles();
  $rcopy = $roles;
  $rids = array_keys($roles);
  $result = db_query("SELECT * FROM {book_access_role} WHERE nid = %d AND rid IN (" . db_placeholders($rids) . ")", array_merge(array(
    $bid,
  ), $rids));

  // Build the role access permissions for the book.
  while ($access = db_fetch_object($result)) {
    unset($rcopy[$access->rid]);
    foreach (self::grantIDs() as $id) {
      $grants[$id][$access->rid] = !empty($access->{$id});
    }
  }
  $defaults = array_filter($defaults);

  // Set the default role access permissions for the roles that don't have
  // access permissions already set.
  foreach (self::grantIDs() as $id) {
    foreach ($rcopy as $rid => $name) {
      $grants[$id][$rid] = !empty($defaults[$id]);
    }
  }
  return $grants;
}