|
Site Map |
|
|
|
/*
$Id: category_tree.php,v1.0 2004/05/10 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2004 osCommerce
Released under the GNU General Public License
*/
class osC_CategoryTree {
var $root_category_id = 0,
$max_level = 0,
$data = array(),
$root_start_string = '',
$root_end_string = '',
$parent_start_string = '',
$parent_end_string = '',
$parent_group_start_string = '',
$parent_group_end_string = ' ',
$child_start_string = '',
$child_end_string = '',
$spacer_string = '',
$spacer_multiplier = 1;
function osC_CategoryTree($load_from_database = true) {
global $languages_id;
$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 c.categoires_master_status='1' and cd.language_id = '" . (int)$languages_id . "' order by c.parent_id, c.sort_order, cd.categories_name");
$this->data = array();
while ($categories = tep_db_fetch_array($categories_query)) {
// Ultimate SEO URLs compatibility - Chemo
# initialize array container
$c = array();
# Get the category path, $c is passed by reference
tep_get_parent_categories($c, $categories['categories_id']);
# For some reason it seems to return in reverse order so reverse the array
$c = array_reverse($c);
# Implode the array to get the full category path
$id = (implode('_', $c) ? implode('_', $c) . '_' . $categories['categories_id'] : $categories['categories_id']);
$this->data[$categories['parent_id']][$id] = array('name' => $categories['categories_name'], 'count' => 0);
}
}
function buildBranch($parent_id, $level = 0) {
$result = $this->parent_group_start_string;
if (isset($this->data[$parent_id])) {
foreach ($this->data[$parent_id] as $category_id => $category) {
if (substr_count($category_id, '_')>0){
$wm_main_category_id =str_replace(strstr($category_id, '_'), "", $category_id);
}else{
$wm_main_category_id=$category_id;
}
$category_link = $category_id;
$result .= $this->child_start_string;
if (isset($this->data[$category_id])) {
$result .= $this->parent_start_string;
}
if ($level == 0) {
$result .= $this->root_start_string;
}
$result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level) . '';
$result .= $category['name'];
$result .= '';
$result .= $this->buildProducts($category_id);
if ($level == 0) {
$result .= $this->root_end_string;
}
if (isset($this->data[$category_id])) {
$result .= $this->parent_end_string;
}
$result .= $this->child_end_string;
if(substr($category_id, -2,1)=="_"){
$category_id_withoutPath=substr($category_id, -1);
}elseif(substr($category_id, -3,1)=="_"){
$category_id_withoutPath=substr($category_id, -2);
}else{
$category_id_withoutPath=substr($category_id, -3);
}
if (isset($this->data[$category_id_withoutPath]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
$result .= $this->buildBranch($category_id_withoutPath , $level+1);
}
}
}
$result .= $this->parent_group_end_string;
return $result;
}
/**
* function qui va ajouter a la liste result les produit de la category defini
* vandoorn Bruno karando@karando.com
*/
function buildProducts($category_id)
{
global $languages_id;
if (strpos($category_id,"_")!==false)
{
$categori_id = explode("_",$category_id);
$categori_id=$categori_id[sizeof($categori_id)-1];
}
else
{
$categori_id=$category_id;
}
/*$req="select * from products prod, products_to_categories prodcate , products_description proddescr
join manufacturers m on manufacturers_id=m.manufacturers_id
where prod.products_status = '1' and prodcate.categories_id=".$categori_id." and prod.products_id=prodcate.products_id
and proddescr.language_id=".$languages_id." and proddescr.products_id=prod.products_id order by proddescr.products_name, proddescr.products_typ, proddescr.products_typ2";*/
$req="select * from products prod
join products_description proddescr on prod.products_id=proddescr.products_id and proddescr.language_id=".$languages_id."
join products_to_categories prodcate on prod.products_id=prodcate.products_id
left join manufacturers m on prod.manufacturers_id=m.manufacturers_id
where prod.products_status = '1' and prodcate.categories_id=".$categori_id."
order by proddescr.products_name, proddescr.products_typ, proddescr.products_typ2";
$products_query = tep_db_query($req);
//echo $req;
$result="";
$result .= $this->parent_group_start_string;
while ($products = tep_db_fetch_array($products_query))
{
if ($products['products_status'] == 1) {
$result .= $this->child_start_string;
$result.=' ' . $products['products_name'] . ' / '. $products['manufacturers_name'] . ' / '. $products['products_typ'] . ' / '. $products['products_typ2'] .' ';
$result .= $this->child_end_string;
}
}
$result .= $this->parent_group_end_string;
return $result;
}
function buildTree() {
global $current_main_category_id;
if ($current_main_category_id>0){
return $this->buildBranch($current_main_category_id);
}else{
return $this->buildBranch($this->root_category_id);
}
}
}
?> | | | | | | | |