Subversion Repositories SmartDukaan

Rev

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