You are here

function tft_folder_tree in Taxonomy File Tree 7.2

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

Construct the folder tree.

Parameters

int $tid = 0:

boolean $inclusive = FALSE: Whether the current term should be included as well

Return value

array

Related topics

4 calls to tft_folder_tree()
tft_block_view in ./tft.module
Implements hook_block_view().
tft_form_alter in ./tft.module
Implements hook_form_alter()
tft_og_block_view_alter in modules/tft_og/tft_og.module
Implements hook_block_view_alter().
tft_og_form_alter in modules/tft_og/tft_og.module
Implements hook_form_alter()

File

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

Code

function tft_folder_tree($tid = 0, $inclusive = FALSE) {
  $folders = array();
  $content = tft_folder_content($tid, TRUE);
  foreach ($content as $term) {
    if (tft_term_access($term['id'])) {
      $folders[$term['id']]['tid'] = $term['id'];
      $folders[$term['id']]['name'] = db_query("SELECT name FROM {taxonomy_term_data} WHERE tid = :tid", array(
        ':tid' => $term['id'],
      ))
        ->fetchField();
      $folders[$term['id']]['weight'] = $term['weight'];
      $folders[$term['id']]['parent'] = $tid ? $tid : 0;
      if ($child_terms = tft_folder_tree($term['id'])) {
        $folders[$term['id']]['children'] = $child_terms;
      }
    }
  }
  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,
        'children' => $folders,
      ),
    );
  }
  return $folders;
}