Subversion Repositories SmartDukaan

Rev

Rev 16493 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14509 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ManualDealsController 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."manualDeals/getManualDeals/?limit=$limit&offset=$offset";
36
		$response = $this->make_request($url,null);
37
		$this->set('negativedeals', $response);
38
		$this->loadModel('Store');
39
		$this->set('sources',$this->Store->find('list'));
40
		$this->set('page',$page);
41
	}
42
 
16520 anikendra 43
	public function admin_dealpoints($type=null) {
16493 anikendra 44
		$page = $this->request->query('page');
45
		if(!isset($page)){
46
			$page = 1;
47
		}
48
		$limit = Configure::read('admindashboardlimit');
16520 anikendra 49
		$offset = ($page - 1)*$limit;		
50
		if($type=='search'){
51
			$type = $this->request->query('type');
52
			$search = $this->request->query('search');				
53
			$url = $this->apihost."Catalog/searchProducts/?class=DealPoints&$type=$search";
54
		}else{
55
			$url = $this->apihost."dealPoints/getDealPoints/?limit=$limit&offset=$offset";
56
		}		
16493 anikendra 57
		$response = $this->make_request($url,null);
58
		$this->set('negativedeals', $response);
59
		$this->loadModel('Store');
60
		$this->set('sources',$this->Store->find('list'));
61
		$this->set('page',$page);
62
	}
63
 
64
	public function admin_add_dealpoints() {
65
		if ($this->request->is('post')) {
66
			$this->request->data['ManualDeals']['startDate'] = 1000*mktime($this->request->data['ManualDeals']['startDate']['hour'],$this->request->data['ManualDeals']['startDate']['min'],0,$this->request->data['ManualDeals']['startDate']['month'],$this->request->data['ManualDeals']['startDate']['day'],$this->request->data['ManualDeals']['startDate']['year']);
67
			$this->request->data['ManualDeals']['endDate'] = 1000*mktime($this->request->data['ManualDeals']['endDate']['hour'],$this->request->data['ManualDeals']['endDate']['min'],0,$this->request->data['ManualDeals']['endDate']['month'],$this->request->data['ManualDeals']['endDate']['day'],$this->request->data['ManualDeals']['endDate']['year']);
68
			$url = $this->apihost."dealPoints/addDealPoints";
69
			$data = $this->request->data['ManualDeals'];
70
			$url = $this->generateMultiUrl($url,$data);
71
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
72
			$response = $this->make_request($url,$jsonVar);
73
			if (key($response)) {
74
				$this->Session->setFlash(current($response));
75
				return $this->redirect(array('action' => 'dealpoints'));
76
			} else {
77
				$this->Session->setFlash(current($response));
78
			}	
79
		}
80
	}
81
 
14509 anikendra 82
/**
83
 * admin_view method
84
 *
85
 * @throws NotFoundException
86
 * @param string $id
87
 * @return void
88
 */
14517 anikendra 89
	public function admin_search() {
90
		$type = $this->request->query('type');
91
		$search = $this->request->query('search');				
92
		$url = $this->apihost."Catalog/searchProducts/?class=".Inflector::pluralize($this->name)."&$type=$search";
93
		$response = $this->make_request($url,null);
94
		$this->set('negativedeals', $response);
95
		$this->set('page',1);
16520 anikendra 96
		$this->loadModel('Store');
14517 anikendra 97
		$this->set('sources',$this->Store->find('list'));
98
		$this->render('admin_index');
14509 anikendra 99
	}
100
/**
101
 * admin_add method
102
 *
103
 * @return void
104
 */
105
	public function admin_add() {
106
		if ($this->request->is('post')) {
16520 anikendra 107
			$this->request->data['ManualDeals']['startDate'] = 1000*mktime($this->request->data['ManualDeals']['startDate']['hour'],$this->request->data['ManualDeals']['startDate']['min'],0,$this->request->data['ManualDeals']['startDate']['month'],$this->request->data['ManualDeals']['startDate']['day'],$this->request->data['ManualDeals']['startDate']['year']);
108
			$this->request->data['ManualDeals']['endDate'] = 1000*mktime($this->request->data['ManualDeals']['endDate']['hour'],$this->request->data['ManualDeals']['endDate']['min'],0,$this->request->data['ManualDeals']['endDate']['month'],$this->request->data['ManualDeals']['endDate']['day'],$this->request->data['ManualDeals']['endDate']['year']);
14509 anikendra 109
			$url = $this->apihost."manualDeals/addManualDeals";
16520 anikendra 110
			$data = $this->request->data['ManualDeals'];
14561 anikendra 111
			$url = $this->generateMultiUrl($url,$data);
112
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
14509 anikendra 113
			$response = $this->make_request($url,$jsonVar);
114
			if (key($response)) {
115
				$this->Session->setFlash(current($response));
116
				return $this->redirect(array('action' => 'index'));
117
			} else {
118
				$this->Session->setFlash(current($response));
119
			}	
120
		}
121
		$this->loadModel('Store');
122
		$this->set('sources',$this->Store->find('list'));
123
	}
124
 
125
/**
126
 * admin_edit method
127
 *
128
 * @throws NotFoundException
129
 * @param string $id
130
 * @return void
131
 */
132
	public function admin_edit($id = null) {
133
		if (!$this->Exceptionalnlc->exists($id)) {
134
			throw new NotFoundException(__('Invalid exceptionalnlc'));
135
		}
136
		if ($this->request->is(array('post', 'put'))) {
137
			if ($this->Exceptionalnlc->save($this->request->data)) {
138
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
139
				return $this->redirect(array('action' => 'index'));
140
			} else {
141
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
142
			}
143
		} else {
144
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
145
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
146
		}
147
	}
148
 
149
/**
150
 * admin_delete method
151
 *
152
 * @throws NotFoundException
153
 * @param string $id
154
 * @return void
155
 */
156
	public function admin_delete($id = null) {		
157
		if ($this->remove($id,'ManualDeals')) {
158
			$this->Session->setFlash(__('The manual deal has been deleted.'));
159
		} else {
160
			$this->Session->setFlash(__('The manual could not be deleted. Please, try again.'));
161
		}
162
		return $this->redirect(array('action' => 'index'));
163
	}
16493 anikendra 164
 
165
	public function admin_delete_dealpoint($id=null) {
166
		if ($this->remove($id,'DealPoints')) {
167
			$this->Session->setFlash(__('The deal point has been deleted.'));
168
		} else {
169
			$this->Session->setFlash(__('The deal pointcould not be deleted. Please, try again.'));
170
		}
171
		return $this->redirect(array('action' => 'dealpoints'));
172
	}
14509 anikendra 173
}