完善栏目删除时的操作,自动整理左右值

This commit is contained in:
Li Jianxuan 2014-03-03 04:07:34 +00:00
parent c9b2e843b7
commit b81b97f910
3 changed files with 853 additions and 795 deletions

View File

@ -45,6 +45,7 @@ class CategoryController extends AbstractActionController
$category = new \Sookon\Article\Category;
$this->ViewModel->setVariable('ptype',$category->ptype);
$this->ViewModel->setVariable('categories',$category->GetFullCategory());
$this->ViewModel->setVariable('deepField',$category->DeepTitle);
if(empty($submit) || !$this->getRequest()->isXmlHttpRequest())
return $this->ViewModel;
@ -124,4 +125,27 @@ class CategoryController extends AbstractActionController
}
}
public function delAction()
{
$id = (int)$this->params()->fromRoute('id');
if(empty($id) || $id<=0)
{
return view::Post($this,"参数错误",-1);
}
$category = new \Sookon\Article\Category;
$status = $category->del($id);
if($status === TRUE)
{
return view::Post($this,"删除成功!",-1);
}else{
if(is_string($status))
return view::Post($this,$status,-1);
return view::Post($this,"删除失败!",-1);
}
}
}

View File

@ -39,7 +39,9 @@
<td><?= $v['ptype'] ?></td>
<td><?= date("Y-m-d H:i",strtotime($v['ts_created'])) ?></td>
<td>
<a href="" onclick="return confirm('是否确定删除?')"><span class="glyphicon glyphicon-trash"></span></a>
<a href="<?= $this->url('admin',array('controller'=>'category','action'=>'del','ac'=>'content','id'=>$v['id'])) ?>" onclick="return confirm('是否确定删除?')">
<span class="glyphicon glyphicon-trash"></span>
</a>
<a href="<?= $this->url('admin',array('controller'=>'category','action'=>'edit','ac'=>'content','id'=>$v['id'])) ?>"><span class="glyphicon glyphicon-pencil"></span></a>
<a href="<?= $this->url('admin',array('controller'=>'category','action'=>'edit','ac'=>'moveup','id'=>$v['id'])) ?>">
<span class="glyphicon glyphicon-arrow-up"></span>

View File

@ -665,4 +665,36 @@ class Category
return $row;
}
//删除某个栏目
public function del($id)
{
if(empty($id) || !is_numeric($id))
{
return "参数错误";
}
$cate = $this->fetch($id);
if($cate[$this->fld_right] - $cate[$this->fld_left] > 1)
{
return "此栏目包含子栏目,不能直接删除,需要先删除子栏目";
}
$sql = "DELETE FROM ".$this->CategoryTable." WHERE id=$id";
if($this->db->exec($sql))
{
$sql = "UPDATE ".$this->CategoryTable.
" SET ".$this->fld_right."=".$this->fld_right."-2".
" WHERE ".$this->fld_right.">".$cate[$this->fld_right];
$sql2 = "UPDATE ".$this->CategoryTable.
" SET ".$this->fld_left."=".$this->fld_left."-2".
" WHERE ".$this->fld_left.">".$cate[$this->fld_left];
if($this->db->exec($sql) || $this->db->exec($sql2))
return true;
else
return false;
}
}
}