[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/classes/ -> category_tree.php (source)

   1  <?php
   2  /*

   3  $Id: category_tree.php 14 2006-07-28 17:42:07Z user $

   4  

   5   osCMax Power E-Commerce

   6   http://oscdox.com

   7  

   8   Copyright 2006 osCMax2004 osCommerce

   9  

  10   Released under the GNU General Public License

  11  */
  12  
  13   class osC_CategoryTree {
  14     var $root_category_id = 0,
  15         $max_level = 0,
  16         $data = array(),
  17         $root_start_string = '',
  18         $root_end_string = '',
  19         $parent_start_string = '',
  20         $parent_end_string = '',
  21         $parent_group_start_string = '<ul>',
  22         $parent_group_end_string = '</ul>',
  23         $child_start_string = '<li>',
  24         $child_end_string = '</li>',
  25         $spacer_string = '',
  26         $spacer_multiplier = 1;
  27  
  28     function osC_CategoryTree($load_from_database = true) {
  29       global $languages_id;
  30           $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by c.parent_id, c.sort_order, cd.categories_name");
  31           $this->data = array();
  32           while ($categories = tep_db_fetch_array($categories_query)) {
  33             $this->data[$categories['parent_id']][$categories['categories_id']] = array('name' => $categories['categories_name'], 'count' => 0);
  34           }
  35     }
  36  
  37     function buildBranch($parent_id, $level = 0) {
  38       $result = $this->parent_group_start_string;
  39  
  40       if (isset($this->data[$parent_id])) {
  41         foreach ($this->data[$parent_id] as $category_id => $category) {
  42           $category_link = $category_id;
  43           $result .= $this->child_start_string;
  44           if (isset($this->data[$category_id])) {
  45             $result .= $this->parent_start_string;
  46           }
  47  
  48           if ($level == 0) {
  49             $result .= $this->root_start_string;
  50           }
  51           $result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level) . '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $category_link) . '">';
  52           $result .= $category['name'];
  53           $result .= '</a>';
  54  
  55           if ($level == 0) {
  56             $result .= $this->root_end_string;
  57           }
  58  
  59           if (isset($this->data[$category_id])) {
  60             $result .= $this->parent_end_string;
  61           }
  62  
  63           $result .= $this->child_end_string;
  64  
  65           if (isset($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
  66             $result .= $this->buildBranch($category_id, $level+1);
  67           }
  68         }
  69       }
  70  
  71       $result .= $this->parent_group_end_string;
  72  
  73       return $result;
  74     }
  75  
  76     function buildTree() {
  77       return $this->buildBranch($this->root_category_id);
  78     }
  79   }
  80  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7