You are here

function _uc_catalog_navigation in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_catalog/uc_catalog.module \_uc_catalog_navigation()
  2. 5 uc_catalog/uc_catalog.module \_uc_catalog_navigation()
  3. 6.2 uc_catalog/uc_catalog.module \_uc_catalog_navigation()

Emulates Drupal's menu system, but based around the catalog taxonomy.

Parameters

$branch: A treeNode object. Determines if the URL points to itself, or possibly one of its children, if present. If the URL points to itself or one of its products, it displays its name and expands to show its children, otherwise displays a link and a count of the products in it. If the URL points to one of its children, it still displays a link and product count, but must still be expanded. Otherwise, it is collapsed and a link.

Return value

An array whose first element is true if the treeNode is in hierarchy of the URL path. The second element is the HTML of the list item of itself and its children.

1 call to _uc_catalog_navigation()
theme_uc_catalog_block in uc_catalog/uc_catalog.theme.inc
Themes the catalog block.

File

uc_catalog/uc_catalog.module, line 452
Ubercart Catalog module.

Code

function _uc_catalog_navigation($branch) {
  static $terms;
  static $breadcrumb;
  static $types;
  if (empty($types)) {
    $types = uc_product_types();
  }
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', $types)
    ->propertyCondition('status', 1)
    ->fieldCondition('taxonomy_catalog', 'tid', $branch->tid)
    ->count();
  $num = $query
    ->execute();
  $branch_path = uc_catalog_path($branch);
  if (!isset($breadcrumb)) {
    $breadcrumb = drupal_get_breadcrumb();
  }
  $vid = variable_get('uc_catalog_vid', 0);
  if ($_GET['q'] == $branch_path) {

    // The URL points to this term.
    $here = TRUE;
  }
  else {
    $here = FALSE;
  }
  if (!isset($terms)) {
    $node = menu_get_object('node', 1);
    $terms = array();
    if ($node && ($field_data = field_get_items('node', $node, 'taxonomy_catalog'))) {
      foreach ($field_data as $term) {
        $terms[$term['tid']] = $term['tid'];
      }
    }
  }

  // Determine whether to expand menu item.
  if (arg(0) == 'node' && array_key_exists($branch->tid, $terms)) {
    $inpath = FALSE;
    foreach ($breadcrumb as $link) {
      if (strpos(urldecode($link), drupal_get_path_alias($branch_path)) !== FALSE) {
        $inpath = TRUE;
      }
    }
  }
  else {
    $inpath = $here;
  }
  $lis = array();
  $expand = variable_get('uc_catalog_expand_categories', FALSE);
  if ($expand || count($branch->children)) {
    foreach ($branch->children as $twig) {

      // Expand if children are in the menu path. Capture their output.
      list($child_in_path, $lis[], $child_num) = _uc_catalog_navigation($twig);
      $num += $child_num;
      if ($child_in_path) {
        $inpath = $child_in_path;
      }
    }
  }

  // No nodes in category or descendants. Not in path and display nothing.
  if (!$num) {
    return array(
      FALSE,
      '',
      0,
    );
  }

  // Checks to see if node counts are desired in navigation.
  $num_text = '';
  if (variable_get('uc_catalog_block_nodecount', TRUE)) {
    $num_text = ' (' . $num . ')';
  }
  $link = l($branch->name . $num_text, $branch_path);
  $output = theme('uc_catalog_item', array(
    'here' => $here,
    'link' => $link,
    'lis' => $lis,
    'expand' => $expand,
    'inpath' => $inpath,
    'count_children' => count($branch->children),
  ));

  // Tell parent category your status, and pass on output.
  return array(
    $inpath,
    $output,
    $num,
  );
}