Subversion Repositories SmartDukaan

Rev

Rev 18063 | Rev 18184 | 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
 * Categories Controller
5
 *
6
 * @property Category $Category
7
 * @property PaginatorComponent $Paginator
8
 */
9
class CategoriesController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
13794 anikendra 17
	public $apihost;
18
	public $limit;
13532 anikendra 19
 
13596 anikendra 20
	public function beforeFilter() {
21
		parent::beforeFilter();
22
		$this->Auth->allow('deals');
13794 anikendra 23
		$this->apihost = Configure::read('pythonapihost');
24
		$this->limit = Configure::read('dealsperpage');
13596 anikendra 25
	}
26
 
13532 anikendra 27
/**
28
 * index method
29
 *
30
 * @return void
31
 */
32
	public function index() {
33
		// $this->Category->recursive = 0;
34
		// $this->set('categories', $this->Paginator->paginate());
13541 anikendra 35
		$userId = $this->request->query('user_id');
36
		$this->loadModel('UserCategory');
13689 anikendra 37
		$options = array('conditions' => array('user_id'=>$userId),'order'=>array('rank','asc'),'recursive'=>-1);
13541 anikendra 38
		$userCategories = $this->UserCategory->find('all',$options);		
13532 anikendra 39
		$this->response->type('json');
40
		$this->layout = 'ajax';
13541 anikendra 41
		$conditions = array(array('Category.parent_id !='=>0));
42
		if(!empty($userCategories)){
43
			foreach ($userCategories as $key => $value) {
44
				$categoryIds[] = $value['UserCategory']['category_id'];
45
			}
46
			array_push($conditions,array('Category.id'=>$categoryIds));
47
		}
48
		$this->Category->recursive = -1;		
13532 anikendra 49
		$categories = $this->Paginator->paginate(null,$conditions);
50
		$callback = $this->request->query('callback');
51
		$result = array('categories' => $categories);
52
		$this->set(array(
53
		    'result' => $result,
54
		    'callback' => $callback,
55
		    '_serialize' => array('result')
56
		));
57
		$this->render('/Elements/jsonp');
58
	}
59
 
13567 anikendra 60
	public function deals(){
13591 anikendra 61
		$userId = $this->request->query('user_id');
17962 manish.sha 62
		$error = $this->request->query('error');
13591 anikendra 63
		if(isset($userId) && !empty($userId)){
13597 anikendra 64
			$this->loadModel('User');
65
			$dbuser = $this->User->findById($userId);
66
			$this->Auth->login($dbuser['User']);	
13591 anikendra 67
		}
13583 anikendra 68
		$likedDeals = $disLikedDeals = array();
13794 anikendra 69
		// $this->loadModel('Api');
70
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
71
		// $categorydeals = $apideals['products'];
72
		$page = $this->request->query('page');
73
		if(!isset($page)){
74
			$page = 1;
75
		}
76
		$offset = ($page - 1) * $this->limit;
77
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
17683 naman 78
		//debug($url);
13794 anikendra 79
		$deals = $this->make_request($url,null);		
13583 anikendra 80
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
81
		if(!empty($myactions)) {
82
			foreach ($myactions['actions'] as $key => $value) {
83
				if($value['UserAction']['action'] == 'like'){
84
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
85
				}else{
86
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
87
				}
88
			}
89
		}
17962 manish.sha 90
 
91
		$errorstr = '';
92
 
93
		if(isset($error)){
94
			$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
95
		}
13567 anikendra 96
		$rows = sizeof($categorydeals);
97
		if($rows>=1){
98
			$this->set('deals',$categorydeals);
13583 anikendra 99
			$this->set('likedDeals',$likedDeals);
100
			$this->set('disLikedDeals',$disLikedDeals);
17962 manish.sha 101
			$this->set('errorstr',$errorstr);
13567 anikendra 102
			$this->render('categorydeals');
103
		}else{
104
			foreach ($categorydeals as $key => $dealarr) {
105
				foreach ($dealarr as $key => $deal) {
106
					$deals[] = $deal[0];
107
				}				
108
			}
17962 manish.sha 109
			$this->set(compact('deals','likedDeals','disLikedDeals','errorstr'));
13567 anikendra 110
		}		
111
	}
112
/*
113
	*
13532 anikendra 114
 * view method
115
 *
116
 * @throws NotFoundException
117
 * @param string $id
118
 * @return void
119
 */
