You are here

public static function BookAccess::addRoleGrants in Book access 7.2

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

Adds role grants to book pages.

Parameters

$bid: The book ID.

$rids: An array of role IDs for which to add the book grants.

$grants: 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.

3 calls to BookAccess::addRoleGrants()
BookAccess::resetToDefault in ./book_access.module
Resets book permissions to its defaults, ignoring user-specific ones.
BookAccess::setRoleGrants in ./book_access.module
Sets the role grants for book pages.
book_access_node_update in ./book_access.module
Implements hook_node_update().

File

./book_access.module, line 63
Allows to set the access control for book nodes on a per book basis. Based on forum_access.module and tac_lite.module.

Class

BookAccess
@file

Code

public static function addRoleGrants($bid, array $rids, array $grants) {
  $row = new stdClass();
  $row->nid = $bid;
  foreach ($rids as $rid) {
    $row->rid = $rid;
    $bool = db_query_range("SELECT 1 FROM {book_access_role} WHERE nid = :nid AND rid = :rid", 0, 1, array(
      ':nid' => $bid,
      ':rid' => $rid,
    ))
      ->fetchField();
    $granted = 0;
    foreach (self::grantIDs() as $id) {
      $row->{$id} = !empty($grants[$id][$rid]);
      if ($row->{$id} != 0) {
        $granted++;
      }
    }
    if ($granted > 0) {
      drupal_write_record('book_access_role', $row, $bool ? array(
        'nid',
        'rid',
      ) : array());
    }
  }
}