示例#1
0
 function getMap($depth = -1, $cat_id = 0)
 {
     $var_depth = $depth;
     $var_cat_id = $cat_id;
     if (isset($this->catMap[$var_depth][$var_cat_id])) {
         return $this->catMap[$var_depth][$var_cat_id];
     }
     if ($cat_id > 0) {
         $row = $this->db->select('select cat_path from sdb_b2c_goods_cat where cat_id=' . intval($cat_id));
         if ($depth > 0) {
             $depth += substr_count($row['cat_path'], ',');
         }
         $rows = $this->db->select('select cat_name,cat_id,parent_id,is_leaf,cat_path,type_id from sdb_b2c_goods_cat where cat_path like "' . $row['cat_path'] . $cat_id . '%" order by cat_path,p_order');
     } else {
         $rows = $this->db->select('select cat_name,cat_id,parent_id,is_leaf,cat_path,type_id from sdb_b2c_goods_cat order by p_order');
     }
     $cats = array();
     $ret = array();
     foreach ($rows as $k => $row) {
         if ($depth < 0 || substr_count($row['cat_path'], ',') < $depth) {
             $cats[$row['cat_id']] = array('type' => 'gcat', 'parent_id' => $row['parent_id'], 'title' => $row['cat_name'], 'link' => kernel::mkUrl('gallery', 'index', array($row['cat_id'])));
         }
     }
     foreach ($cats as $cid => $cat) {
         if ($cat['parent_id'] == $cat_id) {
             $ret[] =& $cats[$cid];
         } else {
             $cats[$cat['parent_id']]['items'][] =& $cats[$cid];
         }
     }
     $this->catMap[$var_depth][$var_cat_id] = $ret;
     return $ret;
 }
示例#2
0
文件: cat.php 项目: syjzwjj/quyeba
 /**
  * 得到分类的树形结构图
  * @param string depth
  * @param int cat_id
  * @return mixed 结果数据
  */
 public function getMap($depth = -1, $cat_id = 0)
 {
     $var_depth = $depth;
     $var_cat_id = $cat_id;
     if (isset($this->catMap[$var_depth][$var_cat_id])) {
         return $this->catMap[$var_depth][$var_cat_id];
     }
     if ($cat_id > 0) {
         $row = $this->getList('cat_path', array('cat_id' => intval($cat_id)));
         if ($depth > 0) {
             $depth += substr_count($row['cat_path'], ',');
         }
         $rows = $this->getList('cat_name,cat_id,parent_id,is_leaf,cat_path,type_id', array('cat_path|head' => $row['cat_path'] . $cat_id), 0, -1, 'cat_path,p_order ASC');
     } else {
         $rows = $this->getList('cat_name,cat_id,parent_id,is_leaf,cat_path,type_id', array(), 0, -1, 'p_order ASC');
     }
     $cats = array();
     $ret = array();
     foreach ($rows as $k => $row) {
         if ($depth < 0 || substr_count($row['cat_path'], ',') < $depth) {
             $cats[$row['cat_id']] = array('type' => 'gcat', 'parent_id' => $row['parent_id'], 'title' => $row['cat_name'], 'link' => kernel::mkUrl('gallery', 'index', array($row['cat_id'])));
         }
     }
     foreach ($cats as $cid => $cat) {
         if ($cat['parent_id'] == $cat_id) {
             $ret[] =& $cats[$cid];
         } else {
             $cats[$cat['parent_id']]['items'][] =& $cats[$cid];
         }
     }
     $this->catMap[$var_depth][$var_cat_id] = $ret;
     return $ret;
 }