Subversion Repositories SmartDukaan

Rev

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