120
	public function view($id = null) {
18115 amit.gupta 121
		$searchableSubCategories = array('20', '8^20^15');
14930 anikendra 122
		$userId = $this->request->query('user_id');
17683 naman 123
 
15378 anikendra 124
		if(isset($userId) && !empty($userId)) {
14930 anikendra 125
			$this->loadModel('User');
126
			$dbuser = $this->User->findById($userId);
127
			$this->Auth->login($dbuser['User']);
16549 anikendra 128
		}				
13583 anikendra 129
		$page = $this->request->query('page');
18063 naman 130
		$searchfor = $this->request->query('searchFor');
131
		// echo "page=>",$page;
17810 manish.sha 132
		$error = $this->request->query('error');
13583 anikendra 133
		if(!isset($page)){
134
			$page = 1;
16549 anikendra 135
		}
136
 
13808 anikendra 137
		$sort = $this->request->query('sort');
138
		$direction = $this->request->query('direction');
15044 anikendra 139
		// $filter = $this->request->query('filter');
140
		// $brands = $this->request->query('brands');
16549 anikendra 141
		if($id != 2) {
142
			//Fetch deals
143
			$likedDeals = $disLikedDeals = array();
17174 naman 144
			$brandschosen = $_COOKIE['brandschosen'];
17683 naman 145
			$subcategorieschosen = $_COOKIE['subcategorieschosen'];			
17759 naman 146
 
147
			// echo "Cookie val", $_COOKIE['old_id'];
148
			// echo "id val", $id;
17683 naman 149
 
18063 naman 150
			if(!empty($searchfor) || $searchfor != null)
151
			{
152
				unset($brandschosen);
153
				setcookie('brandschosen', null, -1, '/');
154
				unset($subcategorieschosen);
155
				setcookie('subcategorieschosen', null, -1, '/');
156
			}
17759 naman 157
 
18004 naman 158
			if((isset($_COOKIE['old_cid'])) && ($_COOKIE['old_cid'] != $id)) {
17683 naman 159
 
160
 
17174 naman 161
				unset($brandschosen);
17683 naman 162
				// setcookie('brandschosen', 1, time()-1, '/');
163
				// unset($_COOKIE['brandschosen']);
164
    			setcookie('brandschosen', null, -1, '/');
165
				unset($subcategorieschosen);
166
				setcookie('subcategorieschosen', 1, time()-1, '/');
167
 
168
			}		
169
 
18004 naman 170
			if((isset($_COOKIE['brandschosen'])) && ($_COOKIE['old_cid'] != $id)) {
17683 naman 171
 
172
				unset($brandschosen);
173
				// setcookie('brandschosen', 1, time()-10, '/');
174
				// unset($_COOKIE['brandschosen']);
175
    			setcookie('brandschosen', null, -1, '/');
176
				unset($subcategorieschosen);
177
				setcookie('subcategorieschosen', 1, time()-1, '/');
178
 
16549 anikendra 179
			}
17683 naman 180
 
18004 naman 181
			setcookie('old_cid', $id, -1, '/');
17683 naman 182
 
183
 
184
				if(!empty($brandschosen) && !empty($subcategorieschosen)){
185
					$filter = 'brand|subcategory';
186
				}			
187
				else if(!empty($brandschosen) && empty($subcategorieschosen)){
188
					$filter = 'brand';
189
				}
190
				if(!empty($subcategorieschosen) && empty($brandschosen)){
191
					$filter = 'subcategory';
192
				}
193
 
194
				/*if(!empty($brandschosen)){
195
					$filter = 'brand';
196
				}*/
197
 
16549 anikendra 198
			$brands = str_replace(',', '^', $brandschosen);
17683 naman 199
			$subcategories = str_replace(',', '^', $subcategorieschosen);
200
			$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16549 anikendra 201
			// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
202
			$response = $this->make_request($url,null);
203
			$deals = array();
17683 naman 204
 
205
			$response_count =1;
206
			if($response == '')
207
			{
208
				$response_count = 0;
209
			}
210
			// debug($response_count);
16549 anikendra 211
			if(!empty($response)){
212
				foreach ($response as $key => $value) {
213
					if(!empty($value)){
214
						$deals[] = $value;
215
					}
16098 anikendra 216
				}
217
			}
17683 naman 218
			#print_r($deals);
16549 anikendra 219
			$this->loadModel('Api');
220
			$myactions = $this->Api->getMyActions($this->Auth->User('id'));
221
			if(!empty($myactions)) {
222
				foreach ($myactions['actions'] as $key => $value) {
223
					if($value['UserAction']['action'] == 'like'){
224
						$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
225
					}else{
226
						$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
227
					}
13583 anikendra 228
				}
229
			}
16549 anikendra 230
			$this->loadModel('NotificationRule');
231
			$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));	
