You are here

public static function BookAccess::addUserGrants in Book access 6.2

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

Adds user grants to book pages.

Parameters

$bid: The book ID.

$uids: An array of user IDs for which to add the book grants.

$grants: An array of grants, in the format

$grants[$grant][$uid];

, where

$grant;

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

$uid;

is the user ID.

2 calls to BookAccess::addUserGrants()
BookAccess::setUserGrants in ./book_access.module
Sets the user grants for book pages.
book_access_ui_user_add_submit in ./book_access_ui.admin.inc
Form submission callback for book_access_ui_grants_form().

File

./book_access.module, line 101
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 addUserGrants($bid, array $uids, array $grants) {
  foreach ($uids as $uid) {
    $bool = db_result(db_query_range("SELECT 1 FROM {book_access_user} WHERE nid = %d AND uid = %d", $bid, $uid, 0, 1));
    $row = new stdClass();
    $row->nid = $bid;
    $row->uid = $uid;
    foreach (self::grantIDs() as $id) {
      $row->{$id} = !empty($grants[$id][$uid]);
    }
    drupal_write_record('book_access_user', $row, $bool ? array(
      'nid',
      'uid',
    ) : array());
  }
}