category_tree Class Reference

List of all members.

Public Member Functions

Public Attributes

Private Member Functions


Detailed Description

Definition at line 21 of file category_tree.php.


Constructor & Destructor Documentation

category_tree::__construct (  ) 

Definition at line 53 of file category_tree.php.

00053                            {
00054       global $languages_id, $osCSS_Cache , $language;
00055 
00056       if (_cst_bool('SHOW_COUNTS'))  $this->show_category_product_count = true;
00057 
00058         if ($osCSS_Cache->read('category_tree-' . $language.'-type', 720)) {
00059           $this->data = $osCSS_Cache->getCache();
00060         } else {
00061           $this->data = array();
00062           categorie::add_where_query(" and c.categories_hidden='1' ");
00063           $list = categorie::get_query('','','',array('limit'=>0));
00064           foreach($list as $categories)
00065             $this->data[$categories->parent_id][$categories->categories_id] = array('name' => $categories->categories_name, 'count' => 0);
00066 
00067 
00068           if ($this->show_category_product_count === true)  $this->calculateCategoryProductCount();
00069 
00070             $osCSS_Cache->writeBuffer($this->data);
00071         }
00072 
00073     }


Member Function Documentation

category_tree::buildBranch ( parent_id,
level = 0 
) [private]

Constructeur de branche.

Parameters:
int $parent_id
int $level

Definition at line 95 of file category_tree.php.

Referenced by buildTree().

00095                                                        {
00096 
00097     $result = $this->parent_group_start_string;
00098 
00099     if (isset($this->data[$parent_id])) {
00100       $nbr = 0;
00101       foreach ($this->data[$parent_id] as $category_id => $category) {
00102 
00103         $category_link = $this->buildBreadcrumb($category_id);
00104 
00105         if ($level == 0 ||(isset($this->data[$category_id]) ) )  $result .= sprintf($this->root_start_string,' class="cat'.$parent_id.'_'.$category_id.'" ')  ;
00106         else $result .= $this->child_start_string ;
00107 
00108         $result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level) . '<a title="'. $category['name'] .'" href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $category_link ) . '">';
00109 
00110         if ($this->follow_cpath === true) {
00111           if (in_array($category_id, $this->cpath_array)) $result .= $this->cpath_start_string . $category['name'] . $this->cpath_end_string;
00112           else  $result .= (!_cst_bool('NOT_RECUP_CASSE_IN_TXT_CATEGORIES'))?strtolower($category['name']) : $category['name'];
00113         } else
00114           $result .= (!_cst_bool('NOT_RECUP_CASSE_IN_TXT_CATEGORIES'))? strtolower($category['name']) : $category['name'];
00115 
00116         if ($this->show_category_product_count === true)
00117           $result .= $this->category_product_count_start_string . $category['count'] . $this->category_product_count_end_string;
00118 
00119         $result .= '</a>';
00120 
00121 
00122 
00123         if (isset($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
00124           if ($this->follow_cpath === true) {
00125             if (in_array($category_id, $this->cpath_array))
00126               $result .= $this->buildBranch($category_id, $level+1);
00127           } else
00128             $result .= $this->buildBranch($category_id, $level+1);
00129         }
00130 
00131         if ( ($this->max_level<$level) && ( (in_array($category_id,$this->cpath_array) && tep_has_category_subcategories($category_id) != false) || ($this->follow_cpath === false &&  tep_has_category_subcategories($category_id) != false ) ) )
00132           $result .= "\n" ;
00133         else
00134           $result .= $this->child_end_string ;
00135 
00136       $nbr++;
00137       }
00138     }
00139 /*     if ($nbr != 0)*/ $result .= $this->parent_group_end_string;
00140 
00141     return $result;
00142   }

category_tree::buildBranchArray ( parent_id,
level = 0,
result = '' 
) [private]

Constructeur des branche en tableaux.

Parameters:
int $parent_id
int $level
string $result

Definition at line 152 of file category_tree.php.

Referenced by getTree().

