<?php
/**
 * 文章管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */

namespace Admin\Controller;
class ArticleController extends BaseController{
	public function _initialize(){
		parent::_initialize();
        $this->ArticleCat=getcache('ArticleCat');
    }
    public function index(){
        $name = CONTROLLER_NAME;
        $map=array();
        $catid=I('catid');
        $keyword=I('keyword');
        if($catid)$map['catid']=array('in',$this->ArticleCat[$catid]['id']['allson']);
        if($keyword)$map['title']=array('like',"%".$keyword."%");
        $list = $this->lists($name,$map);
        $this->assign('list', $list);
	    $this->getNodeTree($catid);
        $this->display();
    }
    public function _before_add(){        
       $this->getNodeTree();
    }
    public function _before_edit(){
        $cat=M(CONTROLLER_NAME)->field('catid')->find(I('id'));
        $this->getNodeTree($cat['catid']);
    }
    /* 得到节点树 */
	private function getNodeTree($pid = '') {
	   $select_categorys='';
       $ArticleCat = $this->ArticleCat;			
       if(empty($pid))$pid = I('cate_id');
	   $Tree = new \Common\Vendor\Tree();
       $treemini=$Tree->treemini($ArticleCat);
       $select_categorys.= $Tree->treeminioption($treemini,$pid);
	   $this->assign('select_categorys',$select_categorys);
	}
}