You are here

function taxonomy_access_defaults_update in Taxonomy Access Control 5

Same name and namespace in other branches
  1. 5.2 taxonomy_access_admin.inc \taxonomy_access_defaults_update()

Updates default permissions for a role for a vocabulary

Parameters

$vid: The vocab to add the permission for.

$role: The role to add the permission to. Can be the name or the role id or blank for all term permissions.

$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_permissions_form_submit in ./taxonomy_access_admin.inc
Saves the category permissions matrix for choosen user role, after editing.

File

./taxonomy_access.module, line 263
Allows administrators to specify how each category (in the taxonomy) can be used by various roles.

Code

function taxonomy_access_defaults_update($vid, $role = null, $grants = null) {
  if (!isset($vid)) {
    return FALSE;
  }
  if (isset($role) && !is_numeric($role)) {
    $role = db_result(db_query("SELECT rid FROM {role} WHERE name='{$role}'"));
  }
  $ta_sql = "INSERT INTO {term_access_defaults} (vid";
  $ta_sql_values = " VALUES ({$vid}";
  if (isset($role)) {
    $ta_sql .= ",rid";
    $ta_sql_values .= ",{$role}";
  }
  $sql = "";
  if (isset($grants)) {
    foreach ($grants as $perm => $value) {
      $sql .= ",grant_{$perm}";
      $ta_sql_values .= ",{$value}";
    }
    $sql .= ")";
    $ta_sql_values .= ")";
  }
  else {
    $sql .= ")";
    $ta_sql_values .= ")";
  }
  $ta_sql .= $sql . $ta_sql_values;
  db_query("DELETE FROM {term_access_defaults} WHERE vid=%d AND rid=%d", $vid, isset($role) ? $role : 0);
  db_query($ta_sql);

  // insert into term_access_defaults
}