Subversion Repositories SmartDukaan

Rev

Rev 19622 | Rev 19644 | 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');
18223 naman 25
		$this->mobileapi = Configure::read('saholicapihost');
19244 amit.gupta 26
		setcookie("fresh", '1', null, '/');
18223 naman 27
 
13596 anikendra 28
	}
29
 
13532 anikendra 30
/**
31
 * index method
32
 *
33
 * @return void
34
 */
35
	public function index() {
36
		// $this->Category->recursive = 0;
37
		// $this->set('categories', $this->Paginator->paginate());
13541 anikendra 38
		$userId = $this->request->query('user_id');
39
		$this->loadModel('UserCategory');
13689 anikendra 40
		$options = array('conditions' => array('user_id'=>$userId),'order'=>array('rank','asc'),'recursive'=>-1);
13541 anikendra 41
		$userCategories = $this->UserCategory->find('all',$options);		
13532 anikendra 42
		$this->response->type('json');
43
		$this->layout = 'ajax';
13541 anikendra 44
		$conditions = array(array('Category.parent_id !='=>0));
45
		if(!empty($userCategories)){
46
			foreach ($userCategories as $key => $value) {
47
				$categoryIds[] = $value['UserCategory']['category_id'];
48
			}
49
			array_push($conditions,array('Category.id'=>$categoryIds));
50
		}
51
		$this->Category->recursive = -1;		
13532 anikendra 52
		$categories = $this->Paginator->paginate(null,$conditions);
53
		$callback = $this->request->query('callback');
54
		$result = array('categories' => $categories);
55
		$this->set(array(
56
		    'result' => $result,
57
		    'callback' => $callback,
58
		    '_serialize' => array('result')
59
		));
60
		$this->render('/Elements/jsonp');
61
	}
62
 
13567 anikendra 63
	public function deals(){
13591 anikendra 64
		$userId = $this->request->query('user_id');
17962 manish.sha 65
		$error = $this->request->query('error');
13591 anikendra 66
		if(isset($userId) && !empty($userId)){
13597 anikendra 67
			$this->loadModel('User');
68
			$dbuser = $this->User->findById($userId);
69
			$this->Auth->login($dbuser['User']);	
13591 anikendra 70
		}
13583 anikendra 71
		$likedDeals = $disLikedDeals = array();
13794 anikendra 72
		// $this->loadModel('Api');
73
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
74
		// $categorydeals = $apideals['products'];
75
		$page = $this->request->query('page');
76
		if(!isset($page)){
77
			$page = 1;
78
		}
79
		$offset = ($page - 1) * $this->limit;
80
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
17683 naman 81
		//debug($url);
13794 anikendra 82
		$deals = $this->make_request($url,null);		
13583 anikendra 83
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
84
		if(!empty($myactions)) {
85
			foreach ($myactions['actions'] as $key => $value) {
86
				if($value['UserAction']['action'] == 'like'){
87
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
88
				}else{
89
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
90
				}
91
			}
92
		}
17962 manish.sha 93
 
94
		$errorstr = '';
95
 
96
		if(isset($error)){
97
			$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
98
		}
13567 anikendra 99
		$rows = sizeof($categorydeals);
100
		if($rows>=1){
101
			$this->set('deals',$categorydeals);
13583 anikendra 102
			$this->set('likedDeals',$likedDeals);
103
			$this->set('disLikedDeals',$disLikedDeals);
17962 manish.sha 104
			$this->set('errorstr',$errorstr);
13567 anikendra 105
			$this->render('categorydeals');
106
		}else{
107
			foreach ($categorydeals as $key => $dealarr) {
108
				foreach ($dealarr as $key => $deal) {
109
					$deals[] = $deal[0];
110
				}				
111
			}
17962 manish.sha 112
			$this->set(compact('deals','likedDeals','disLikedDeals','errorstr'));
13567 anikendra 113
		}		
114
	}
115
/*
116
	*
13532 anikendra 117
 * view method
118
 *
119
 * @throws NotFoundException
120
 * @param string $id
121
 * @return void
122
 */
