You are here

public static function BookAccess::deleteGrants in Book access 1.x

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.

File

src/Access/BookAccess.php, line 262
Allows to set the access control for book nodes on a per book basis.

Class

BookAccess
@file

Namespace

Drupal\book_access\Access

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();
  }
}