You are here

function taxonomy_access_set_recursive_grants in Taxonomy Access Control 6

Recursively updates permissions for a role for a term.

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.

1 call to taxonomy_access_set_recursive_grants()
taxonomy_access_admin_form_submit in ./taxonomy_access.admin.inc
Submit handler for the administration form at admin/user/taxonomy_access.

File

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

Code

function taxonomy_access_set_recursive_grants($tid, $rid = NULL, $grants = NULL) {

  // First, process the original.
  taxonomy_access_set_term_grants($tid, $rid, $grants);

  // Process the children.
  $ran_tids = array();

  // tids that have been processed.
  $run_tids = array(
    $tid,
  );

  // tids that are in the queue to be processed.
  while (count($run_tids) > 0) {
    foreach ($run_tids as $run_key => $run_tid) {

      // Some basic loop protection.
      if (!(array_search($run_tid, $ran_tids) === FALSE)) {
        drupal_set_message(t("Loop detected for tid %run_tid. Stopping.", array(
          '%run_tid' => $run_tid,
        )));
        $run_tids = array();

        // stop the execution
      }
      else {
        $result = db_query('SELECT th.tid FROM {term_hierarchy} th WHERE th.parent = %d', $run_tid);

        // If this tid has children, update grants and queue the children
        while ($row = db_fetch_array($result)) {
          taxonomy_access_set_term_grants($row['tid'], $rid, $grants);
          $run_tids[] = $row['tid'];
        }

        // Remove this tid from the queue and mark as processed,
        unset($run_tids[$run_key]);
        $ran_tids[] = $run_tid;
      }
    }
  }
}