Subversion Repositories SmartDukaan

Rev

Rev 13682 | Rev 13695 | 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
 * Preferences Controller
5
 *
6
 * @property Preference $Preference
7
 * @property PaginatorComponent $Paginator
8
 */
9
class PreferencesController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
13688 anikendra 18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('mine');
21
		$callback = $this->request->query('callback');
22
	}
23
 
13682 anikendra 24
	public function brand($action='hide') {
25
		$this->response->type('json');
26
		$this->layout = 'ajax';
27
		$userId = $this->request->query('user_id');
28
		$productId = $this->request->query('product_id');
29
		$hide = $this->request->query('hide');
30
		if(isset($hide) && !empty($hide) && $hide == 1){
31
			$this->loadModel('StoreProduct');
32
			$options = array('conditions'=>array('id'=>$productId),'fields'=>array('category_id','brand'),'recursive'=>-1);
33
			$product = $this->StoreProduct->find('first',$options);
13688 anikendra 34
			$this->loadModel('HiddenBrand');
13682 anikendra 35
			$data = array('user_id' => $userId, 'category_id' => $product['StoreProduct']['category_id'],'brand'=>$product['StoreProduct']['brand']);
13688 anikendra 36
			$this->HiddenBrand->create();
37
			if($this->HiddenBrand->save($data)){
13682 anikendra 38
				$result = array('success'=>true,'message'=>'brand hidden');
39
			}else{
40
				$result = array('success'=>false,'message'=>'database issue');
41
			}
42
		}else{
43
			$result = array('success'=>false,'message'=>'brand not hidden');
44
		}
45
		// $callback = $this->request->query('callback');
46
		$this->set(array(
47
		    'result' => $result,
48
		    // 'callback' => $callback,
49
		    '_serialize' => array('result')
50
		));
51
		$this->render('/Elements/json');
52
	}
53
 
13688 anikendra 54
	public function mine(){
55
		$userId = $this->request->query('user_id');
56
		if(isset($userId) && !empty($userId)){
57
			$this->loadModel('User');
58
			$dbuser = $this->User->findById($userId);
59
			$this->Auth->login($dbuser['User']);
60
		}
61
	}
62
 
13532 anikendra 63
/**
64
 * index method
65
 *
66
 * @return void
67
 */
68
	public function index() {
69
		$this->Preference->recursive = 0;
70
		$this->set('preferences', $this->Paginator->paginate());
71
	}
72
 
73
/**
74
 * view method
75
 *
76
 * @throws NotFoundException
77
 * @param string $id
78
 * @return void
79
 */
80
	public function view($id = null) {
81
		if (!$this->Preference->exists($id)) {
82
			throw new NotFoundException(__('Invalid preference'));
83
		}
84
		$options = array('conditions' => array('Preference.' . $this->Preference->primaryKey => $id));
85
		$this->set('preference', $this->Preference->find('first', $options));
86
	}
87
 
88
/**
89
 * add method
90
 *
91
 * @return void
92
 */
93
	public function add() {
94
		if ($this->request->is('post')) {
95
			$this->Preference->create();
96
			if ($this->Preference->save($this->request->data)) {
97
				$this->Session->setFlash(__('The preference has been saved.'));
98
				return $this->redirect(array('action' => 'index'));
99
			} else {
100
				$this->Session->setFlash(__('The preference could not be saved. Please, try again.'));
101
			}
102
		}
103
		$users = $this->Preference->User->find('list');
104
		$this->set(compact('users'));
105
	}
106
 
107
/**
108
 * edit method
109
 *
110
 * @throws NotFoundException
111
 * @param string $id
112
 * @return void
113
 */
114
	public function edit($id = null) {
115
		if (!$this->Preference->exists($id)) {
116
			throw new NotFoundException(__('Invalid preference'));
117
		}
118
		if ($this->request->is(array('post', 'put'))) {
119
			if ($this->Preference->save($this->request->data)) {
120
				$this->Session->setFlash(__('The preference has been saved.'));
121
				return $this->redirect(array('action' => 'index'));
122
			} else {
123
				$this->Session->setFlash(__('The preference could not be saved. Please, try again.'));
124
			}
125
		} else {
126
			$options = array('conditions' => array('Preference.' . $this->Preference->primaryKey => $id));
127
			$this->request->data = $this->Preference->find('first', $options);
128
		}
129
		$users = $this->Preference->User->find('list');
130
		$this->set(compact('users'));
131
	}
