You are here

public static function BookAccess::getBookList in Book access 7.2

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

Lists all the books to which the current user has access.

Parameters

$account: The user account to use; if NULL, the currently logged in user account will be used.

$grants: An array containing one or more values between 'view', 'update', 'delete', 'admin_access', 'add_child', and 'edit_outline'.

Return value

An array containing the node ID of the books to which the user has access.

1 call to BookAccess::getBookList()
BookAccess::restrictOptions in ./book_access.module
Restricts the options available to who moves book pages between books.

File

./book_access.module, line 350
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 getBookList(array $grants = array(
  'update',
), $account = NULL) {
  $permitted_bids = array();
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }
  foreach ($grants as $grant) {
    $result = db_query("SELECT nid FROM {book_access_author} WHERE uid = :uid AND grant_{$grant} > 0", array(
      ':uid' => $account->uid,
    ));
    foreach ($result as $book) {
      $permitted_bids[$book->nid] = $book->nid;
    }
    $roles = array_keys($account->roles);
    $result = db_query("SELECT nid FROM {book_access_role} WHERE rid IN (:rid) AND grant_{$grant} > 0", array(
      ':rid' => $roles,
    ));
    foreach ($result as $book) {
      $permitted_bids[$book->nid] = $book->nid;
    }
    $result = db_query("SELECT nid FROM {book_access_user} WHERE uid = :uid AND grant_{$grant} > 0", array(
      ':uid' => $account->uid,
    ));
    foreach ($result as $book) {
      $permitted_bids[$book->nid] = $book->nid;
    }
  }
  return $permitted_bids;
}