colly_wyx
2018-04-28 c315a791545733391c15e42bc747e34293d36a99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php 
 
class ManagerController extends System_Controller_Admin{
 
    public function init(){
        parent::init();
        $this->article_service = new Service_Article();
        //echo $this->layout;
    }
 
    public function ListAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $total = $this->article_service->getArticleTotal();
            $data['draw'] = !empty($_REQUEST['draw'])?$_REQUEST['draw']:1;
            $data['start'] = !empty($_REQUEST['start'])?$_REQUEST['start']:0;
            $data['length'] = !empty($_REQUEST['length'])?$_REQUEST['length']:10;
            $data['recordsTotal'] = $total;
            $data['recordsFiltered'] = $total;
            $data['data'] = $this->article_service->getArticleList(array(), array(), array(), $data['length'], $data['start']);
            //print_r($this->module_service->getModuleList());
            exit($this->sendToDataTable($data));
        }
    }
 
    /**
     * 添加栏目
     */
    public function AddAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $data['name'] = $this->getRequest()->getPost('name');
            $data['category'] = $this->getRequest()->getPost('category');
            $data['is_publish'] = $this->getRequest()->getPost('is_publish');
            $data['content'] = $this->getRequest()->getPost('content');
            $data['create_time'] = date('Y-m-d H:i:s');
            
            if($this->article_service->add($data)){
                Util::updateModules();
                exit($this->showSuccess('文章添加成功', true));
            }
            else{
                exit($this->showError($this->article_service->error, 400, true));
            }
        }
    }
 
    /**
     * 修改文章
     * @param [type] $id [description]
     */
    public function EditAction($id){
        $article = $this->article_service->getArticleInfo(array('_id' => $id));
        if($article){
            if($this->getRequest()->isXmlHttpRequest()){
                $data['name'] = $this->getRequest()->getPost('name');
                $data['category'] = $this->getRequest()->getPost('category');
                $data['is_publish'] = $this->getRequest()->getPost('is_publish');
                $data['content'] = $this->getRequest()->getPost('content');
                
                if($this->article_service->update($data, array('_id' => $article['_id']))){
                    exit($this->showSuccess('文章修改成功', true));
                }
                else{
                    exit($this->showError($this->module_service->error, 400, true));
                }
            }
            $this->getView()->assign('article', $article);
        }
        else{
            $this->redirect('/error/show/type/no_data');
        }
    }
 
    /**
     * 删除
     */
    public function DelAction(){
        $id = $this->post('id');
        $article = $this->article_service->getArticleInfo(array('_id' => $id));
        if($article){
            if($this->article_service->delete(array('_id' => $id))){
                exit($this->showSuccess('文章删除成功', true));
            }
            else{
                exit($this->showError($this->module_service->error, 400, true));
            }
        }
        else{
            exit($this->showError('删除失败,文章不存在', 400, true));
        }
    }
 
 
 
}