// +---------------------------------------------------------------------- namespace Portal\Controller; use Common\Controller\AdminbaseController; class AdminTermController extends AdminbaseController { protected $terms_model; protected $taxonomys=array("article"=>"文章","picture"=>"图片"); function _initialize() { parent::_initialize(); $this->terms_model = D("Portal/Terms"); $this->assign("taxonomys",$this->taxonomys); } // 后台文章分类列表 public function index(){ $result = $this->terms_model->order(array("listorder"=>"asc"))->select(); $tree = new \Tree(); $tree->icon = array('   │ ', '   ├─ ', '   └─ '); $tree->nbsp = '   '; foreach ($result as $r) { $r['str_manage'] = ' $r['term_id'])) . '">'.L('ADD_SUB_CATEGORY').' | $r['term_id'])) . '">'.L('EDIT').' | $r['term_id'])) . '">'.L('DELETE').' '; $url=U('portal/list/index',array('id'=>$r['term_id'])); $r['url'] = $url; $r['taxonomys'] = $this->taxonomys[$r['taxonomy']]; $r['id']=$r['term_id']; $r['parentid']=$r['parent']; $array[] = $r; } $tree->init($array); $str = " \$id \$spacer \$name \$taxonomys \$str_manage "; $taxonomys = $tree->get_tree(0, $str); $this->assign("taxonomys", $taxonomys); $this->display(); } // 文章分类添加 public function add(){ $parentid = I("get.parent",0,'intval'); $tree = new \Tree(); $tree->icon = array('   │ ', '   ├─ ', '   └─ '); $tree->nbsp = '   '; $terms = $this->terms_model->order(array("path"=>"asc"))->select(); $new_terms=array(); foreach ($terms as $r) { $r['id']=$r['term_id']; $r['parentid']=$r['parent']; $r['selected']= (!empty($parentid) && $r['term_id']==$parentid)? "selected":""; $new_terms[] = $r; } $tree->init($new_terms); $tree_tpl=""; $tree=$tree->get_tree(0,$tree_tpl); $this->assign("terms_tree",$tree); $this->assign("parent",$parentid); $this->display(); } // 文章分类添加提交 public function add_post(){ if (IS_POST) { if ($this->terms_model->create()!==false) { if ($this->terms_model->add()!==false) { F('all_terms',null); $this->success("添加成功!",U("AdminTerm/index")); } else { $this->error("添加失败!"); } } else { $this->error($this->terms_model->getError()); } } } // 文章分类编辑 public function edit(){ $id = I("get.id",0,'intval'); $data=$this->terms_model->where(array("term_id" => $id))->find(); $tree = new \Tree(); $tree->icon = array('   │ ', '   ├─ ', '   └─ '); $tree->nbsp = '   '; $terms = $this->terms_model->where(array("term_id" => array("NEQ",$id), "path"=>array("notlike","%-$id-%")))->order(array("path"=>"asc"))->select(); $new_terms=array(); foreach ($terms as $r) { $r['id']=$r['term_id']; $r['parentid']=$r['parent']; $r['selected']=$data['parent']==$r['term_id']?"selected":""; $new_terms[] = $r; } $tree->init($new_terms); $tree_tpl=""; $tree=$tree->get_tree(0,$tree_tpl); $this->assign("terms_tree",$tree); $this->assign("data",$data); $this->display(); } // 文章分类编辑提交 public function edit_post(){ if (IS_POST) { if ($this->terms_model->create()!==false) { if ($this->terms_model->save()!==false) { F('all_terms',null); $this->success("修改成功!"); } else { $this->error("修改失败!"); } } else { $this->error($this->terms_model->getError()); } } } // 文章分类排序 public function listorders() { $status = parent::_listorders($this->terms_model); if ($status) { $this->success("排序更新成功!"); } else { $this->error("排序更新失败!"); } } // 删除文章分类 public function delete() { $id = I("get.id",0,'intval'); $count = $this->terms_model->where(array("parent" => $id))->count(); if ($count > 0) { $this->error("该菜单下还有子类,无法删除!"); } if ($this->terms_model->delete($id)!==false) { $this->success("删除成功!"); } else { $this->error("删除失败!"); } } }