123
	public function view($id = null) {
19609 naman 124
		$arrSubCategory = Configure::read('arrSubCategory');
18393 amit.gupta 125
		$userId = $this->request->query('user_id');
15378 anikendra 126
		if(isset($userId) && !empty($userId)) {
14930 anikendra 127
			$this->loadModel('User');
128
			$dbuser = $this->User->findById($userId);
129
			$this->Auth->login($dbuser['User']);
19345 naman 130
		}			
131
 
18390 naman 132
		//Sort - type, ordering
133
		$sort = $this->request->query('sort');
134
		$direction = $this->request->query('direction');
135
 
136
		//Filter - brand/subcategory		
137
		$brands = $this->request->query('brands');
138
		$subcategories = $this->request->query('subcategories');
139
 
19543 amit.gupta 140
		$searchableSubCategories = array('20'=>'Screen Guard', '27'=>'Back Cover', '29'=>'Batteries', '33'=>'Flip Cover', '28'=>'Tempered Glass');
18390 naman 141
 
19609 naman 142
		$subcatlist = Configure::read('arrSubCategory');
143
 
144
		$whatfirst = $this->request->query('whatfirst');
145
 
19640 naman 146
		if(isset($brands) && !empty($brands) && !isset($subcategories) && !isset($whatfirst)){
147
			$whatfirst = "brand";
148
		}
149
		else if(isset($subcategories) && !empty($subcategories) && !isset($brands) && !isset($whatfirst)){
150
			$whatfirst = "subCategory";
151
		}else if(isset($subcategories) && !empty($subcategories) && isset($brands) && !empty($brands) && !isset($whatfirst)){
152
			$whatfirst = "subCategory";
153
		}
154
 
19622 naman 155
		if($id == 6)
156
		{
157
			$cachekey = 'subcat-6';
158
			$getdet = Cache::read($cachekey,'subcatdetail');
159
			if(empty($getdet) || $getdet === false){
160
				$url = $this->apihost.'deals/subCategory/?category_id=6';
161
				$getdet = $this->make_request($url,null);
162
				Cache::write($cachekey , $getdet ,'subcatdetail');
163
			}
164
			$this->set(compact('getdet'));
165
		}
166
 
19609 naman 167
		$whatsecond = "";
168
		$whatsecondid = "";
169
		$whatfirstid = "";
170
		$secondloop = "";
171
		if(isset($whatfirst)){
172
			$brandprourl = "";
173
			if($whatfirst == "subCategory"){
174
				$secondloop = explode("^",$brands);
175
				$whatsecond = "brand";
176
				$whatsecondid = "brand_id";
177
				$whatfirstid = "subCategoryId";
178
				$brandprourl = $this->apihost."getBrandSubCategoryInfo/?category_id=6&type=subCategoryInfo&id_list=".$subcategories;
179
			}
180
			else if($whatfirst == "brand"){
181
 
182
				$secondloop = explode("^",$subcategories);
183
				$whatsecond = "subCategory";
184
				$whatsecondid = "subCategoryId";
185
				$whatfirstid = "brand_id";
186
				$brandprourl = $this->apihost."getBrandSubCategoryInfo/?category_id=6&type=brandInfo&id_list=".$brands;
187
			}
188
			$allbrandsubcat = $this->make_request($brandprourl, null);
189
			$this->set(compact('secondloop','whatfirstid','whatsecondid','subcatlist','whatfirst','whatsecond','allbrandsubcat'));
190
		}
191
 
192
 
13583 anikendra 193
		$page = $this->request->query('page');
18063 naman 194
		$searchfor = $this->request->query('searchFor');
195
		// echo "page=>",$page;
17810 manish.sha 196
		$error = $this->request->query('error');
13583 anikendra 197
		if(!isset($page)){
198
			$page = 1;
16549 anikendra 199
		}
200
 
18207 amit.gupta 201
		//$filter = $this->request->query('filter');
15044 anikendra 202
		// $brands = $this->request->query('brands');
16549 anikendra 203
		if($id != 2) {
204
			//Fetch deals
205
			$likedDeals = $disLikedDeals = array();
18390 naman 206
			if(!empty($brands) && !empty($subcategories)){
207
				$filter = 'brand|subcategory';
208
			}			
209
			else if(!empty($brands)){
210
				$filter = 'brand';
211
			}
212
			else if(!empty($subcategories)){
213
				$filter = 'subcategory';
214
			}
17759 naman 215
 
18390 naman 216
			$sortlabel = 'recommended';
217
			if	($sort=='bestSellerPoints'){
218
				$sortlabel  = 'bestseller';
18063 naman 219
			}
18390 naman 220
			else if ($sort=='available_price' && $direction==-1){
221
				$sortlabel  = 'pricehigh';
16549 anikendra 222
			}
18390 naman 223
			else if ($sort=='available_price' && $direction==1){
224
				$sortlabel  = 'pricelow';
225
			}
17683 naman 226
 
227
			$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16549 anikendra 228
			$response = $this->make_request($url,null);
229
			$deals = array();
17683 naman 230
 
231
			$response_count =1;
232
			if($response == '')
233
			{
234
				$response_count = 0;
235
			}
236
			// debug($response_count);
16549 anikendra 237
			if(!empty($response)){
238
				foreach ($response as $key => $value) {
239
					if(!empty($value)){
240
						$deals[] = $value;
241
					}
16098 anikendra 242
				}
243
			}
17683 naman 244
			#print_r($deals);
16549 anikendra 245
			$this->loadModel('Api');
246
			$myactions = $this->Api->getMyActions($this->Auth->User('id'));
247
			if(!empty($myactions)) {
248
				foreach ($myactions['actions'] as $key => $value) {
249
					if($value['UserAction']['action'] == 'like'){
250
						$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
251
					}else{
252
						$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
253
					}
13583 anikendra 254
				}
255
			}
16549 anikendra 256
			$this->loadModel('NotificationRule');
257
			$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));	
