Subversion Repositories SmartDukaan

Rev

Rev 13583 | Rev 13674 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * UserActions Controller
5
 *
6
 * @property UserAction $UserAction
7
 * @property PaginatorComponent $Paginator
8
 */
9
class UserActionsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
13562 anikendra 18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('update','by','rem');
21
	}
22
 
13672 anikendra 23
	public function mine() {
24
		$this->layout = "innerpages";
25
		$this->UserAction->Behaviors->attach('Containable');
26
		$contain = array('StoreProduct.title','StoreProduct.thumbnail','StoreProduct.mrp','StoreProduct.available_price');
27
		$options = array('contain'=>$contain,'conditions'=>array('UserAction.user_id'=>$this->Auth->User('id'),'UserAction.action'=>'like'));
28
		$myfavorites = $this->UserAction->find('all',$options);
29
		$this->set(compact(myfavorites));
30
	}
31
 
13562 anikendra 32
	public function update($user_id,$store_product_id,$action) {
33
		if(!empty($user_id) && !empty($store_product_id) && !empty($action)) {
34
			$data = array('user_id'=>$user_id,'store_product_id'=>$store_product_id);
35
			$this->UserAction->deleteAll(array($data),false);
36
			$this->response->type('json');
37
			$this->layout = 'ajax';
38
			$callback = $this->request->query('callback');
39
			$data['action'] = $action;
40
			$this->UserAction->create();
41
			if ($this->UserAction->save($data)) {
42
				$result = array('success'=>true,'message'=>(__('The user action has been saved.')));
43
			} else {
44
				$result = array('success'=>false,(__('The user action could not be saved. Please, try again.')));
45
			}
46
			$this->set(array(
47
			    'result' => $result,
48
			    'callback' => $callback,
49
			    '_serialize' => array('result')
50
			));
51
			$this->render('/Elements/jsonp');
52
		}		
53
	}
54
 
55
	public function rem($user_id,$store_product_id,$action) {
56
		if(!empty($user_id) && !empty($store_product_id) && !empty($action)) {
57
			$data = array('user_id'=>$user_id,'store_product_id'=>$store_product_id);
58
			$this->UserAction->deleteAll(array($data),false);
59
			$this->response->type('json');
60
			$this->layout = 'ajax';
61
			$callback = $this->request->query('callback');			
62
			$result = array('success'=>true,'message'=>(__('The user action has been deleted.')));
63
			$this->set(array(
64
			    'result' => $result,
65
			    'callback' => $callback,
66
			    '_serialize' => array('result')
67
			));
68
			$this->render('/Elements/jsonp');
69
		}		
70
	}
71
 
72
	public function by($user_id=null){
73
		if(!empty($user_id)){
74
			$this->response->type('json');
75
			$this->layout = 'ajax';
76
			$callback = $this->request->query('callback');
77
			$this->UserAction->recursive = -1;
78
			$conditions = array('user_id' => $user_id);
13583 anikendra 79
			$result['actions'] = $this->UserAction->find('all',array('conditions'=>$conditions));
13562 anikendra 80
			$this->set(array(
81
			    'result' => $result,
82
			    'callback' => $callback,
83
			    '_serialize' => array('result')
84
			));
13583 anikendra 85
			$this->render('/Elements/json');
13562 anikendra 86
		}
87
	}
13532 anikendra 88
/**
89
 * index method
90
 *
91
 * @return void
92
 */
93
	public function index() {
94
		$this->UserAction->recursive = 0;
95
		$this->set('userActions', $this->Paginator->paginate());
96
	}
97
 
98
/**
99
 * view method
100
 *
101
 * @throws NotFoundException
102
 * @param string $id
103
 * @return void
104
 */
105
	public function view($id = null) {
106
		if (!$this->UserAction->exists($id)) {
107
			throw new NotFoundException(__('Invalid user action'));
108
		}
109
		$options = array('conditions' => array('UserAction.' . $this->UserAction->primaryKey => $id));
110
		$this->set('userAction', $this->UserAction->find('first', $options));
111
	}
112
 
113
/**
114
 * add method
115
 *
116
 * @return void
117
 */
118
	public function add() {
119
		if ($this->request->is('post')) {
120
			$this->UserAction->create();
121
			if ($this->UserAction->save($this->request->data)) {
122
				$this->Session->setFlash(__('The user action has been saved.'));
123
				return $this->redirect(array('action' => 'index'));
124
			} else {
125
				$this->Session->setFlash(__('The user action could not be saved. Please, try again.'));
126
			}
127
		}
13562 anikendra 128
		// $users = $this->UserAction->User->find('list');
129
		// $storeProducts = $this->UserAction->StoreProduct->find('list');
130
		// $this->set(compact('users', 'storeProducts'));
13532 anikendra 131
	}
132
 
133
/**
134
 * edit method
135
 *
136
 * @throws NotFoundException
137
 * @param string $id
138
 * @return void
139
 */
