Subversion Repositories SmartDukaan

Rev

Rev 15085 | Details | Compare with Previous | 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;
15094 anikendra 127
		$q = $this->request->query('q');
128
		if(isset($q) && !empty($q)){
129
			$this->Paginator->settings = array('conditions' => array('UserFilter.filters LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
130
 			$this->set(compact('q'));
131
		} else {
132
			$this->Paginator->settings = array('order' => array('id'=>'desc'));
133
 		}
15085 anikendra 134
		$this->set('userFilters', $this->Paginator->paginate());
135
	}
136
 
15094 anikendra 137
	public function admin_by($userId = null) {
138
		$options = array('conditions' => array('UserFilter.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
139
		$this->Paginator->settings = $options;
140
		$userFilters = $this->Paginator->paginate();		
141
		$this->set(compact('userFilters'));
142
	}
143
 
15085 anikendra 144
/**
145
 * admin_view method
146
 *
147
 * @throws NotFoundException
148
 * @param string $id
149
 * @return void
150
 */
151
	public function admin_view($id = null) {
152
		if (!$this->UserFilter->exists($id)) {
153
			throw new NotFoundException(__('Invalid user filter'));
154
		}
155
		$options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
156
		$this->set('userFilter', $this->UserFilter->find('first', $options));
157
	}
158
 
159
/**
160
 * admin_add method
161
 *
162
 * @return void
163
 */
164
	public function admin_add() {
165
		if ($this->request->is('post')) {
166
			$this->UserFilter->create();
167
			if ($this->UserFilter->save($this->request->data)) {
168
				$this->Session->setFlash(__('The user filter has been saved.'));
169
				return $this->redirect(array('action' => 'index'));
170
			} else {
171
				$this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
172
			}
173
		}
174
		$users = $this->UserFilter->User->find('list');
175
		$this->set(compact('users'));
176
	}
177
 
178
/**
179
 * admin_edit method
180
 *
181
 * @throws NotFoundException
182
 * @param string $id
183
 * @return void
184
 */
185
	public function admin_edit($id = null) {
186
		if (!$this->UserFilter->exists($id)) {
187
			throw new NotFoundException(__('Invalid user filter'));
188
		}
189
		if ($this->request->is(array('post', 'put'))) {
190
			if ($this->UserFilter->save($this->request->data)) {
191
				$this->Session->setFlash(__('The user filter has been saved.'));
192
				return $this->redirect(array('action' => 'index'));
193
			} else {
194
				$this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
195
			}
196
		} else {
197
			$options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
198
			$this->request->data = $this->UserFilter->find('first', $options);
199
		}
200
		$users = $this->UserFilter->User->find('list');
201
		$this->set(compact('users'));
202
	}
203
 
204
/**
205
 * admin_delete method
206
 *
207
 * @throws NotFoundException
208
 * @param string $id
209
 * @return void
210
 */
211
	public function admin_delete($id = null) {
212
		$this->UserFilter->id = $id;
213
		if (!$this->UserFilter->exists()) {
214
			throw new NotFoundException(__('Invalid user filter'));
215
		}
216
		$this->request->onlyAllow('post', 'delete');
217
		if ($this->UserFilter->delete()) {
218
			$this->Session->setFlash(__('The user filter has been deleted.'));
219
		} else {
220
			$this->Session->setFlash(__('The user filter could not be deleted. Please, try again.'));
221
		}
222
		return $this->redirect(array('action' => 'index'));
223
	}}