public static function BookAccess::getBookList in Book access 1.x
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 src/
Access/ BookAccess.php - Restricts the options available to who moves book pages between books.
File
- src/
Access/ BookAccess.php, line 355 - Allows to set the access control for book nodes on a per book basis.
Class
- BookAccess
- @file
Namespace
Drupal\book_access\AccessCode
public static function getBookList(array $grants = array(
'update',
), $account = NULL) {
$permitted_bids = array();
if (!isset($account)) {
$account = \Drupal::currentUser();
}
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;
}