public static function BookAccess::getGrantRecords in Book access 1.x
Gets the list of grant records assigned to a book.
Parameters
$bid: The ID of the book for which the function returns the grant records.
$types: An array of grants types for which the function returns the records; the currently used values are 'author', 'role', 'user'.
Return value
The array of grant records for the specified book.
1 call to BookAccess::getGrantRecords()
- BookAccess::writeGrantRecords in src/
Access/ BookAccess.php
File
- src/
Access/ BookAccess.php, line 407 - 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 getGrantRecords($bid, array $types = array(
'author',
'role',
'user',
)) {
$grants = array();
$info = array();
foreach ($types as $type) {
switch ($type) {
case 'author':
$info[] = array(
'table' => 'book_access_author',
'gid' => 'uid',
);
break;
case 'role':
$info[] = array(
'table' => 'book_access_role',
'gid' => 'rid',
);
break;
case 'user':
$info[] = array(
'table' => 'book_access_user',
'gid' => 'uid',
);
break;
}
}
foreach ($info as $data) {
$result = db_query("SELECT * FROM {" . db_escape_table($data['table']) . "} WHERE nid = :nid", array(
':nid' => $bid,
));
foreach ($result as $grant) {
$grants[] = array(
'realm' => $data['table'],
'gid' => $grant->{$data['gid']},
'grant_view' => $grant->grant_view,
'grant_update' => $grant->grant_update,
'grant_delete' => $grant->grant_delete,
'priority' => variable_get('book_access_priority', 0),
);
}
}
return $grants;
}