You are here

function tft_tree in Taxonomy File Tree 7.2

Same name and namespace in other branches
  1. 7 tft.module \tft_tree()

Construct the folder tree recursively.

Parameters

int $tid:

bool $inclusive = FALSE: Whether to include the passed term.

Return value

array

Related topics

1 call to tft_tree()
tft_manage_folders_form in includes/tft.pages.inc
Form: reorganize folder items.
1 string reference to 'tft_tree'
tft_install in ./tft.install
Implements hook_install().

File

./tft.module, line 943
Hook implementations and module logic for TFT.

Code

function tft_tree($tid = 0, $inclusive = FALSE) {
  $folders = array();
  $content = tft_folder_content($tid);
  foreach ($content as $item) {
    $folders[$item['id']]['weight'] = isset($item['weight']) ? $item['weight'] : 0;
    $folders[$item['id']]['parent'] = $tid ? $tid : 0;
    $folders[$item['id']]['type'] = $item['type'];
    if ($item['type'] == 'term' && tft_term_access($item['id'])) {
      $folders[$item['id']]['tid'] = $item['id'];
      $folders[$item['id']]['name'] = db_query("SELECT name FROM {taxonomy_term_data} WHERE tid = :tid", array(
        ':tid' => $item['id'],
      ))
        ->fetchField();
      if ($child_terms = tft_tree($item['id'])) {
        $folders[$item['id']]['children'] = $child_terms;
      }
    }
    elseif ($item['type'] == 'node' && node_access('view', node_load($item['id']))) {
      $folders[$item['id']]['nid'] = $item['id'];
      $folders[$item['id']]['name'] = db_query("SELECT v.title FROM {node} n LEFT JOIN {node_revision} v ON v.vid = n.vid WHERE n.nid = :nid", array(
        ':nid' => $item['id'],
      ))
        ->fetchField();
    }
  }
  if ($inclusive) {
    if ($tid == 0) {
      $name = t("Root");
    }
    else {
      $name = db_query("SELECT name FROM {taxonomy_term_data} WHERE tid = :tid", array(
        ':tid' => $tid,
      ))
        ->fetchField();
    }
    $folders = array(
      $tid => array(
        'name' => $name,
        'tid' => $tid,
        'weight' => 0,
        'parent' => 0,
        'type' => 'term',
        'children' => $folders,
      ),
    );
  }
  return $folders;
}