public static function BookAccess::addRoleGrants in Book access 1.x
Adds role grants to book pages.
Parameters
$bid: The book ID.
$rids: An array of role IDs for which to add the book grants.
$grants: An array of grants, in the format
$grants[$grant][$rid];
, where
$grant;
is a string between 'grant_view', 'grant_update', 'grant_delete', 'grant_admin_access', 'grant_add_child', 'grant_edit_outline', and
$rid;
is the role ID.
2 calls to BookAccess::addRoleGrants()
- BookAccess::resetToDefault in src/
Access/ BookAccess.php - Resets book permissions to its defaults, ignoring user-specific ones.
- BookAccess::setRoleGrants in src/
Access/ BookAccess.php - Sets the role grants for book pages.
File
- src/
Access/ BookAccess.php, line 68 - 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 addRoleGrants($bid, array $rids, array $grants) {
$row = new stdClass();
$row->nid = $bid;
foreach ($rids as $rid) {
$row->rid = $rid;
$bool = db_query_range("SELECT 1 FROM {book_access_role} WHERE nid = :nid AND rid = :rid", 0, 1, array(
':nid' => $bid,
':rid' => $rid,
))
->fetchField();
$granted = 0;
foreach (self::grantIDs() as $id) {
$row->{$id} = !empty($grants[$id][$rid]);
if ($row->{$id} != 0) {
$granted++;
}
}
if ($granted > 0) {
drupal_write_record('book_access_role', $row, $bool ? array(
'nid',
'rid',
) : array());
}
}
}