Subversion Repositories SmartDukaan

Rev

Rev 14561 | Rev 17450 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14517 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class FeaturedDealsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
//		Configure::load('live');
21
		$this->apihost = Configure::read('pythonapihost');
22
	}
23
/**
24
 * admin_index method
25
 *
26
 * @return void
27
 */
28
	public function admin_index() {
29
		$page = $this->request->query('page');
30
		if(!isset($page)){
31
			$page = 1;
32
		}
33
		$limit = Configure::read('admindashboardlimit');
34
		$offset = ($page - 1)*$limit;
35
		$url = $this->apihost."featuredDeals/getFeaturedDeals/?limit=$limit&offset=$offset";
36
		$response = $this->make_request($url,null);
37
		$this->set('featureddeals', $response);
38
		$this->set('page',$page);
39
	}
40
 
41
/**
42
 * admin_view method
43
 *
44
 * @throws NotFoundException
45
 * @param string $id
46
 * @return void
47
 */
48
	public function admin_search() {
49
		$type = $this->request->query('type');
50
		$search = $this->request->query('search');				
51
		$url = $this->apihost."Catalog/searchProducts/?class=".Inflector::pluralize($this->name)."&$type=$search";
17342 naman 52
		$url = $this->apihost."Catalog/searchProducts/?class=".Inflector::pluralize($this->name)."&$type=$search";
53
		debug($url);
14517 anikendra 54
		$response = $this->make_request($url,null);
55
		$this->set('featureddeals', $response);
56
		$this->set('page',1);
57
		$this->render('admin_index');
58
	}
59
 
60
/**
61
 * admin_add method
62
 *
63
 * @return void
64
 */
65
	public function admin_add() {
14533 anikendra 66
		if ($this->request->is('post')) {			
17342 naman 67
			// date_default_timezone_set('UTC'); 
14517 anikendra 68
			$this->request->data['FeaturedDeal']['startDate'] = 1000*mktime($this->request->data['FeaturedDeal']['startDate']['hour'],$this->request->data['FeaturedDeal']['startDate']['min'],0,$this->request->data['FeaturedDeal']['startDate']['month'],$this->request->data['FeaturedDeal']['startDate']['day'],$this->request->data['FeaturedDeal']['startDate']['year']);
69
			$this->request->data['FeaturedDeal']['endDate'] = 1000*mktime($this->request->data['FeaturedDeal']['endDate']['hour'],$this->request->data['FeaturedDeal']['endDate']['min'],0,$this->request->data['FeaturedDeal']['endDate']['month'],$this->request->data['FeaturedDeal']['endDate']['day'],$this->request->data['FeaturedDeal']['endDate']['year']);
17342 naman 70
			// echo "startDate ", $this->request->data['FeaturedDeal']['startDate'];
71
			// debug($this->request->data['FeaturedDeal']['startDate']);
14533 anikendra 72
			// $this->request->data['FeaturedDeal']['rankDetails']= array($this->request->data['FeaturedDeal']['type'] => $this->request->data['FeaturedDeal']['rankDetails']);
17342 naman 73
			//// unset($this->request->data['FeaturedDeal']['rankDetails']);
74
			// $form_detail = array();
75
			$form_val = array();
76
			$form_val['skuBundleId'] = $this->request->data['FeaturedDeal']['skuBundleId'];
77
			$form_val['rank'] = $this->request->data['FeaturedDeal']['rankDetails'][0];
78
			$form_val['thresholdPrice'] = $this->request->data['FeaturedDeal']['thresholdPrice'];
79
			$form_val['startDate'] = $this->request->data['FeaturedDeal']['startDate'];
80
			$form_val['endDate'] = $this->request->data['FeaturedDeal']['endDate'];
81
 
82
 
14517 anikendra 83
			$url = $this->apihost."featuredDeals/addFeaturedDeals";
17342 naman 84
			$response = $this->make_request($url,json_encode($form_val,JSON_NUMERIC_CHECK));
85
 
86
			// unset($this->request->data['FeaturedDeal']['type']);
87
			// foreach ($this->request->data['FeaturedDeal']['rankDetails'] as $key => $value) {
88
			// 	if(empty($value)){
89
			// 		unset($this->request->data['FeaturedDeal']['rankDetails'][$key]);
90
			// 	}
91
			// }
92
			// $this->log(print_r($this->request->data,1),'featuredeals');
93
			// // $url = $this->apihost."featuredDeals/addFeaturedDeals";
94
			// // $data = $this->request->data['FeaturedDeal'];
95
			// // $url = $this->generateMultiUrl($url,$data);
96
			// debug($url);
97
			// // $jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
98
			// // $jsonVar = json_encode($form_val,JSON_NUMERIC_CHECK);
99
			// // $response = $this->make_request($url,$jsonVar);
100
 
14517 anikendra 101
			if (key($response)) {
102
				$this->Session->setFlash(current($response));
103
				return $this->redirect(array('action' => 'index'));
104
			} else {
105
				$this->Session->setFlash(current($response));
106
			}	
107
		}
108
	}
109
 
110
/**
111
 * admin_edit method
112
 *
113
 * @throws NotFoundException
114
 * @param string $id
115
 * @return void
116
 */
117
	public function admin_edit($id = null) {
118
		if (!$this->Exceptionalnlc->exists($id)) {
119
			throw new NotFoundException(__('Invalid exceptionalnlc'));
120
		}
121
		if ($this->request->is(array('post', 'put'))) {
122
			if ($this->Exceptionalnlc->save($this->request->data)) {
123
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
124
				return $this->redirect(array('action' => 'index'));
125
			} else {
126
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
127
			}
128
		} else {
129
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
130
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
131
		}
132
	}
133
 
134
/**
135
 * admin_delete method
136
 *
137
 * @throws NotFoundException
138
 * @param string $id
139
 * @return void
140
 */
141
 
142
	public function admin_delete($id = null) {		
143
		// $this->request->onlyAllow('post', 'delete');
144
		if ($this->remove($id,'FeaturedDeals')) {
145
			$this->Session->setFlash(__('The negative deal has been deleted.'));
146
		} else {
147
			$this->Session->setFlash(__('The negative could not be deleted. Please, try again.'));
148
		}
149
		return $this->redirect(array('action' => 'index'));
150
	}	
151
}