統計
| ブランチ: | リビジョン:

pictcode / app / Controller / ProgramsController.php @ master

履歴 | 表示 | アノテート | ダウンロード (3.032 KB)

1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Programs Controller
5
 *
6
 * @property Program $Program
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ProgramsController extends AppController {
10

    
11
             public $layout = 'procedure';
12

    
13
/**
14
 * Components
15
 *
16
 * @var array
17
 */
18
        public $components = array('Paginator');
19

    
20
/**
21
 * index method
22
 *
23
 * @return void
24
 */
25
        public function index() {
26
                $this->Program->recursive = 0;
27
                $user_id = $this->Session->read('Auth.User.id');
28
                // if (!$this->Program->exists($id)) {
29
                //         throw new NotFoundException(__('Invalid program'));
30
                // }
31
                $options = array('conditions' => array('Program.user_id' => $user_id));
32
                $this->set('programs', $this->Program->find('all', $options));
33
                $this->set('countprograms', $this->Program->find('count', $options));
34

    
35

    
36
                // $this->set('programs', $this->Paginator->paginate());
37
        }
38

    
39
/**
40
 * view method
41
 *
42
 * @throws NotFoundException
43
 * @param string $id
44
 * @return void
45
 */
46
        public function view($id = null) {
47
                if (!$this->Program->exists($id)) {
48
                        throw new NotFoundException(__('Invalid program'));
49
                }
50
                $options = array('conditions' => array('Program.' . $this->Program->primaryKey => $id));
51
                $this->set('program', $this->Program->find('first', $options));
52
        }
53

    
54
/**
55
 * add method
56
 *
57
 * @return void
58
 */        
59
        
60
        
61
        public function add() {
62
                if ($this->request->is('post')) {
63
                        $this->Program->create();
64
                        if ($this->Program->save($this->request->data)) {
65
                                $this->Flash->success(__('The program has been saved.'));
66
                                return $this->redirect(array('action' => 'index'));
67
                        } else {
68
                                $this->Flash->error(__('The program could not be saved. Please, try again.'));
69
                        }
70
                }
71
                $users = $this->Program->User->find('list');
72
                $this->set(compact('users'));
73
        }
74

    
75
/**
76
 * edit method
77
 *
78
 * @throws NotFoundException
79
 * @param string $id
80
 * @return void
81
 */
82
        public function edit($id = null) {
83
                if (!$this->Program->exists($id)) {
84
                        throw new NotFoundException(__('Invalid program'));
85
                }
86
                if ($this->request->is(array('post', 'put'))) {
87
                        if ($this->Program->save($this->request->data)) {
88
                                $this->Flash->success(__('The program has been saved.'));
89
                                return $this->redirect(array('action' => 'index'));
90
                        } else {
91
                                $this->Flash->error(__('The program could not be saved. Please, try again.'));
92
                        }
93
                } else {
94
                        $options = array('conditions' => array('Program.' . $this->Program->primaryKey => $id));
95
                        $this->request->data = $this->Program->find('first', $options);
96
                }
97
                $users = $this->Program->User->find('list');
98
                $this->set(compact('users'));
99
        }
100

    
101
/**
102
 * delete method
103
 *
104
 * @throws NotFoundException
105
 * @param string $id
106
 * @return void
107
 */
108
        public function delete($id = null) {
109
                $this->Program->id = $id;
110
                if (!$this->Program->exists()) {
111
                        throw new NotFoundException(__('Invalid program'));
112
                }
113
                $this->request->allowMethod('post', 'delete');
114
                if ($this->Program->delete()) {
115
                        $this->Flash->success(__('The program has been deleted.'));
116
                } else {
117
                        $this->Flash->error(__('The program could not be deleted. Please, try again.'));
118
                }
119
                return $this->redirect(array('action' => 'index'));
120
        }
121

    
122

    
123
}
124

    
125