Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13579 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Brands Controller
5
 *
6
 * @property Brand $Brand
7
 * @property PaginatorComponent $Paginator
8
 */
9
class BrandsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
16261 anikendra 18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('filter');
21
	}
22
 
13579 anikendra 23
/**
24
 * index method
25
 *
26
 * @return void
27
 */
28
	public function index() {
29
		$this->Brand->recursive = 0;
30
		$this->set('brands', $this->Paginator->paginate());
31
	}
32
 
33
/**
34
 * view method
35
 *
36
 * @throws NotFoundException
37
 * @param string $id
38
 * @return void
39
 */
40
	public function view($id = null) {
41
		if (!$this->Brand->exists($id)) {
42
			throw new NotFoundException(__('Invalid brand'));
43
		}
44
		$options = array('conditions' => array('Brand.' . $this->Brand->primaryKey => $id));
45
		$this->set('brand', $this->Brand->find('first', $options));
46
	}
47
 
48
/**
49
 * add method
50
 *
51
 * @return void
52
 */
53
	public function add() {
54
		if ($this->request->is('post')) {
55
			$this->Brand->create();
56
			if ($this->Brand->save($this->request->data)) {
57
				$this->Session->setFlash(__('The brand has been saved.'));
58
				return $this->redirect(array('action' => 'index'));
59
			} else {
60
				$this->Session->setFlash(__('The brand could not be saved. Please, try again.'));
61
			}
62
		}
63
	}
64
 
16261 anikendra 65
	public function filter($str,$catId=3) {
18357 amit.gupta 66
		setcookie("brandschosen", urldecode($str), time()+6*3600, '/');
18359 amit.gupta 67
		setcookie("old_cid", $catId, time()+6*3600, '/');
16423 anikendra 68
		$userId = $this->request->query('user_id');
69
		if(isset($userId) && !empty($userId)) {
70
			$this->loadModel('User');
71
			$dbuser = $this->User->findById($userId);
72
			$this->Auth->login($dbuser['User']);
73
		}
16261 anikendra 74
		$this->redirect('/category/'.$catId);
75
	}	
76
 
13579 anikendra 77
/**
78
 * edit method
79
 *
80
 * @throws NotFoundException
81
 * @param string $id
82
 * @return void
83
 */
84
	public function edit($id = null) {
85
		if (!$this->Brand->exists($id)) {
86
			throw new NotFoundException(__('Invalid brand'));
87
		}
88
		if ($this->request->is(array('post', 'put'))) {
89
			if ($this->Brand->save($this->request->data)) {
90
				$this->Session->setFlash(__('The brand has been saved.'));
91
				return $this->redirect(array('action' => 'index'));
92
			} else {
93
				$this->Session->setFlash(__('The brand could not be saved. Please, try again.'));
94
			}
95
		} else {
96
			$options = array('conditions' => array('Brand.' . $this->Brand->primaryKey => $id));
97
			$this->request->data = $this->Brand->find('first', $options);
98
		}
99
	}
100
 
101
/**
102
 * delete method
103
 *
104
 * @throws NotFoundException
105
 * @param string $id
106
 * @return void
107
 */
108
	public function delete($id = null) {
109
		$this->Brand->id = $id;
110
		if (!$this->Brand->exists()) {
111
			throw new NotFoundException(__('Invalid brand'));
112
		}
113
		$this->request->onlyAllow('post', 'delete');
114
		if ($this->Brand->delete()) {
115
			$this->Session->setFlash(__('The brand has been deleted.'));
116
		} else {
117
			$this->Session->setFlash(__('The brand could not be deleted. Please, try again.'));
118
		}
119
		return $this->redirect(array('action' => 'index'));
120
	}
121
 
122
/**
123
 * admin_index method
124
 *
125
 * @return void
126
 */
127
	public function admin_index() {
128
		$this->Brand->recursive = 0;
129
		$this->set('brands', $this->Paginator->paginate());
130
	}
131
 
132
/**
133
 * admin_view method
134
 *
135
 * @throws NotFoundException
136
 * @param string $id
137
 * @return void
138
 */
139
	public function admin_view($id = null) {
140
		if (!$this->Brand->exists($id)) {
141
			throw new NotFoundException(__('Invalid brand'));
142
		}
143
		$options = array('conditions' => array('Brand.' . $this->Brand->primaryKey => $id));
144
		$this->set('brand', $this->Brand->find('first', $options));
145
	}
146
 
147
/**
148
 * admin_add method
149
 *
150
 * @return void
151
 */
152
	public function admin_add() {
153
		if ($this->request->is('post')) {
154
			$this->Brand->create();
155
			if ($this->Brand->save($this->request->data)) {
156
				$this->Session->setFlash(__('The brand has been saved.'));
157
				return $this->redirect(array('action' => 'index'));
158
			} else {
159
				$this->Session->setFlash(__('The brand could not be saved. Please, try again.'));
160
			}
161
		}
162
	}
163
 
164
/**
165
 * admin_edit method
166
 *
167
 * @throws NotFoundException
168
 * @param string $id
169
 * @return void
170
 */
171
	public function admin_edit($id = null) {
13758 anikendra 172
		$this->response->type('json');
173
		$this->layout = 'ajax';
13579 anikendra 174
		if (!$this->Brand->exists($id)) {
175
			throw new NotFoundException(__('Invalid brand'));
176
		}
177
		if ($this->request->is(array('post', 'put'))) {
178
			if ($this->Brand->save($this->request->data)) {
13758 anikendra 179
				$result = array('success'=>true,'message'=>'The brand has been edited');
13579 anikendra 180
			} else {
13758 anikendra 181
				$result = array('success'=>false,'message'=>'The brand could not be edited. Try again later');
13579 anikendra 182
			}
13758 anikendra 183
		} 
184
	 	$this->set(array(
185
		    'result' => $result,
186
		    '_serialize' => array('result')
187
		)); 
188
		$this->render('/Elements/json');  
13579 anikendra 189
	}
190
 
191
/**
192
 * admin_delete method
193
 *
194
 * @throws NotFoundException
195
 * @param string $id
196
 * @return void
197
 */
198
	public function admin_delete($id = null) {
199
		$this->Brand->id = $id;
200
		if (!$this->Brand->exists()) {
201
			throw new NotFoundException(__('Invalid brand'));
202
		}
203
		$this->request->onlyAllow('post', 'delete');
204
		if ($this->Brand->delete()) {
205
			$this->Session->setFlash(__('The brand has been deleted.'));
206
		} else {
207
			$this->Session->setFlash(__('The brand could not be deleted. Please, try again.'));
208
		}
209
		return $this->redirect(array('action' => 'index'));
16261 anikendra 210
	}
211
 
212
	public function admin_genurl() {
213
		$this->Brand->Category->Behaviors->attach('Containable');
214
		$options = array('conditions'=>array('parent_id !='=>0),'contain'=>(array('Brand.name','Brand.displayed_in_preference_page','Brand.id')));
215
		$categories = $this->Brand->Category->find('all',$options);
216
		$this->set(compact('categories'));
217
	}
218
}