/**
* 获得指定分类下的子分类的数组
* @access public
* @param int $cat_id 分类的ID
* @param int $selected 当前选中分类的ID
* @param boolean $re_type 返回的类型: 值为真时返回下拉列表,否则返回数组
* @param int $level 限定返回的级数。为0时返回所有级数
* @return mix
*/
public function goods_cat_list($cat_id = 0, $selected = 0, $re_type = true, $level = 0)
{
global $goods_category, $goods_category2;
$sql = "SELECT * FROM __PREFIX__goods_category ORDER BY parent_id , sort_order ASC";
$goods_category = DB::query($sql);
$goods_category = convert_arr_key($goods_category, 'id');
foreach ($goods_category AS $key => $value)
{
if($value['level'] == 1)
$this->get_cat_tree($value['id']);
}
/*
foreach ($goods_category2 AS $key => $value)
{
$strpad_count = $value['level']*10;
echo str_pad('',$strpad_count,"-",STR_PAD_LEFT);
echo $value['name'];
echo "<br/>";
}*/
return $goods_category2;
}
/**
* 获取指定id下的 所有分类
* @global type $goods_category 所有商品分类
* @param type $id 当前显示的 菜单id
* @return 返回数组 Description
*/
public function get_cat_tree($id)
{
global $goods_category, $goods_category2;
$goods_category2[$id] = $goods_category[$id];
foreach ($goods_category AS $key => $value){
if($value['parent_id'] == $id)
{
$this->get_cat_tree($value['id']);
$goods_category2[$id]['have_son'] = 1; // 还有下级
}
}
}
/**
* 移除指定$parent_id_path 分类以及下的所有分类
* @global type $cat_list 所有商品分类
* @param type $parent_id_path 指定的id
* @return 返回数组 Description
*/
public function remove_cat($cat_list,$parent_id_path)
{
foreach ($cat_list AS $key => $value){
if(strstr($value['parent_id_path'],$parent_id_path))
{
unset($cat_list[$value['id']]);
}
}
return $cat_list;
}
常用函数(一) 分类树
最新推荐文章于 2024-01-30 20:03:36 发布