140
	public function edit($id = null) {
141
		if (!$this->UserAction->exists($id)) {
142
			throw new NotFoundException(__('Invalid user action'));
143
		}
144
		if ($this->request->is(array('post', 'put'))) {
145
			if ($this->UserAction->save($this->request->data)) {
146
				$this->Session->setFlash(__('The user action has been saved.'));
147
				return $this->redirect(array('action' => 'index'));
148
			} else {
149
				$this->Session->setFlash(__('The user action could not be saved. Please, try again.'));
150
			}
151
		} else {
152
			$options = array('conditions' => array('UserAction.' . $this->UserAction->primaryKey => $id));
153
			$this->request->data = $this->UserAction->find('first', $options);
154
		}
155
		$users = $this->UserAction->User->find('list');
156
		$storeProducts = $this->UserAction->StoreProduct->find('list');
157
		$this->set(compact('users', 'storeProducts'));
158
	}
159
 
160
/**
161
 * delete method
162
 *
163
 * @throws NotFoundException
164
 * @param string $id
165
 * @return void
166
 */
167
	public function delete($id = null) {
168
		$this->UserAction->id = $id;
169
		if (!$this->UserAction->exists()) {
170
			throw new NotFoundException(__('Invalid user action'));
171
		}
172
		$this->request->onlyAllow('post', 'delete');
173
		if ($this->UserAction->delete()) {
174
			$this->Session->setFlash(__('The user action has been deleted.'));
175
		} else {
176
			$this->Session->setFlash(__('The user action could not be deleted. Please, try again.'));
177
		}
178
		return $this->redirect(array('action' => 'index'));
179
	}
180
 
181
/**
182
 * admin_index method
183
 *
184
 * @return void
185
 */
186
	public function admin_index() {
187
		$this->UserAction->recursive = 0;
188
		$this->set('userActions', $this->Paginator->paginate());
189
	}
190
 
191
/**
192
 * admin_view method
193
 *
194
 * @throws NotFoundException
195
 * @param string $id
196
 * @return void
197
 */
198
	public function admin_view($id = null) {
199
		if (!$this->UserAction->exists($id)) {
200
			throw new NotFoundException(__('Invalid user action'));
201
		}
202
		$options = array('conditions' => array('UserAction.' . $this->UserAction->primaryKey => $id));
203
		$this->set('userAction', $this->UserAction->find('first', $options));
204
	}
205
 
206
/**
207
 * admin_add method
208
 *
209
 * @return void
210
 */
211
	public function admin_add() {
212
		if ($this->request->is('post')) {
213
			$this->UserAction->create();
214
			if ($this->UserAction->save($this->request->data)) {
215
				$this->Session->setFlash(__('The user action has been saved.'));
216
				return $this->redirect(array('action' => 'index'));
217
			} else {
218
				$this->Session->setFlash(__('The user action could not be saved. Please, try again.'));
219
			}
220
		}
221
		$users = $this->UserAction->User->find('list');
222
		$storeProducts = $this->UserAction->StoreProduct->find('list');
223
		$this->set(compact('users', 'storeProducts'));
224
	}
225
 
226
/**
227
 * admin_edit method
228
 *
229
 * @throws NotFoundException
230
 * @param string $id
231
 * @return void
232
 */
233
	public function admin_edit($id = null) {
234
		if (!$this->UserAction->exists($id)) {
235
			throw new NotFoundException(__('Invalid user action'));
236
		}
237
		if ($this->request->is(array('post', 'put'))) {
238
			if ($this->UserAction->save($this->request->data)) {
239
				$this->Session->setFlash(__('The user action has been saved.'));
240
				return $this->redirect(array('action' => 'index'));
241
			} else {
242
				$this->Session->setFlash(__('The user action could not be saved. Please, try again.'));
243
			}
244
		} else {
245
			$options = array('conditions' => array('UserAction.' . $this->UserAction->primaryKey => $id));
246
			$this->request->data = $this->UserAction->find('first', $options);
247
		}
248
		$users = $this->UserAction->User->find('list');
249
		$storeProducts = $this->UserAction->StoreProduct->find('list');
250
		$this->set(compact('users', 'storeProducts'));
251
	}
252
 
253
/**
254
 * admin_delete method
255
 *
256
 * @throws NotFoundException
257
 * @param string $id
258
 * @return void
259
 */
260
	public function admin_delete($id = null) {
261
		$this->UserAction->id = $id;
262
		if (!$this->UserAction->exists()) {
263
			throw new NotFoundException(__('Invalid user action'));
264
		}
265
		$this->request->onlyAllow('post', 'delete');
266
		if ($this->UserAction->delete()) {
267
			$this->Session->setFlash(__('The user action has been deleted.'));
268
		} else {
269
			$this->Session->setFlash(__('The user action could not be deleted. Please, try again.'));
270
		}
271
		return $this->redirect(array('action' => 'index'));
272
	}}