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