258
		    $filterstr = '';
259
			if(isset($filter) && !empty($filter)){
17759 naman 260
 
17683 naman 261
			    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
17695 naman 262
		  	} 
263
		  	$get_url = "'".$_SERVER['REQUEST_URI']."'";
264
		  	$urlArray = explode('=',$_SERVER['REQUEST_URI']);
265
		  	$last = $urlArray[sizeof($urlArray)-1];
266
 
17810 manish.sha 267
			$errorstr = '';
268
 
269
			if(isset($error)){
270
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
271
			}
17759 naman 272
 
18390 naman 273
			$filterstr = '&brands='.$brands.'&subcategories='.$subcategories;
274
			$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;			
18063 naman 275
 
19609 naman 276
			$offerresponse = $this->getuseroffer();
277
			$color = array('0'=>'#458ccc','1'=>'#44cbbc','2'=>'#a77189', '3'=>'#f9b931' ,'4' =>'#44cbbc', '5' => '#f48f3f' , '6'=>'#a77189');
278
			$this->set(compact('color','arrSubCategory','offerresponse','response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','subcategories','errorstr','nexturl','searchfor', 'searchableSubCategories', 'sortlabel'));
16549 anikendra 279
		}else{
16583 anikendra 280
			//Check for apk support of sharing
281
			$sharable = 0;
282
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
283
				$sharable = 1;
17183 anikendra 284
			}			
16704 anikendra 285
			$url = $this->apihost."appOffers/1";
286
			$appOffers = $this->make_request($url,null);
287
			$this->set(compact('page','id','sharable','appOffers'));
16549 anikendra 288
			$this->render('viewapps');
13583 anikendra 289
		}
13532 anikendra 290
	}
291
 
16549 anikendra 292
	public function getapps($id=null){
293
		$this->layout = 'ajax';
294
		$page = $this->request->query('page');
295
		if(!isset($page)){
296
			$page = 1;
297
		}
298
		$this->loadModel('AppOffer');
299
		$this->AppOffer->recursive = -1;
300
		$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);
301
		$this->Paginator->settings = $options;
302
		try{
303
			$appOffers = $this->Paginator->paginate('AppOffer');
304
		} catch (NotFoundException $e) {
305
	        //get current page
306
	        $page = $this->request->params['named']['page'];
307
	     	$appOffers = array();   
308
		}
309
		debug($appOffers);		
310
		if(!empty($appOffers)){
311
			$this->set(compact('page','id','appOffers'));
312
			$this->render('/Elements/appoffers');
313
		}else{
314
			$this->render('/Elements/nooffers');
315
		}		
316
	}
317
 
