Subversion Repositories SmartDukaan

Rev

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