Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Commit

Permalink
修复分类path错乱,以及其引起的级别限制无效和删除不全的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
chekun committed Jan 4, 2014
1 parent 6e7b523 commit f0fdc20
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions admin/controllers/category_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,24 @@ public function _save_post()
if ($data['parentid'] > 0)
{
//如果不是顶级分类,就读其path数据
$data['path'] = '0';
$data['path'] = '{0}';
$data['level'] = 1;
$parent_class = $this->db->where('classid', $data['parentid'])->get($this->db->dbprefix('u_c_') . $model)->row();
if ($parent_class AND $parent_class->path)

if ($parent_class)
{
$data['path'] .= ',' ;
$data['path'] = $parent_class->path;
$data['level'] = $parent_class->level + 1;
}
$data['path'] .= $data['parentid'] . ',0';
}
else
{
$this->_message('不存在的顶级分类!', '', FALSE);
}
$data['path'] .= ',{'.$data['parentid'].'}';
} else {
$data['path'] = '{0}';
$data['level'] = 1;
}
$attachment = $this->input->post('uploadedfile', TRUE);

if ($id)
Expand Down Expand Up @@ -371,14 +379,16 @@ public function _del_post()
$ids = array($ids);
}
//搜索子分类
$this->db->select('classid')->from($this->db->dbprefix('u_c_') . $model);
$where_string = 'classid < 0 ';
foreach ($ids as $v)
{
$where_string .= " OR path Like '%," . $v . ",%'";
$_category = $this->db->select('path')->where('classid', $v)->get($this->db->dbprefix('u_c_') . $model)->row();
$where_string .= " OR path Like '" . $_category->path . ',{' . $v . "}%'";
}
$this->db->select('classid')->from($this->db->dbprefix('u_c_') . $model);
$this->db->where($where_string);
$result = $this->db->get()->result();

foreach ($result as $v)
{
array_push($ids, $v->classid);
Expand Down

0 comments on commit f0fdc20

Please sign in to comment.