13579 anikendra 318
	public function getdeals($id = null) {
17695 naman 319
 
13808 anikendra 320
		$this->log('getdeal id '.$id,'api');
13583 anikendra 321
		$likedDeals = $disLikedDeals = array();
13579 anikendra 322
		$this->layout = 'ajax';
323
		$page = $this->request->query('page');
324
		if(!isset($page)){
325
			$page = 1;
326
		}
13808 anikendra 327
		$sort = $this->request->query('sort');
328
		$direction = $this->request->query('direction');
15044 anikendra 329
		// $filter = $this->request->query('filter');
330
		// $brands = $this->request->query('brands');
18390 naman 331
		$brands = $this->request->query('brands');
332
		$subcategories = $this->request->query('subcategories'); 	
17759 naman 333
 
18390 naman 334
		$likedDeals = $disLikedDeals = array();
335
		if(!empty($brands) && !empty($subcategories)){
17759 naman 336
			$filter = 'brand|subcategory';
18390 naman 337
		}
338
		else if(!empty($brands)){
15044 anikendra 339
			$filter = 'brand';
340
		}
18390 naman 341
		else if(!empty($subcategories)){
17759 naman 342
			$filter = 'subcategory';
343
		}
18390 naman 344
 
17759 naman 345
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16098 anikendra 346
		$response = $this->make_request($url,null);
347
		$deals = array();
348
		if(!empty($response)){
349
			foreach ($response as $key => $value) {
350
				if(!empty($value)){
351
					$deals[] = $value;
352
				}
353
			}
354
		}
13794 anikendra 355
		// if (!$this->Category->exists($id)) {
356
			// throw new NotFoundException(__('Invalid category'));
357
		// }
13579 anikendra 358
		$this->loadModel('Api');
13794 anikendra 359
		// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
360
		// $deals = $apideals['products'];
13583 anikendra 361
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
362
		if(!empty($myactions)) {
363
			foreach ($myactions['actions'] as $key => $value) {
364
				if($value['UserAction']['action'] == 'like'){
365
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
366
				}else{
367
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
368
				}
369
			}
370
		}
18390 naman 371
 
372
		$filterstr = '&brands='.$brands.'&subcategories='.$subcategories;
373
		$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
19306 naman 374
 
19609 naman 375
		$offerresponse = $this->getuseroffer();
19306 naman 376
 
19609 naman 377
		$this->set(compact('offerresponse','nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
16098 anikendra 378
		if(!empty($deals) && !empty($deals[0])){
15026 anikendra 379
			$this->render('/Elements/deals');
380
		}else{
381
			$this->render('/Elements/nodeals');
382
		}
17695 naman 383
 
384
 
385
 
13579 anikendra 386
	}
18063 naman 387
 
18212 naman 388
	public function dealdetail($item_id = null){
19244 amit.gupta 389
		setcookie("fresh", '0', null, '/');
18212 naman 390
		$this->layout = "innerpages";
18223 naman 391
		$dealinfo = $deal = array();
392
		$likedDeals = $disLikedDeals = array();
393
		$url = $this->mobileapi.'entity/'.$item_id;
394
		$dealinfo = $this->make_request($url,null);
395
		$this->loadModel('Api');
396
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
397
		if(!empty($myactions)) {
398
			foreach ($myactions['actions'] as $key => $value) {
399
				if($value['UserAction']['action'] == 'like'){
400
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
401
				}else{
402
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
403
				}
404
			}
405
		}
406
		$this->set(compact('deal','dealinfo','likedDeals','disLikedDeals'));
18212 naman 407
	}
408
 
18288 naman 409
	public function saholicdeal($proid = null){
410
		$likedDeals = $disLikedDeals = array();
411
		$this->layout = 'ajax';
412
		$deal = array();
413
		$url = $this->apihost."getDealById/".$proid;
414
		$deal = $this->make_request($url,null);
415
		$this->loadModel('Api');
416
 
417
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
418
		if(!empty($myactions)) {
419
			foreach ($myactions['actions'] as $key => $value) {
420
				if($value['UserAction']['action'] == 'like'){
421
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
422
				}else{
423
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
424
				}
425
			}
426
		}
427
 
19609 naman 428
		$offerresponse = $this->getuseroffer();
18288 naman 429
 
19609 naman 430
		$this->set(compact('offerresponse','deal','likedDeals','disLikedDeals'));
19327 naman 431
 
18288 naman 432
		$this->render('/Elements/saholicdeal');
433
 
434
 
435
	}
436
 
18063 naman 437
	public function getdealsforsearchterm($searchterm,$page = null){
438
		$likedDeals = $disLikedDeals = array();
439
		$this->layout = 'ajax';
440
		$page = $this->request->query('page');
18390 naman 441
		$subcategories = $this->request->query('subcategories'); 
18063 naman 442
		if(!isset($page)){
443
			$page = 1;
444
			$offset = 0;
445
			$limit=10;
446
		}
447
		else{
448
			$offset = ($page*20) - 30;
449
			$limit = 20;
450
		}
451
		$sort = $this->request->query('sort');
452
		$direction = $this->request->query('direction');
453
 
18390 naman 454
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategories;
18063 naman 455
		$response = $this->make_request($url,null);
456
		$deals = array();
457
		if(!empty($response)){
458
			foreach ($response as $key => $value) {
459
				if(!empty($value)){
460
					$deals[] = $value;
461
				}
462
			}
463
		}
18115 amit.gupta 464
 
18063 naman 465
		$this->loadModel('Api');
18115 amit.gupta 466
 
18063 naman 467
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
468
		if(!empty($myactions)) {
469
			foreach ($myactions['actions'] as $key => $value) {
470
				if($value['UserAction']['action'] == 'like'){
471
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
472
				}else{
473
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
474
				}
475
			}
476
		}
477
 
18390 naman 478
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1).'&subcategories='.$subcategories;
19327 naman 479
 
19609 naman 480
		$offerresponse = $this->getuseroffer(); 
19327 naman 481
 
19609 naman 482
		$this->set(compact('offerresponse','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
18063 naman 483
		if(!empty($deals) && !empty($deals[0])){
484
			$this->render('/Elements/deals');
485
		}else{
486
			$this->render('/Elements/nodeals');
487
		}
488
 
489
 
490
	}
19306 naman 491
 
19345 naman 492
	public function target(){
19306 naman 493
		$this->layout = "innerpages";
19374 naman 494
		$user_id = $this->Auth->user('id');
19357 naman 495
 
19306 naman 496
		$cachekey = 'target-'.$user_id;
497
		$getoffer = Cache::read($cachekey,'target');
19333 naman 498
		$current_time = time();
19306 naman 499
		$response = "";
500
		if($getoffer === false){
19357 naman 501
			$offerurl = $this->apihost."getOfferForUser/?user_id=".$user_id;
19306 naman 502
			$response = $this->make_request($offerurl,null);
503
			Cache::write($cachekey , $response ,'target');
504
			if(!empty($response)){
19333 naman 505
 
506
								if($response['startDate']/1000 <= $current_time && $response['endDate']/1000 >= $current_time ){
19306 naman 507
 
508
								}
509
								else{
19333 naman 510
									$response = "";
19306 naman 511
									}
512
				}
513
				else{
19333 naman 514
					$response = "";
19306 naman 515
				}
516
		}else{
19333 naman 517
			if(!empty($getoffer)){
518
					$response = $getoffer;
519
					if($response['startDate']/1000 <= $current_time && $response['endDate']/1000 >= $current_time ){
520
 
521
					}
522
					else{
523
						$response = "";
524
					}
525
				}
19306 naman 526
		}
527
 
528
		$maxpercentage = 0;
19357 naman 529
 
19306 naman 530
		if(isset($response['target2_cash_back_percetage']) && !empty($response['target2_cash_back_percetage'])){
531
			$maxpercentage = $response['target2_cash_back_percetage'];
532
		}
533
		else{
534
			if(isset($response['target1_cash_back_percetage']) && !empty($response['target1_cash_back_percetage'])){
535
				$maxpercentage = $response['target1_cash_back_percetage'];
536
			}
537
		}
538
 
19357 naman 539
 
540
		$this->loadModel('User');
541
		$user_email = "";
19345 naman 542
 
19374 naman 543
		$user_email = $this->Auth->user('email');
19357 naman 544
		$this->set(compact('response','maxpercentage','user_email'));
19306 naman 545
	}
13532 anikendra 546
/**
547
 * add method
548
 *
549
 * @return void
550
 */
551
	public function add() {
552
		if ($this->request->is('post')) {
553
			$this->Category->create();
554
			if ($this->Category->save($this->request->data)) {
555
				$this->Session->setFlash(__('The category has been saved.'));
556
				return $this->redirect(array('action' => 'index'));
557
			} else {
558
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
559
			}
560
		}
561
	}
562
 
563
/**
564
 * edit method
565
 *
566
 * @throws NotFoundException
567
 * @param string $id
568
 * @return void
569
 */
570
	public function edit($id = null) {
571
		if (!$this->Category->exists($id)) {
572
			throw new NotFoundException(__('Invalid category'));
573
		}
574
		if ($this->request->is(array('post', 'put'))) {
575
			if ($this->Category->save($this->request->data)) {
576
				$this->Session->setFlash(__('The category has been saved.'));
577
				return $this->redirect(array('action' => 'index'));
578
			} else {
579
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
580
			}
581
		} else {
582
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
583
			$this->request->data = $this->Category->find('first', $options);
584
		}
585
	}
586
 
587
/**
588
 * delete method
589
 *
590
 * @throws NotFoundException
591
 * @param string $id
592
 * @return void
593
 */
594
	public function delete($id = null) {
595
		$this->Category->id = $id;
596
		if (!$this->Category->exists()) {
597
			throw new NotFoundException(__('Invalid category'));
598
		}
599
		$this->request->onlyAllow('post', 'delete');
600
		if ($this->Category->delete()) {
601
			$this->Session->setFlash(__('The category has been deleted.'));
602
		} else {
603
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
604
		}
605
		return $this->redirect(array('action' => 'index'));
606
	}
607
 
608
/**
609
 * admin_index method
610
 *
611
 * @return void
612
 */
613
	public function admin_index() {
614
		$this->Category->recursive = 0;
615
		$this->set('categories', $this->Paginator->paginate());
616
	}
617
 
618
/**
619
 * admin_view method
620
 *
621
 * @throws NotFoundException
622
 * @param string $id
623
 * @return void
624
 */
625
	public function admin_view($id = null) {
626
		if (!$this->Category->exists($id)) {
627
			throw new NotFoundException(__('Invalid category'));
628
		}
629
		$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
630
		$this->set('category', $this->Category->find('first', $options));
631
	}
632
 
633
/**
634
 * admin_add method
635
 *
636
 * @return void
637
 */
638
	public function admin_add() {
639
		if ($this->request->is('post')) {
640
			// print_r($this->request->data);die;
641
			$this->Category->create();
642
			if ($this->Category->save($this->request->data)) {
643
				$this->Session->setFlash(__('The category has been saved.'));
644
				return $this->redirect(array('action' => 'index'));
645
			} else {
646
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
647
			}
648
		}
649
		$this->set('parent_id',$this->Category->find('list'));
650
	}
651
 
652
/**
653
 * admin_edit method
654
 *
655
 * @throws NotFoundException
656
 * @param string $id
657
 * @return void
658
 */
659
	public function admin_edit($id = null) {
660
		if (!$this->Category->exists($id)) {
661
			throw new NotFoundException(__('Invalid category'));
662
		}
663
		if ($this->request->is(array('post', 'put'))) {
664
			if ($this->Category->save($this->request->data)) {
665
				$this->Session->setFlash(__('The category has been saved.'));
666
				return $this->redirect(array('action' => 'index'));
667
			} else {
668
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
669
			}
670
		} else {
671
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
672
			$this->request->data = $this->Category->find('first', $options);
673
		}
674
	}
675
 
676
/**
677
 * admin_delete method
678
 *
679
 * @throws NotFoundException
680
 * @param string $id
681
 * @return void
682
 */
683
	public function admin_delete($id = null) {
684
		$this->Category->id = $id;
685
		if (!$this->Category->exists()) {
686
			throw new NotFoundException(__('Invalid category'));
687
		}
688
		$this->request->onlyAllow('post', 'delete');
689
		if ($this->Category->delete()) {
690
			$this->Session->setFlash(__('The category has been deleted.'));
691
		} else {
692
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
693
		}
694
		return $this->redirect(array('action' => 'index'));
19613 naman 695
	}}