public static function BookAccess::getGrantRecords in Book access 7.2
Same name and namespace in other branches
- 6.2 book_access.module \BookAccess::getGrantRecords()
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.
2 calls to BookAccess::getGrantRecords()
File
- ./
book_access.module, line 402 - 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 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;
}