00152                                                                           {
00153     if (empty($result)) {
00154       $result = array();
00155     }
00156 
00157     if (isset($this->data[$parent_id])) {
00158       foreach ($this->data[$parent_id] as $category_id => $category) {
00159         if ($this->breadcrumb_usage == true)  $category_link = $this->buildBreadcrumb($category_id);
00160         else  $category_link = $category_id;
00161 
00162         $result[] = array('id' => $category_link, 'title' => str_repeat($this->spacer_string, $this->spacer_multiplier * $level) . $category['name']);
00163 
00164         if (isset($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
00165           if ($this->follow_cpath === true) {
00166             if (in_array($category_id, $this->cpath_array))  $result = $this->buildBranchArray($category_id, $level+1, $result);
00167           } else {
00168             $result = $this->buildBranchArray($category_id, $level+1, $result);
00169           }
00170         }
00171       }
00172     }
00173 
00174     return $result;
00175   }

category_tree::buildBreadcrumb ( category_id,
level = 0 
) [private]
Parameters:
$category_id int
$level int

Definition at line 183 of file category_tree.php.

Referenced by buildBranch(), and buildBranchArray().

00183                                                              {
00184     $breadcrumb = '';
00185 
00186     foreach ($this->data as $parent => $categories) {
00187       foreach ($categories as $id => $info) {
00188         if ($id == $category_id) {
00189           if ($level < 1)  $breadcrumb = $id;
00190           else $breadcrumb = $id . $this->breadcrumb_separator . $breadcrumb;
00191 
00192           if ($parent != $this->root_category_id)  $breadcrumb = $this->buildBreadcrumb($parent, $level+1) . $breadcrumb;
00193 
00194         }
00195       }
00196     }
00197 
00198     return $breadcrumb;
00199   }

category_tree::buildTree ( parent_id = ''  ) 
Parameters:
$parent_id 

Definition at line 206 of file category_tree.php.

00206                                              {
00207     return $this->buildBranch((empty($parent_id) ? $this->root_category_id : $parent_id));
00208   }

category_tree::calculateCategoryProductCount (  ) 

Definition at line 222 of file category_tree.php.

Referenced by __construct().

00222                                            {
00223     foreach ($this->data as $parent => $categories) {
00224       foreach ($categories as $id => $info) {
00225         $this->data[$parent][$id]['count'] =  categorie::get_count_products_in_category($id);
00226         $cp=0;
00227         $parent_category = $parent;
00228         while ($parent_category != $this->root_category_id) {
00229           foreach ($this->data as $parent_parent => $parent_categories) {
00230             foreach ($parent_categories as $parent_category_id => $parent_category_info) {
00231               if ($parent_category_id == $parent_category) {
00232                 $this->data[$parent_parent][$parent_category_id]['count'] += $this->data[$parent][$id]['count'];
00233 
00234                 $parent_category = $parent_parent;
00235                 break 2;
00236               }
00237               if($cp>100)break;
00238               $cp++;
00239             }
00240           }
00241         }
00242       }
00243     }
00244   }

category_tree::getTree ( parent_id = ''  ) 

Recup menu en array.

Parameters:
$parent_id 

Definition at line 218 of file category_tree.php.

00218                                            {
00219     return $this->buildBranchArray((empty($parent_id) ? $this->root_category_id : $parent_id));
00220   }

category_tree::setBreadcrumbSeparator ( breadcrumb_separator  ) 
Parameters:
$breadcrumb_separator string

Definition at line 315 of file category_tree.php.

00315                                                                 {
00316     $this->breadcrumb_separator = $breadcrumb_separator;
00317   }

category_tree::setBreadcrumbUsage ( breadcrumb_usage  ) 
Parameters:
$breadcrumb_usage 

Definition at line 323 of file category_tree.php.

00323                                                         {
00324       if ($breadcrumb_usage === true)  $this->breadcrumb_usage = true;
00325       else  $this->breadcrumb_usage = false;
00326     }

category_tree::setCategoryPath ( cpath,
cpath_start_string = '',
cpath_end_string = '' 
)

Definition at line 337 of file category_tree.php.

00337                                                                                             {
00338     $this->follow_cpath = true;
00339     $this->cpath_array = explode($this->breadcrumb_separator, $cpath);
00340     $this->cpath_start_string = $cpath_start_string;
00341     $this->cpath_end_string = $cpath_end_string;
00342   }

category_tree::setCategoryPathString ( cpath_start_string,
cpath_end_string 
)

Definition at line 353 of file category_tree.php.

00353                                                                                 {
00354       $this->cpath_start_string = $cpath_start_string;
00355       $this->cpath_end_string = $cpath_end_string;
00356     }

category_tree::setCategoryProductCountString ( category_product_count_start_string,
category_product_count_end_string 
)

encapusalation du nombre d'element enfants

Definition at line 367 of file category_tree.php.

00367                                                                                                                            {
00368     $this->category_product_count_start_string = $category_product_count_start_string;
00369     $this->category_product_count_end_string = $category_product_count_end_string;
00370   }

category_tree::setChildString ( child_start_string,
child_end_string 
)

Encapsulation item parent.

Parameters:
$child_start_string string
$child_end_string string

Definition at line 306 of file category_tree.php.

00306                                                                          {
00307     $this->child_start_string = $child_start_string;
00308     $this->child_end_string = $child_end_string;
00309   }

category_tree::setData ( &$  data_array  )  [private]

Definition at line 79 of file category_tree.php.

00079                                          {
00080     if (is_array($data_array)) {
00081       $this->data = array();
00082 
00083       for ($i=0, $n=sizeof($data_array); $i<$n; $i++) {
00084         $this->data[$data_array[$i]['parent_id']][$data_array[$i]['categories_id']] = array('name' => $data_array[$i]['categories_name'], 'count' => $data_array[$i]['categories_count']);
00085       }
00086     }
00087   }

category_tree::setFollowCategoryPath ( follow_cpath  ) 

Definition at line 346 of file category_tree.php.

00346                                                        {
00347     if ($follow_cpath === true)  $this->follow_cpath = true;
00348     else  $this->follow_cpath = false;
00349   }

category_tree::setMaximumLevel ( max_level  ) 

nbr niveau

Parameters:
int $max_level

Definition at line 260 of file category_tree.php.

00260                                               {
00261     $this->max_level = $max_level;
00262   }

category_tree::setParentGroupString ( parent_group_start_string,
parent_group_end_string 
)

Encapsulation Parent.

Parameters:
$parent_group_start_string string
$parent_group_end_string string

Definition at line 293 of file category_tree.php.

00293                                                                                              {
00294     $this->parent_group_start_string = $parent_group_start_string;
00295     $this->parent_group_end_string = $parent_group_end_string;
00296   }

category_tree::setParentString ( parent_start_string,
parent_end_string 
)

Encapsulation item Root.

Parameters:
$parent_start_string string
$parent_end_string string

Definition at line 283 of file category_tree.php.

00283                                                                             {
00284     $this->parent_start_string = $parent_start_string;
00285     $this->parent_end_string = $parent_end_string;
00286   }

category_tree::setRootCategoryID ( root_category_id  )  [private]
Parameters:
$root_category_id int

Definition at line 251 of file category_tree.php.

00251                                                         {
00252     $this->root_category_id = $root_category_id;
00253   }

category_tree::setRootString ( root_start_string,
root_end_string 
)

Encapsulation Root.

Parameters:
string $root_start_string
string $root_end_string

Definition at line 273 of file category_tree.php.

00273                                                                       {
00274     $this->root_start_string = $root_start_string;
00275     $this->root_end_string = $root_end_string;
00276   }

category_tree::setShowCategoryProductCount ( show_category_product_count  ) 

Definition at line 360 of file category_tree.php.

00360                                                                             {
00361     $this->show_category_product_count = ($show_category_product_count === true)? true : false ;
00362   }

category_tree::setSpacerString ( spacer_string,
spacer_multiplier = 2 
)

Definition at line 330 of file category_tree.php.

00330                                                                           {
00331     $this->spacer_string = $spacer_string;
00332     $this->spacer_multiplier = $spacer_multiplier;
00333   }


Member Data Documentation

category_tree::$breadcrumb_separator = '_'

Definition at line 38 of file category_tree.php.

Referenced by setBreadcrumbSeparator().

category_tree::$breadcrumb_usage = true

Definition at line 39 of file category_tree.php.

Referenced by setBreadcrumbUsage().

category_tree::$category_product_count_end_string = ')'

Definition at line 48 of file category_tree.php.

Referenced by setCategoryProductCountString().

category_tree::$category_product_count_start_string = ' ('

Definition at line 47 of file category_tree.php.

Referenced by setCategoryProductCountString().

category_tree::$child_end_string = ''

Definition at line 36 of file category_tree.php.

Referenced by setChildString().

category_tree::$child_start_string = ''

Definition at line 35 of file category_tree.php.

Referenced by setChildString().

category_tree::$cpath_array = array()

Definition at line 43 of file category_tree.php.

category_tree::$cpath_end_string = ''

Definition at line 45 of file category_tree.php.

Referenced by setCategoryPath(), and setCategoryPathString().

category_tree::$cpath_start_string = ''

Definition at line 44 of file category_tree.php.

Referenced by setCategoryPath(), and setCategoryPathString().

category_tree::$data = array()

Definition at line 24 of file category_tree.php.

category_tree::$follow_cpath = false

Definition at line 42 of file category_tree.php.

Referenced by setFollowCategoryPath().

category_tree::$max_level = 0

Definition at line 23 of file category_tree.php.

Referenced by setMaximumLevel().

category_tree::$parent_end_string = ''

Definition at line 33 of file category_tree.php.

Referenced by setParentString().

category_tree::$parent_group_end_string = ''

Definition at line 30 of file category_tree.php.

Referenced by setParentGroupString().

category_tree::$parent_group_start_string = ''

Definition at line 29 of file category_tree.php.

Referenced by setParentGroupString().

category_tree::$parent_start_string = ''

Definition at line 32 of file category_tree.php.

Referenced by setParentString().

category_tree::$root_category_id = 0

Definition at line 22 of file category_tree.php.

Referenced by setRootCategoryID().

category_tree::$root_end_string = ''

Definition at line 27 of file category_tree.php.

Referenced by setRootString().

category_tree::$root_start_string = ''

Definition at line 26 of file category_tree.php.

Referenced by setRootString().

category_tree::$show_category_product_count = false

Definition at line 46 of file category_tree.php.

Referenced by setShowCategoryProductCount().

category_tree::$spacer_multiplier = 1

Definition at line 41 of file category_tree.php.

Referenced by setSpacerString().

category_tree::$spacer_string = ''

Definition at line 40 of file category_tree.php.

Referenced by setSpacerString().


The documentation for this class was generated from the following file: