Subversion Repositories SmartDukaan

Rev

Rev 16261 | 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) {
16423 anikendra 66
		$userId = $this->request->query('user_id');
67
		if(isset($userId) && !empty($userId)) {
68
			$this->loadModel('User');
69
			$dbuser = $this->User->findById($userId);
70
			$this->Auth->login($dbuser['User']);
71
		}
16261 anikendra 72
		setcookie("brandschosen", urldecode($str), time()+6*3600, '/');
73
		$this->redirect('/category/'.$catId);
74
	}	
75
 
13579 anikendra 76
/**
77
 * edit method
78
 *
79
 * @throws NotFoundException
80
 * @param string $id
81
 * @return void
82
 */
83
	public function edit($id = null) {
84
		if (!$this->Brand->exists($id)) {
85
			throw new NotFoundException(__('Invalid brand'));
86
		}
87
		if ($this->request->is(array('post', 'put'))) {
88
			if ($this->Brand->save($this->request->data)) {
89
				$this->Session->setFlash(__('The brand has been saved.'));
90
				return $this->redirect(array('action' => 'index'));
91
			} else {
92
				$this->Session->setFlash(__('The brand could not be saved. Please, try again.'));
93
			}
94
		} else {
95
			$options = array('conditions' => array('Brand.' . $this->Brand->primaryKey => $id));
96
			$this->request->data = $this->Brand->find('first', $options);
97
		}
98
	}
99
 
100
/**
101
 * delete method
102
 *
103
 * @throws NotFoundException
104
 * @param string $id
105
 * @return void
106
 */
107
	public function delete($id = null) {
108
		$this->Brand->id = $id;
109
		if (!$this->Brand->exists()) {
110
			throw new NotFoundException(__('Invalid brand'));
111
		}
112
		$this->request->onlyAllow('post', 'delete');
113
		if ($this->Brand->delete()) {
114
			$this->Session->setFlash(__('The brand has been deleted.'));
115
		} else {
116
			$this->Session->setFlash(__('The brand could not be deleted. Please, try again.'));
117
		}
118
		return $this->redirect(array('action' => 'index'));
119
	}
120
 
121
/**
122
 * admin_index method
123
 *
124
 * @return void
125
 */
126
	public function admin_index() {
127
		$this->Brand->recursive = 0;
128
		$this->set('brands', $this->Paginator->paginate());
129
	}
130
 
131
/**
132
 * admin_view method
133
 *
134
 * @throws NotFoundException
135
 * @param string $id
136
 * @return void
137
 */
138
	public function admin_view($id = null) {
139
		if (!$this->Brand->exists($id)) {
140
			throw new NotFoundException(__('Invalid brand'));
141
		}
142
		$options = array('conditions' => array('Brand.' . $this->Brand->primaryKey => $id));
143
		$this->set('brand', $this->Brand->find('first', $options));
144
	}
145
 
146
/**
147
 * admin_add method
148
 *
149
 * @return void
150
 */
151
	public function admin_add() {
152
		if ($this->request->is('post')) {
153
			$this->Brand->create();
154
			if ($this->Brand->save($this->request->data)) {
155
				$this->Session->setFlash(__('The brand has been saved.'));
156
				return $this->redirect(array('action' => 'index'));
157
			} else {
158
				$this->Session->setFlash(__('The brand could not be saved. Please, try again.'));
159
			}
160
		}
161
	}
162
 
163
/**
164
 * admin_edit method
165
 *
166
 * @throws NotFoundException
167
 * @param string $id
168
 * @return void
169
 */
170
	public function admin_edit($id = null) {
13758 anikendra 171
		$this->response->type('json');
172
		$this->layout = 'ajax';
13579 anikendra 173
		if (!$this->Brand->exists($id)) {
174
			throw new NotFoundException(__('Invalid brand'));
175
		}
176
		if ($this->request->is(array('post', 'put'))) {
177
			if ($this->Brand->save($this->request->data)) {
13758 anikendra 178
				$result = array('success'=>true,'message'=>'The brand has been edited');
13579 anikendra 179
			} else {
13758 anikendra 180
				$result = array('success'=>false,'message'=>'The brand could not be edited. Try again later');
13579 anikendra 181
			}
13758 anikendra 182
		} 
183
	 	$this->set(array(
184
		    'result' => $result,
185
		    '_serialize' => array('result')
186
		)); 
187
		$this->render('/Elements/json');  
13579 anikendra 188
	}
189
 
190
/**
191
 * admin_delete method
192
 *
193
 * @throws NotFoundException
194
 * @param string $id
195
 * @return void
196
 */
197
	public function admin_delete($id = null) {
198
		$this->Brand->id = $id;
199
		if (!$this->Brand->exists()) {
200
			throw new NotFoundException(__('Invalid brand'));
201
		}
202
		$this->request->onlyAllow('post', 'delete');
203
		if ($this->Brand->delete()) {
204
			$this->Session->setFlash(__('The brand has been deleted.'));
205
		} else {
206
			$this->Session->setFlash(__('The brand could not be deleted. Please, try again.'));
207
		}
208
		return $this->redirect(array('action' => 'index'));
16261 anikendra 209
	}
210
 
211
	public function admin_genurl() {
212
		$this->Brand->Category->Behaviors->attach('Containable');
213
		$options = array('conditions'=>array('parent_id !='=>0),'contain'=>(array('Brand.name','Brand.displayed_in_preference_page','Brand.id')));
214
		$categories = $this->Brand->Category->find('all',$options);
215
		$this->set(compact('categories'));
216
	}
217
}