You are here

function taxonomy_access_set_term_grants in Taxonomy Access Control 6

Same name and namespace in other branches
  1. 7 taxonomy_access.module \taxonomy_access_set_term_grants()

Updates permissions for a role for a term. Note: This function adds nodes to the affected nodes cache. Callers should run _taxonomy_access_node_access_update() on _taxonomy_access_cache_affected_nodes() after all changes are processed.

Parameters

$tid: The term to add the permission for.

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

$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.

$skip_nodes: A flag indicating whether to skip node updates when processing.

2 calls to taxonomy_access_set_term_grants()
taxonomy_access_admin_form_submit in ./taxonomy_access.admin.inc
Submit handler for the administration form at admin/user/taxonomy_access.
taxonomy_access_set_recursive_grants in ./taxonomy_access.module
Recursively updates permissions for a role for a term.

File

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

Code

function taxonomy_access_set_term_grants($tid, $rid = NULL, $grants = NULL, $skip_nodes = FALSE) {
  if (!isset($tid) or !is_numeric($rid)) {
    return FALSE;
  }

  // Assemble a $row object for Schema API.
  $row = new stdClass();
  $row->tid = $tid;
  if (isset($rid)) {
    $row->rid = $rid;
  }
  if (isset($grants) && is_array($grants)) {
    foreach ($grants as $op => $value) {
      if (is_numeric($value)) {
        $grant_name = "grant_{$op}";
        $row->{$grant_name} = $value;
      }
    }
  }
  if (!$skip_nodes) {
    $affected_nodes = _taxonomy_access_get_nodes_for_term($tid);
  }

  // Delete old entries.
  db_query("DELETE FROM {term_access} WHERE tid=%d AND rid=%d", $tid, $rid);

  // Insert new entries.
  drupal_write_record('term_access', $row);

  // Add any affected nodes to the cache to be updated by the submit handler.
  if (!empty($affected_nodes)) {
    _taxonomy_access_cache_affected_nodes($affected_nodes);
  }
}