You are here

private function MenuTree::buildMenuTreeRecursively in Taxonomy Facets 7.3

1 call to MenuTree::buildMenuTreeRecursively()
MenuTree::__construct in classes/MenuTree.php

File

classes/MenuTree.php, line 39

Class

MenuTree

Namespace

taxonomyFacets

Code

private function buildMenuTreeRecursively($parent) {
  $tree = taxonomy_get_tree($this->vid, $parent, 1, FALSE);

  // Count items, we need this so that leaf object can display right class
  $item_number = 1;
  $number_of_items = count($tree);
  $this->menuTree[] = theme('taxonomy_facets_ul_wrapper_begin_template');
  $leafClass = 'leaf';
  foreach ($tree as $leaf) {
    if ($this
      ->displayMenuItem($leaf)) {

      // Check if the current term in this loop has any children.
      $children = taxonomy_get_children($leaf->tid, $this->vid);
      if ($children) {
        $leafClass = 'collapsed';
      }

      // Check if selected filer is somewhere in the children leafs.
      if ($selectedFilterInChildrenLeafs = $this
        ->selectedFilterInChildrenLeafs($leaf->tid)) {
        $leafClass = 'expanded';
      }
      $this->menuTree[] = new MenuLeaf($leaf, $number_of_items, $item_number, $leafClass);
      $item_number++;
      if ($selectedFilterInChildrenLeafs || $this
        ->menuItemIsFilterApplied($leaf->tid)) {
        $this
          ->buildMenuTreeRecursively($leaf->tid);
      }
    }
  }
  $this->menuTree[] = theme('taxonomy_facets_ul_wrapper_end_template');
}