You are here

public static function BookAccess::getGrantRecords in Book access 6.2

Same name and namespace in other branches
  1. 7.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()
BookAccess::writeGrantRecords in ./book_access.module
book_access_node_access_records in ./book_access.module
Implements hook_node_access_records().

File

./book_access.module, line 339
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 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 = %d", $bid);
    while ($grant = db_fetch_object($result)) {
      $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' => self::GRANT_PRIORITY,
      );
    }
  }
  return $grants;
}