You are here

function taxonomy_access_defaults_update in Taxonomy Access Control 5.2

Same name and namespace in other branches
  1. 5 taxonomy_access.module \taxonomy_access_defaults_update()

Updates default permissions for a role for a vocabulary

Parameters

$vid: The vocab to add the permission for.

$rid: The role id to add the permission to.

$grants: A hash of the grants in the form of $grants['perm'] = boolean A value of 1 will grant the permission for this user and term.

1 call to taxonomy_access_defaults_update()
taxonomy_access_admin_form_submit in ./taxonomy_access_admin.inc

File

./taxonomy_access_admin.inc, line 397
Administrative interface for taxonomy access control.

Code

function taxonomy_access_defaults_update($vid, $rid = null, $grants = null) {
  if (!isset($vid) or !is_numeric($rid)) {
    return FALSE;
  }
  $args = array();
  $ta_sql = "INSERT INTO {term_access_defaults} (vid";
  $ta_sql_values = " VALUES (%d";
  $args[] = $vid;
  if (isset($rid)) {
    $ta_sql .= ",rid";
    $ta_sql_values .= ",%d";
    $args[] = $rid;
  }
  $sql = "";
  if (isset($grants)) {
    foreach ($grants as $perm => $value) {
      $sql .= ',' . db_escape_table("grant_{$perm}");
      $ta_sql_values .= ',%d';
      $args[] = is_array($value) ? $value[0] : $value;
    }
    $sql .= ")";
    $ta_sql_values .= ")";
  }
  else {
    $sql .= ")";
    $ta_sql_values .= ")";
  }
  $ta_sql .= $sql . $ta_sql_values;

  // issue #167977 - klance
  $affected_nodes = _taxonomy_access_get_nodes_for_vocabulary($vid, $rid);
  db_query("DELETE FROM {term_access_defaults} WHERE vid=%d AND rid=%d", $vid, $rid);
  db_query($ta_sql, $args);

  // insert into term_access_defaults
  // issue #167977 - klance
  _taxonomy_access_node_access_update($affected_nodes);
}