Subversion Repositories SmartDukaan

Rev

Rev 15222 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15194 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Acls Controller
5
 *
6
 * @property Acl $Acl
7
 * @property PaginatorComponent $Paginator
8
 */
9
class AclsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
/**
19
 * index method
20
 *
21
 * @return void
22
 */
23
	public function index() {
24
		$this->Acl->recursive = 0;
25
		$this->set('acls', $this->Paginator->paginate());
26
	}
27
 
28
/**
29
 * view method
30
 *
31
 * @throws NotFoundException
32
 * @param string $id
33
 * @return void
34
 */
35
	public function view($id = null) {
36
		if (!$this->Acl->exists($id)) {
37
			throw new NotFoundException(__('Invalid acl'));
38
		}
39
		$options = array('conditions' => array('Acl.' . $this->Acl->primaryKey => $id));
40
		$this->set('acl', $this->Acl->find('first', $options));
41
	}
42
 
43
/**
44
 * add method
45
 *
46
 * @return void
47
 */
48
	public function add() {
49
		if ($this->request->is('post')) {
50
			$this->Acl->create();
51
			if ($this->Acl->save($this->request->data)) {
52
				$this->Session->setFlash(__('The acl has been saved.'));
53
				return $this->redirect(array('action' => 'index'));
54
			} else {
55
				$this->Session->setFlash(__('The acl could not be saved. Please, try again.'));
56
			}
57
		}
58
		Cache::delete('acls');
59
		$groups = $this->Acl->Group->find('list');
60
		$this->set(compact('groups'));
61
	}
62
 
63
/**
64
 * edit method
65
 *
66
 * @throws NotFoundException
67
 * @param string $id
68
 * @return void
69
 */
70
	public function edit($id = null) {
71
		if (!$this->Acl->exists($id)) {
72
			throw new NotFoundException(__('Invalid acl'));
73
		}
74
		if ($this->request->is(array('post', 'put'))) {
75
			if ($this->Acl->save($this->request->data)) {
76
				$this->Session->setFlash(__('The acl has been saved.'));
77
				return $this->redirect(array('action' => 'index'));
78
			} else {
79
				$this->Session->setFlash(__('The acl could not be saved. Please, try again.'));
80
			}
81
		} else {
82
			$options = array('conditions' => array('Acl.' . $this->Acl->primaryKey => $id));
83
			$this->request->data = $this->Acl->find('first', $options);
84
		}
85
		$groups = $this->Acl->Group->find('list');
86
		$this->set(compact('groups'));
87
	}
88
 
89
/**
90
 * delete method
91
 *
92
 * @throws NotFoundException
93
 * @param string $id
94
 * @return void
95
 */
96
	public function delete($id = null) {
97
		$this->Acl->id = $id;
98
		if (!$this->Acl->exists()) {
99
			throw new NotFoundException(__('Invalid acl'));
100
		}
101
		$this->request->onlyAllow('post', 'delete');
102
		if ($this->Acl->delete()) {
103
			$this->Session->setFlash(__('The acl has been deleted.'));
104
		} else {
105
			$this->Session->setFlash(__('The acl could not be deleted. Please, try again.'));
106
		}
107
		return $this->redirect(array('action' => 'index'));
108
	}
109
 
110
/**
111
 * admin_index method
112
 *
113
 * @return void
114
 */
115
	public function admin_index() {
116
		$this->Acl->recursive = 0;
117
		$this->set('permissions', $this->Paginator->paginate());
118
	}
119
 
120
/**
121
 * admin_view method
122
 *
123
 * @throws NotFoundException
124
 * @param string $id
125
 * @return void
126
 */
127
	public function admin_view($id = null) {
128
		if (!$this->Acl->exists($id)) {
129
			throw new NotFoundException(__('Invalid acl'));
130
		}
131
		$options = array('conditions' => array('Acl.' . $this->Acl->primaryKey => $id));
132
		$this->set('acl', $this->Acl->find('first', $options));
133
	}
134
 
135
/**
136
 * admin_add method
137
 *
138
 * @return void
139
 */
140
	public function admin_add() {
141
		if ($this->request->is('post')) {
142
			$this->Acl->create();
143
			if ($this->Acl->save($this->request->data)) {
144
				$this->Session->setFlash(__('The acl has been saved.'));
145
				Cache::delete('acls','month');
146
				return $this->redirect(array('action' => 'index'));
147
			} else {
148
				$this->Session->setFlash(__('The acl could not be saved. Please, try again.'));
149
			}
150
		}		
151
		$groups = $this->Acl->Group->find('list');
152
		$this->set(compact('groups'));
153
	}
154
 
155
/**
156
 * admin_edit method
157
 *
158
 * @throws NotFoundException
159
 * @param string $id
160
 * @return void
161
 */
162
	public function admin_edit($id = null) {
163
		if (!$this->Acl->exists($id)) {
164
			throw new NotFoundException(__('Invalid acl'));
165
		}
166
		if ($this->request->is(array('post', 'put'))) {
167
			if ($this->Acl->save($this->request->data)) {
168
				$this->Session->setFlash(__('The acl has been saved.'));
169
				Cache::delete('acls','month');
170
				return $this->redirect(array('action' => 'index'));
171
			} else {
172
				$this->Session->setFlash(__('The acl could not be saved. Please, try again.'));
173
			}
174
		} else {
175
			$options = array('conditions' => array('Acl.' . $this->Acl->primaryKey => $id));
176
			$this->request->data = $this->Acl->find('first', $options);
177
		}		
178
		$groups = $this->Acl->Group->find('list');
179
		$this->set(compact('groups'));
180
	}
181
 
182
/**
183
 * admin_delete method
184
 *
185
 * @throws NotFoundException
186
 * @param string $id
187
 * @return void
188
 */
189
	public function admin_delete($id = null) {
190
		$this->Acl->id = $id;
191
		if (!$this->Acl->exists()) {
192
			throw new NotFoundException(__('Invalid acl'));
193
		}
194
		$this->request->onlyAllow('post', 'delete');
195
		if ($this->Acl->delete()) {
196
			$this->Session->setFlash(__('The acl has been deleted.'));
197
		} else {
198
			$this->Session->setFlash(__('The acl could not be deleted. Please, try again.'));
199
		}
200
		return $this->redirect(array('action' => 'index'));
201
	}}