232
		    $filterstr = '';
233
			if(isset($filter) && !empty($filter)){
17759 naman 234
 
17683 naman 235
			    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
17695 naman 236
		  	} 
237
 
17759 naman 238
 
17695 naman 239
		  	$get_url = "'".$_SERVER['REQUEST_URI']."'";
240
		  	$urlArray = explode('=',$_SERVER['REQUEST_URI']);
241
		  	$last = $urlArray[sizeof($urlArray)-1];
242
 
17759 naman 243
		  	// <Code for url used after scrolling...>
17695 naman 244
		  	if(!isset($filter) && empty($filter)){
245
		  		if (strpos($get_url,'filter=brand&brands') !== false)
246
		  		{
247
		  			$filterstr= "&filter=brand&brands=".$last;
248
		  		}
249
		  		if (strpos($get_url,'filter=subcategory&subcategories') !== false)
250
		  		{
251
		  			$filterstr= "&filter=subcategory&subcategories=".$last;
252
		  		}
253
 
17759 naman 254
		  	}
255
 
256
 
257
			if(!empty($subcategorieschosen) && isset($subcategorieschosen) && empty($brandschosen) && !isset($brandschosen)){	
258
					$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;				
259
			}
17810 manish.sha 260
 
261
			$errorstr = '';
262
 
263
			if(isset($error)){
264
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
265
			}
17759 naman 266
 
18063 naman 267
 
268
			$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;			
18115 amit.gupta 269
			$this->set(compact('response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen','subcategories','subcategorieschosen','errorstr','nexturl','searchfor', 'searchableSubCategories'));
16549 anikendra 270
		}else{
16583 anikendra 271
			//Check for apk support of sharing
272
			$sharable = 0;
273
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
274
				$sharable = 1;
17183 anikendra 275
			}			
16704 anikendra 276
			$url = $this->apihost."appOffers/1";
277
			$appOffers = $this->make_request($url,null);
278
			$this->set(compact('page','id','sharable','appOffers'));
16549 anikendra 279
			$this->render('viewapps');
13583 anikendra 280
		}
13532 anikendra 281
	}
282
 
16549 anikendra 283
	public function getapps($id=null){
284
		$this->layout = 'ajax';
285
		$page = $this->request->query('page');
286
		if(!isset($page)){
287
			$page = 1;
288
		}
289
		$this->loadModel('AppOffer');
290
		$this->AppOffer->recursive = -1;
291
		$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);
292
		$this->Paginator->settings = $options;
293
		try{
294
			$appOffers = $this->Paginator->paginate('AppOffer');
295
		} catch (NotFoundException $e) {
296
	        //get current page
297
	        $page = $this->request->params['named']['page'];
298
	     	$appOffers = array();   
299
		}
300
		debug($appOffers);		
301
		if(!empty($appOffers)){
302
			$this->set(compact('page','id','appOffers'));
303
			$this->render('/Elements/appoffers');
304
		}else{
305
			$this->render('/Elements/nooffers');
306
		}		
307
	}
308
 
