You are here

function uc_catalog_block in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_catalog/uc_catalog.module \uc_catalog_block()

Implements hook_block().

Displays a menu for navigating the "Product Catalog".

File

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

Code

function uc_catalog_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = variable_get('uc_catalog_name', t('Catalog'));
      $blocks[0]['cache'] = BLOCK_CACHE_PER_PAGE;
      return $blocks;
    case 'view':
      $block = array();
      if (user_access('view catalog')) {
        switch ($delta) {
          case 0:
            drupal_add_css(drupal_get_path('module', 'uc_catalog') . '/uc_catalog.css');

            // Get the vocabulary tree information.
            $vid = variable_get('uc_catalog_vid', 0);
            $tree = taxonomy_get_tree($vid);

            // Then convert it into an actual tree structure.
            $seq = 0;
            $menu_tree = new UcTreeNode();
            $level = array();
            $curr_depth = -1;
            foreach ($tree as $knot) {
              $seq++;
              $knot->sequence = $seq;
              $knothole = new UcTreeNode($knot);

              // Begin at the root of the tree and find the proper place.
              $menu_tree
                ->add_child($knothole);
            }

            // Now, create a structured menu, separate from Drupal's menu.
            $content = theme('uc_catalog_block', $menu_tree);
            $subject = variable_get('uc_catalog_name', t('Catalog'));
            $block = array(
              'subject' => $subject,
              'content' => $content,
            );
            break;
        }
      }
      return $block;
  }
}