You are here

public static function BookAccess::deleteGrants in Book access 7.2

Same name and namespace in other branches
  1. 6.2 book_access.module \BookAccess::deleteGrants()

Resets the book access grants from the database.

NOTE: once a grant has been created, it is merely set to 0 to avoid using defaults.

Parameters

$value: The value to look for. param $field The database field where to look the value. The currently accepted values are 'bid', 'nid', 'uid', 'rid'.

$types: An array of grants types for which the function deletes records; the currently used values are 'author', 'role', 'user'. When this parameter is not passed, the method cues off the $field setting.

2 calls to BookAccess::deleteGrants()
book_access_node_delete in ./book_access.module
Implements hook_node_delete().
book_access_user_delete in ./book_access.module
Implements hook_user_delete().

File

./book_access.module, line 257
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 deleteGrants($value, $field = 'nid', array $types = NULL) {
  if (isset($types)) {
    $tables = array();
    foreach ($types as $type) {
      switch ($type) {
        case 'author':
        case 'role':
        case 'user':
          $tables[] = "book_access_{$type}";
          break;
      }
    }
  }
  else {
    switch ($field) {
      case 'bid':
      case 'nid':
        $tables = array(
          'book_access_author',
          'book_access_role',
          'book_access_user',
        );
        break;
      case 'uid':
        $tables = array(
          'book_access_author',
          'book_access_user',
        );
        break;
      case 'rid':
        $tables = array(
          'book_access_role',
        );
        break;
      default:
        $tables = array();
    }
  }
  foreach ($tables as $table) {
    db_update($table)
      ->fields(array(
      "grant_admin_access" => 0,
      "grant_update" => 0,
      "grant_delete" => 0,
      "grant_add_child" => 0,
      "grant_edit_outline" => 0,
      "grant_view" => 0,
    ))
      ->condition($field == "bid" ? "nid" : $field, $value, '=')
      ->execute();
  }
}