132
 
133
/**
134
 * delete method
135
 *
136
 * @throws NotFoundException
137
 * @param string $id
138
 * @return void
139
 */
140
	public function delete($id = null) {
141
		$this->Preference->id = $id;
142
		if (!$this->Preference->exists()) {
143
			throw new NotFoundException(__('Invalid preference'));
144
		}
145
		$this->request->onlyAllow('post', 'delete');
146
		if ($this->Preference->delete()) {
147
			$this->Session->setFlash(__('The preference has been deleted.'));
148
		} else {
149
			$this->Session->setFlash(__('The preference could not be deleted. Please, try again.'));
150
		}
151
		return $this->redirect(array('action' => 'index'));
152
	}
153
 
154
/**
155
 * admin_index method
156
 *
157
 * @return void
158
 */
159
	public function admin_index() {
160
		$this->Preference->recursive = 0;
161
		$this->set('preferences', $this->Paginator->paginate());
162
	}
163
 
164
/**
165
 * admin_view method
166
 *
167
 * @throws NotFoundException
168
 * @param string $id
169
 * @return void
170
 */
171
	public function admin_view($id = null) {
172
		if (!$this->Preference->exists($id)) {
173
			throw new NotFoundException(__('Invalid preference'));
174
		}
175
		$options = array('conditions' => array('Preference.' . $this->Preference->primaryKey => $id));
176
		$this->set('preference', $this->Preference->find('first', $options));
177
	}
178
 
179
/**
180
 * admin_add method
181
 *
182
 * @return void
183
 */
184
	public function admin_add() {
185
		if ($this->request->is('post')) {
186
			$this->Preference->create();
187
			if ($this->Preference->save($this->request->data)) {
188
				$this->Session->setFlash(__('The preference has been saved.'));
189
				return $this->redirect(array('action' => 'index'));
190
			} else {
191
				$this->Session->setFlash(__('The preference could not be saved. Please, try again.'));
192
			}
193
		}
194
		$users = $this->Preference->User->find('list');
195
		$this->set(compact('users'));
196
	}
197
 
198
/**
199
 * admin_edit method
200
 *
201
 * @throws NotFoundException
202
 * @param string $id
203
 * @return void
204
 */
205
	public function admin_edit($id = null) {
206
		if (!$this->Preference->exists($id)) {
207
			throw new NotFoundException(__('Invalid preference'));
208
		}
209
		if ($this->request->is(array('post', 'put'))) {
210
			if ($this->Preference->save($this->request->data)) {
211
				$this->Session->setFlash(__('The preference has been saved.'));
212
				return $this->redirect(array('action' => 'index'));
213
			} else {
214
				$this->Session->setFlash(__('The preference could not be saved. Please, try again.'));
215
			}
216
		} else {
217
			$options = array('conditions' => array('Preference.' . $this->Preference->primaryKey => $id));
218
			$this->request->data = $this->Preference->find('first', $options);
219
		}
220
		$users = $this->Preference->User->find('list');
221
		$this->set(compact('users'));
222
	}
223
 
224
/**
225
 * admin_delete method
226
 *
227
 * @throws NotFoundException
228
 * @param string $id
229
 * @return void
230
 */
231
	public function admin_delete($id = null) {
232
		$this->Preference->id = $id;
233
		if (!$this->Preference->exists()) {
234
			throw new NotFoundException(__('Invalid preference'));
235
		}
236
		$this->request->onlyAllow('post', 'delete');
237
		if ($this->Preference->delete()) {
238
			$this->Session->setFlash(__('The preference has been deleted.'));
239
		} else {
240
			$this->Session->setFlash(__('The preference could not be deleted. Please, try again.'));
241
		}
242
		return $this->redirect(array('action' => 'index'));
243
	}}