13579 anikendra 309
	public function getdeals($id = null) {
17695 naman 310
 
13808 anikendra 311
		$this->log('getdeal id '.$id,'api');
13583 anikendra 312
		$likedDeals = $disLikedDeals = array();
13579 anikendra 313
		$this->layout = 'ajax';
314
		$page = $this->request->query('page');
315
		if(!isset($page)){
316
			$page = 1;
317
		}
13808 anikendra 318
		$sort = $this->request->query('sort');
319
		$direction = $this->request->query('direction');
15044 anikendra 320
		// $filter = $this->request->query('filter');
321
		// $brands = $this->request->query('brands');
17759 naman 322
		$brandschosen = $_COOKIE['brandschosen'];	 
323
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 	
324
 
325
		// Replace with the below content
326
		// if(!empty($brandschosen)){
327
		// 	$filter = 'brand';
328
		// }
329
 
330
		//I have replaced the above content
331
		if(!empty($brandschosen) && !empty($subcategorieschosen)){
332
			$filter = 'brand|subcategory';
333
		}			
334
		else if(!empty($brandschosen) && empty($subcategorieschosen)){
15044 anikendra 335
			$filter = 'brand';
336
		}
17759 naman 337
		if(!empty($subcategorieschosen) && empty($brandschosen)){
338
			$filter = 'subcategory';
339
		}
340
		//Replaced end
341
 
15044 anikendra 342
		$brands = str_replace(',', '^', $brandschosen);
17759 naman 343
		$subcategories = str_replace(',', '^', $subcategorieschosen);
344
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16098 anikendra 345
		$response = $this->make_request($url,null);
346
		$deals = array();
347
		if(!empty($response)){
348
			foreach ($response as $key => $value) {
349
				if(!empty($value)){
350
					$deals[] = $value;
351
				}
352
			}
353
		}
13794 anikendra 354
		// if (!$this->Category->exists($id)) {
355
			// throw new NotFoundException(__('Invalid category'));
356
		// }
13579 anikendra 357
		$this->loadModel('Api');
13794 anikendra 358
		// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
359
		// $deals = $apideals['products'];
13583 anikendra 360
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
361
		if(!empty($myactions)) {
362
			foreach ($myactions['actions'] as $key => $value) {
363
				if($value['UserAction']['action'] == 'like'){
364
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
365
				}else{
366
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
367
				}
368
			}
369
		}
15026 anikendra 370
		$filterstr = '';
17695 naman 371
 
372
		$get_url = "'".$_SERVER['REQUEST_URI']."'";
373
		$urlArray = explode('=',$_SERVER['REQUEST_URI']);
374
		$last = $urlArray[sizeof($urlArray)-1];
375
 
376
		if(!isset($filter) && empty($filter)){
377
			if (strpos($get_url,'filter=brand&brands') !== false)
378
			{
379
				$filterstr= "&filter=brand&brands=".$last;
380
			}
381
			if (strpos($get_url,'filter=subcategory&subcategories') !== false)
382
			{
383
				$filterstr= "&filter=subcategory&subcategories=".$last;
384
			}
385
 
386
		} 	  	
387
 
15026 anikendra 388
		if(isset($filter) && !empty($filter)){
17759 naman 389
		    // $filterstr = '&filter='.$filter.'&brands='.$brands;
390
		    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
15026 anikendra 391
	  	} 
17759 naman 392
 
393
	  	if(!empty($subcategorieschosen) && isset($subcategorieschosen)&& empty($brandschosen) && !isset($brandschosen)){
394
 
395
	  			$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;
396
	  	}
397
 
18063 naman 398
	  	$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
17759 naman 399
 
18063 naman 400
		$this->set(compact('nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
16098 anikendra 401
		if(!empty($deals) && !empty($deals[0])){
15026 anikendra 402
			$this->render('/Elements/deals');
403
		}else{
404
			$this->render('/Elements/nodeals');
405
		}
17695 naman 406
 
407
 
408
 
13579 anikendra 409
	}
18063 naman 410
 
411
 
412
	public function getdealsforsearchterm($searchterm,$page = null){
413
		$likedDeals = $disLikedDeals = array();
414
		$this->layout = 'ajax';
415
		$page = $this->request->query('page');
416
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 
417
		if(!isset($page)){
418
			$page = 1;
419
			$offset = 0;
420
			$limit=10;
421
		}
422
		else{
423
			$offset = ($page*20) - 30;
424
			$limit = 20;
425
		}
426
		$sort = $this->request->query('sort');
427
		$direction = $this->request->query('direction');
428
 
18115 amit.gupta 429
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategorieschosen;
18063 naman 430
		$response = $this->make_request($url,null);
431
		$deals = array();
432
		if(!empty($response)){
433
			foreach ($response as $key => $value) {
434
				if(!empty($value)){
435
					$deals[] = $value;
436
				}
437
			}
438
		}
18115 amit.gupta 439
 
18063 naman 440
		$this->loadModel('Api');
18115 amit.gupta 441
 
18063 naman 442
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
443
		if(!empty($myactions)) {
444
			foreach ($myactions['actions'] as $key => $value) {
445
				if($value['UserAction']['action'] == 'like'){
446
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
447
				}else{
448
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
449
				}
450
			}
451
		}
452
 
453
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1);
454
 
455
		$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
456
		if(!empty($deals) && !empty($deals[0])){
457
			$this->render('/Elements/deals');
458
		}else{
459
			$this->render('/Elements/nodeals');
460
		}
461
 
462
 
463
	}
13532 anikendra 464
/**
465
 * add method
466
 *
467
 * @return void
468
 */
469
	public function add() {
470
		if ($this->request->is('post')) {
471
			$this->Category->create();
472
			if ($this->Category->save($this->request->data)) {
473
				$this->Session->setFlash(__('The category has been saved.'));
474
				return $this->redirect(array('action' => 'index'));
475
			} else {
476
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
477
			}
478
		}
479
	}
480
 
481
/**
482
 * edit method
483
 *
484
 * @throws NotFoundException
485
 * @param string $id
486
 * @return void
487
 */
488
	public function edit($id = null) {
489
		if (!$this->Category->exists($id)) {
490
			throw new NotFoundException(__('Invalid category'));
491
		}
492
		if ($this->request->is(array('post', 'put'))) {
493
			if ($this->Category->save($this->request->data)) {
494
				$this->Session->setFlash(__('The category has been saved.'));
495
				return $this->redirect(array('action' => 'index'));
496
			} else {
497
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
498
			}
499
		} else {
500
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
501
			$this->request->data = $this->Category->find('first', $options);
502
		}
503
	}
504
 
505
/**
506
 * delete method
507
 *
508
 * @throws NotFoundException
509
 * @param string $id
510
 * @return void
511
 */
512
	public function delete($id = null) {
513
		$this->Category->id = $id;
514
		if (!$this->Category->exists()) {
515
			throw new NotFoundException(__('Invalid category'));
516
		}
517
		$this->request->onlyAllow('post', 'delete');
518
		if ($this->Category->delete()) {
519
			$this->Session->setFlash(__('The category has been deleted.'));
520
		} else {
521
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
522
		}
523
		return $this->redirect(array('action' => 'index'));
524
	}
525
 
526
/**
527
 * admin_index method
528
 *
529
 * @return void
530
 */
531
	public function admin_index() {
532
		$this->Category->recursive = 0;
533
		$this->set('categories', $this->Paginator->paginate());
534
	}
535
 
536
/**
537
 * admin_view method
538
 *
539
 * @throws NotFoundException
540
 * @param string $id
541
 * @return void
542
 */
543
	public function admin_view($id = null) {
544
		if (!$this->Category->exists($id)) {
545
			throw new NotFoundException(__('Invalid category'));
546
		}
547
		$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
548
		$this->set('category', $this->Category->find('first', $options));
549
	}
550
 
551
/**
552
 * admin_add method
553
 *
554
 * @return void
555
 */
556
	public function admin_add() {
557
		if ($this->request->is('post')) {
558
			// print_r($this->request->data);die;
559
			$this->Category->create();
560
			if ($this->Category->save($this->request->data)) {
561
				$this->Session->setFlash(__('The category has been saved.'));
562
				return $this->redirect(array('action' => 'index'));
563
			} else {
564
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
565
			}
566
		}
567
		$this->set('parent_id',$this->Category->find('list'));
568
	}
569
 
570
/**
571
 * admin_edit method
572
 *
573
 * @throws NotFoundException
574
 * @param string $id
575
 * @return void
576
 */
577
	public function admin_edit($id = null) {
578
		if (!$this->Category->exists($id)) {
579
			throw new NotFoundException(__('Invalid category'));
580
		}
581
		if ($this->request->is(array('post', 'put'))) {
582
			if ($this->Category->save($this->request->data)) {
583
				$this->Session->setFlash(__('The category has been saved.'));
584
				return $this->redirect(array('action' => 'index'));
585
			} else {
586
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
587
			}
588
		} else {
589
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
590
			$this->request->data = $this->Category->find('first', $options);
591
		}
592
	}
593
 
594
/**
595
 * admin_delete method
596
 *
597
 * @throws NotFoundException
598
 * @param string $id
599
 * @return void
600
 */
601
	public function admin_delete($id = null) {
602
		$this->Category->id = $id;
603
		if (!$this->Category->exists()) {
604
			throw new NotFoundException(__('Invalid category'));
605
		}
606
		$this->request->onlyAllow('post', 'delete');
607
		if ($this->Category->delete()) {
608
			$this->Session->setFlash(__('The category has been deleted.'));
609
		} else {
610
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
611
		}
612
		return $this->redirect(array('action' => 'index'));
613
	}}