Subversion Repositories SmartDukaan

Rev

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