You are here

public static function BookAccess::getBookList in Book access 6.2

Same name and namespace in other branches
  1. 7.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 287
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 getBookList(array $grants = array(
  'update',
), $account = NULL) {
  $permitted_bids = array();
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }
  foreach ($grants as $grant) {
    $query = db_query("SELECT nid FROM {book_access_author} WHERE uid = %d AND grant_{$grant} > 0", $account->uid);
    while ($result = db_fetch_object($query)) {
      $permitted_bids[$result->nid] = $result->nid;
    }
    $roles = array_keys($account->roles);
    $query = db_query("SELECT nid FROM {book_access_role} WHERE rid IN (" . db_placeholders($roles) . ") AND grant_{$grant} > 0", $roles);
    while ($result = db_fetch_object($query)) {
      $permitted_bids[$result->nid] = $result->nid;
    }
    $query = db_query("SELECT nid FROM {book_access_user} WHERE uid = %d AND grant_{$grant} > 0", $account->uid);
    while ($result = db_fetch_object($query)) {
      $permitted_bids[$result->nid] = $result->nid;
    }
  }
  return $permitted_bids;
}