You are here

function _taxonomy_facets_get_menu_tree in Taxonomy Facets 7.2

Helper function for taxonomy_facets_get_menu_tree.

Returns menu tree, it is called recursively. There is no limit on the number of menu items or the depth of the tree. It works on one level of hierarhy at the time and and 1 level at each call

Parameters

integer $vid: Vocabulary id

array $tree: Taxonomy tree, but only one level, either first level if called for the first time, or first level children of the current level.

array $terms: Selected filters.

integer $tid_selected: Selected term in the menu

bolen $first_level: (optional) Defaults to True.

Return value

string Themed menu item.

1 call to _taxonomy_facets_get_menu_tree()
taxonomy_facets_get_menu_tree in ./taxonomy_facets.module
Print out menu tree for each vocab selected to be taxo faceted filter.

File

./taxonomy_facets.module, line 499
Taxo Faceted Navigation module code.

Code

function _taxonomy_facets_get_menu_tree($vid, $tree, $terms, $tid_selected) {

  //dsm($tree);
  $menu = '';

  // Count items, we need this so we know when we hit the last item.
  $number_of_items = count($tree);
  $item_number = 1;

  // Loop through current level of terms and format as links.
  foreach ($tree as $term) {

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

    // Work out if we will display this item or not.
    $display_item = taxonomy_facets_display_meny_item_check($vid, $term, $children, $terms, $tid_selected);
    if ($display_item) {
      $menu_record = array();
      $menu_record['tid'] = $term->tid;
      $menu_record['term name'] = check_plain($term->name);
      $menu_record['url alias'] = taxonomy_facets_build_url_alias($vid, $terms, $term->tid);
      $curent_term_in_children = FALSE;

      // If it has a filter applied then check that one of the children or
      // any sub children is filter current selected term
      // also set menu class as expandable as there are children and menu can
      // be expanded.
      if (!empty($children)) {

        // Get all children and subchildren.
        $all_children = taxonomy_get_tree($vid, $term->tid);
        foreach ($all_children as $child) {
          if ($tid_selected == $child->tid) {
            $curent_term_in_children = TRUE;
          }
        }
      }

      // Sort out menu item class for menu item in this loop.
      $menu_record['menu item class'] = '';

      // If first element in current level.
      if ($item_number == 1) {
        $menu_record['menu item class'] = 'first ';
      }
      else {
        if ($item_number == $number_of_items) {
          $menu_record['menu item class'] = 'last ';
        }
      }
      $menu_record['active'] = '';

      // This is selected menu item.
      if ($term->tid == $tid_selected) {
        $menu_record['active'] = 'class="active"';
        if (empty($children)) {
          $menu_record['menu item class'] .= 'leaf';
        }
        else {
          $menu_record['menu item class'] .= 'expanded';
        }
      }
      else {
        if (empty($children)) {
          $menu_record['menu item class'] .= 'leaf';
        }
        else {
          $menu_record['menu item class'] .= 'collapsed';
        }
      }

      // Add menu items from this level to menu string.
      $menu .= theme('taxonomy_facets_menu_template', array(
        'taxo_menu_item' => $menu_record,
      ));

      // Print sub menu if current term is one of the children of tid in loop,
      // or if tid in loop is actually the selected one.
      if ($curent_term_in_children || $tid_selected == $term->tid) {
        $menu .= _taxonomy_facets_get_menu_tree($vid, $children, $terms, $tid_selected);
      }
      $item_number++;
    }
  }
  return theme('taxonomy_facets_ul_wrapper_template', array(
    'ul_sub_menu' => $menu,
  ));
}