taxonomy_get_tree

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

modules/taxonomy/taxonomy.module, строка 989

Версии
5 – 6
taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL)

Создает иерархическое представление словаря.

Параметры

$vid Для какого словаря создавать дерево.

$parent ID термина, под которым создавать дерево. Если 0, то создавать дерево всего словаря.

$depth Только для внутреннего пользования.

$max_depth Количество уровней дерева, которое возвращается. Оставьте NULL, чтобы вернуть все уровни.

Возвращаемое значение

Массив всех объектов терминов в дереве. Каждый объект термина дополнены атрибутами 'depth' и 'parents', которых обычно нет. Результаты статически кешируются.

▾ 10 функции вызывают taxonomy_get_tree()

forum_get_forums in modules/forum/forum.module
Returns a list of all forums for a given taxonomy id
forum_overview in modules/forum/forum.module
Returns an overview list of existing forums and containers
forum_submit in modules/forum/forum.module
Implementation of hook_submit().
taxonomy_form_all in modules/taxonomy/taxonomy.module
Generate a set of options for selecting a term from all vocabularies.
taxonomy_form_term in modules/taxonomy/taxonomy.module
taxonomy_get_tree in modules/taxonomy/taxonomy.module
Создает иерархическое представление словаря.
taxonomy_overview_terms in modules/taxonomy/taxonomy.module
Display a tree of all the terms in a vocabulary, with options to edit each one.
taxonomy_select_nodes in modules/taxonomy/taxonomy.module
Находит все ноды, которые соответствуют выбранным условиям таксономии.
_forum_parent_select in modules/forum/forum.module
Returns a select box for available parent terms
_taxonomy_term_select in modules/taxonomy/taxonomy.module
Create a select form element for a given taxonomy vocabulary.

Код

<?php
function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) {
  static $children, $parents, $terms;

  $depth++;

  // We cache trees, so it's not CPU-intensive to call get_tree() on a term
  // and its children, too.
  if (!isset($children[$vid])) {
    $children[$vid] = array();

    $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN  {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid);
    while ($term = db_fetch_object($result)) {
      $children[$vid][$term->parent][] = $term->tid;
      $parents[$vid][$term->tid][] = $term->parent;
      $terms[$vid][$term->tid] = $term;
    }
  }

  $max_depth = (is_null($max_depth)) ? count($children[$vid]) : $max_depth;
  if ($children[$vid][$parent]) {
    foreach ($children[$vid][$parent] as $child) {
      if ($max_depth > $depth) {
        $term = drupal_clone($terms[$vid][$child]);
        $term->depth = $depth;
        // The "parent" attribute is not useful, as it would show one parent only.
        unset($term->parent);
        $term->parents = $parents[$vid][$child];
        $tree[] = $term;

        if ($children[$vid][$child]) {
          $tree = array_merge($tree, taxonomy_get_tree($vid, $child, $depth, $max_depth));
        }
      }
    }
  }

  return $tree ? $tree : array();
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему