root
2017-08-03 02d49834cb0d8936dc49352b3968c3baf6da3232
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
95
96
97
98
99
100
101
102
103
104
105
<?php 
 
class ManagerController extends System_Controller_Admin{
 
    public function init(){
        parent::init();
        $this->module_service = new Service_Module();
        //echo $this->layout;
    }
 
    public function IndexAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $total = $this->module_service->getModuleTotal();
            $data['draw'] = !empty($_REQUEST['draw'])?$_REQUEST['draw']:1;
            $data['recordsTotal'] = $total;
            $data['recordsFiltered'] = $total;
            $data['data'] = $this->module_service->getModuleList();
            //print_r($this->module_service->getModuleList());
            exit($this->sendToDataTable($data));
        }
    }
 
    /**
     * 添加栏目
     */
    public function AddAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $data['module'] = $this->getRequest()->getPost('module');
            $data['controller'] = $this->getRequest()->getPost('controller');
            $data['action'] = $this->getRequest()->getPost('action');
            $data['parent'] = $this->getRequest()->getPost('parent');
            $data['name'] = $this->getRequest()->getPost('name');
            if($data['parent'] != 0){
                $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent']));
                if($parent_module){
                    $data['is_module'] = false;
                    if($parent['level'] <= 2 ){
                        $data['level'] = $parent['level'] + 1;
                    }
                    else{
                        exit($this->showError('目前栏目只支持三级', 400, true));    
                    }
                }
                else{
                    exit($this->showError('所属栏目不存在,请重新选择', 400, true));
                }
            }
            else{
                $data['level'] = 1;
                $data['is_module'] = true;
            }
            if($this->module_service->add($data)){
                Util::updateModules();
                exit($this->showSuccess('栏目添加成功', true));
            }
            else{
                exit($this->showError($this->module_service->error, 400, true));
            }
        }
    }
 
    public function EditAction($id){
        $module = $this->module_service->getModuleInfo(array('_id' => $id));
        if($module){
            if($this->getRequest()->isXmlHttpRequest()){
                $data['module'] = $this->getRequest()->getPost('module');
                $data['controller'] = $this->getRequest()->getPost('controller');
                $data['action'] = $this->getRequest()->getPost('action');
                $data['parent'] = $this->getRequest()->getPost('parent');
                $data['name'] = $this->getRequest()->getPost('name');
                if($data['parent']){
                    $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent']));
                    if($parent_module){
                        if($parent['level'] <= 2 ){
                            $data['level'] = $parent['level'] + 1;
                        }
                        else{
                            exit($this->showError('目前栏目只支持三级', 400, true));    
                        }
                    }
                    else{
                        exit($this->showError('所属栏目不存在,请重新选择', 400, true));
                    }
                }
                else{
                    $data['level'] = 1;
                    $data['is_module'] = true;
                }    
                if($this->module_service->update($data, array('_id' => $module['_id']))){
                    Util::updateModules();
                    exit($this->showSuccess('栏目添加成功', true));
                }
                else{
                    exit($this->showError($this->module_service->error, 400, true));
                }
            }
            $this->getView()->assign('module', $module);
        }
        else{
            $this->redirect('/error/show/type/no_data');
        }
    }
 
 
}