Subversion Repositories SmartDukaan

Rev

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