You are here

function taxonomy_workbench_access_tree in Workbench Access 7

Implements hook_workbench_access_tree().

Get the access tree for a taxonomy term.

Parameters

$info: An array defining the access scheme.

$keys: Boolean value to return only array keys, or all data.

Return value

An array of access_ids or a data array.

File

modules/taxonomy.workbench_access.inc, line 156
Taxonomy integration for Workbench Access.

Code

function taxonomy_workbench_access_tree($info, $keys) {
  $tree = array();
  $items = array();
  if (isset($info['access_id'])) {
    if ($info['access_type_id'] != $info['access_id']) {
      $items[$info['access_type_id']] = $info['access_id'];
    }
    else {
      $items[$info['access_type_id']] = 0;
    }
  }
  else {
    foreach (array_filter($info['access_type_id']) as $vid) {
      $items[$vid] = 0;
    }
  }
  foreach ($items as $vid => $tid) {
    if ($vocabulary = taxonomy_vocabulary_machine_name_load($vid)) {
      if ($tid == 0) {
        $tree[$vocabulary->machine_name] = array(
          'access_id' => $vocabulary->machine_name,
          'access_type_id' => $vocabulary->machine_name,
          'name' => $vocabulary->name,
          'description' => $vocabulary->description,
          'weight' => 0,
          'depth' => 0,
          'parent' => $vocabulary->machine_name,
        );
      }
      $children = taxonomy_get_tree($vocabulary->vid, $tid);
      foreach ($children as $child) {
        $tree[$child->tid] = array(
          'access_id' => $child->tid,
          'access_type_id' => $vocabulary->machine_name,
          'name' => $child->name,
          'description' => $child->description,
          'weight' => $child->weight,
          'depth' => $child->depth + 1,
          'parent' => !empty($child->parents[0]) ? $child->parents[0] : $vocabulary->machine_name,
        );
      }
    }
  }
  if ($keys) {
    return array_keys($tree);
  }
  return $tree;
}