Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
15085 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * UserFilters Controller
5
 *
6
 * @property UserFilter $UserFilter
7
 * @property PaginatorComponent $Paginator
8
 */
9
class UserFiltersController 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->UserFilter->recursive = 0;
25
		$this->set('userFilters', $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->UserFilter->exists($id)) {
37
			throw new NotFoundException(__('Invalid user filter'));
38
		}
39
		$options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
40
		$this->set('userFilter', $this->UserFilter->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->log(print_r($this->request->data,1),'user_filters');
51
			$this->UserFilter->create();
52
			if ($this->UserFilter->save($this->request->data)) {
53
				$result = array('success'=>true,'message'=>__('The user filter has been saved.'));
54
				// $this->Session->setFlash(__('The user filter has been saved.'));
55
				// return $this->redirect(array('action' => 'index'));
56
			} else {
57
				$result = array('success'=>false,'message'=>__('The user filter could not be saved. Please, try again.'));
58
				// $this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
59
			}
60
		}
61
		// $users = $this->UserFilter->User->find('list');
62
		// $this->set(compact('users'));
63
		$this->response->type('json');
64
		$this->layout = 'ajax';
65
		$this->set(array(
66
		    'result' => $result,
67
		    // 'callback' => $callback,
68
		    '_serialize' => array('result')
69
		));
70
		$this->render('/Elements/json');
71
	}
72
 
73
/**
74
 * edit method
75
 *
76
 * @throws NotFoundException
77
 * @param string $id
78
 * @return void
79
 */
80
	public function edit($id = null) {
81
		if (!$this->UserFilter->exists($id)) {
82
			throw new NotFoundException(__('Invalid user filter'));
83
		}
84
		if ($this->request->is(array('post', 'put'))) {
85
			if ($this->UserFilter->save($this->request->data)) {
86
				$this->Session->setFlash(__('The user filter has been saved.'));
87
				return $this->redirect(array('action' => 'index'));
88
			} else {
89
				$this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
90
			}
91
		} else {
92
			$options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
93
			$this->request->data = $this->UserFilter->find('first', $options);
94
		}
95
		$users = $this->UserFilter->User->find('list');
96
		$this->set(compact('users'));
97
	}
98
 
99
/**
100
 * delete method
101
 *
102
 * @throws NotFoundException
103
 * @param string $id
104
 * @return void
105
 */
106
	public function delete($id = null) {
107
		$this->UserFilter->id = $id;
108
		if (!$this->UserFilter->exists()) {
109
			throw new NotFoundException(__('Invalid user filter'));
110
		}
111
		$this->request->onlyAllow('post', 'delete');
112
		if ($this->UserFilter->delete()) {
113
			$this->Session->setFlash(__('The user filter has been deleted.'));
114
		} else {
115
			$this->Session->setFlash(__('The user filter could not be deleted. Please, try again.'));
116
		}
117
		return $this->redirect(array('action' => 'index'));
118
	}
119
 
120
/**
121
 * admin_index method
122
 *
123
 * @return void
124
 */
125
	public function admin_index() {
126
		$this->UserFilter->recursive = 0;
127
		$this->set('userFilters', $this->Paginator->paginate());
128
	}
129
 
130
/**
131
 * admin_view method
132
 *
133
 * @throws NotFoundException
134
 * @param string $id
135
 * @return void
136
 */
137
	public function admin_view($id = null) {
138
		if (!$this->UserFilter->exists($id)) {
139
			throw new NotFoundException(__('Invalid user filter'));
140
		}
141
		$options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
142
		$this->set('userFilter', $this->UserFilter->find('first', $options));
143
	}
144
 
145
/**
146
 * admin_add method
147
 *
148
 * @return void
149
 */
150
	public function admin_add() {
151
		if ($this->request->is('post')) {
152
			$this->UserFilter->create();
153
			if ($this->UserFilter->save($this->request->data)) {
154
				$this->Session->setFlash(__('The user filter has been saved.'));
155
				return $this->redirect(array('action' => 'index'));
156
			} else {
157
				$this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
158
			}
159
		}
160
		$users = $this->UserFilter->User->find('list');
161
		$this->set(compact('users'));
162
	}
163
 
164
/**
165
 * admin_edit method
166
 *
167
 * @throws NotFoundException
168
 * @param string $id
169
 * @return void
170
 */
171
	public function admin_edit($id = null) {
172
		if (!$this->UserFilter->exists($id)) {
173
			throw new NotFoundException(__('Invalid user filter'));
174
		}
175
		if ($this->request->is(array('post', 'put'))) {
176
			if ($this->UserFilter->save($this->request->data)) {
177
				$this->Session->setFlash(__('The user filter has been saved.'));
178
				return $this->redirect(array('action' => 'index'));
179
			} else {
180
				$this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
181
			}
182
		} else {
183
			$options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
184
			$this->request->data = $this->UserFilter->find('first', $options);
185
		}
186
		$users = $this->UserFilter->User->find('list');
187
		$this->set(compact('users'));
188
	}
189
 
190
/**
191
 * admin_delete method
192
 *
193
 * @throws NotFoundException
194
 * @param string $id
195
 * @return void
196
 */
197
	public function admin_delete($id = null) {
198
		$this->UserFilter->id = $id;
199
		if (!$this->UserFilter->exists()) {
200
			throw new NotFoundException(__('Invalid user filter'));
201
		}
202
		$this->request->onlyAllow('post', 'delete');
203
		if ($this->UserFilter->delete()) {
204
			$this->Session->setFlash(__('The user filter has been deleted.'));
205
		} else {
206
			$this->Session->setFlash(__('The user filter could not be deleted. Please, try again.'));
207
		}
208
		return $this->redirect(array('action' => 'index'));
209
	}}