Subversion Repositories SmartDukaan

Rev

Rev 14517 | Go to most recent revision | Details | 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
 
43
/**
44
 * admin_view method
45
 *
46
 * @throws NotFoundException
47
 * @param string $id
48
 * @return void
49
 */
50
	public function admin_view($id = null) {
51
		if (!$this->Exceptionalnlc->exists($id)) {
52
			throw new NotFoundException(__('Invalid exceptionalnlc'));
53
		}
54
		$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
55
		$this->set('exceptionalnlc', $this->Exceptionalnlc->find('first', $options));
56
	}
57
 
58
/**
59
 * admin_add method
60
 *
61
 * @return void
62
 */
63
	public function admin_add() {
64
		if ($this->request->is('post')) {
65
			$this->request->data['ManualDeal']['startDate'] = 1000*mktime(0,0,0,$this->request->data['ManualDeal']['startDate']['month'],$this->request->data['ManualDeal']['startDate']['day'],$this->request->data['ManualDeal']['startDate']['year']);
66
			$this->request->data['ManualDeal']['endDate'] = 1000*mktime(0,0,0,$this->request->data['ManualDeal']['endDate']['month'],$this->request->data['ManualDeal']['endDate']['day'],$this->request->data['ManualDeal']['endDate']['year']);
67
			$url = $this->apihost."manualDeals/addManualDeals";
68
			$jsonVar = json_encode($this->request->data['ManualDeal'], JSON_NUMERIC_CHECK );
69
			$response = $this->make_request($url,$jsonVar);
70
			if (key($response)) {
71
				$this->Session->setFlash(current($response));
72
				return $this->redirect(array('action' => 'index'));
73
			} else {
74
				$this->Session->setFlash(current($response));
75
			}	
76
		}
77
		$this->loadModel('Store');
78
		$this->set('sources',$this->Store->find('list'));
79
	}
80
 
81
/**
82
 * admin_edit method
83
 *
84
 * @throws NotFoundException
85
 * @param string $id
86
 * @return void
87
 */
88
	public function admin_edit($id = null) {
89
		if (!$this->Exceptionalnlc->exists($id)) {
90
			throw new NotFoundException(__('Invalid exceptionalnlc'));
91
		}
92
		if ($this->request->is(array('post', 'put'))) {
93
			if ($this->Exceptionalnlc->save($this->request->data)) {
94
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
95
				return $this->redirect(array('action' => 'index'));
96
			} else {
97
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
98
			}
99
		} else {
100
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
101
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
102
		}
103
	}
104
 
105
/**
106
 * admin_delete method
107
 *
108
 * @throws NotFoundException
109
 * @param string $id
110
 * @return void
111
 */
112
	public function admin_delete($id = null) {		
113
		// $this->request->onlyAllow('post', 'delete');
114
		if ($this->remove($id,'ManualDeals')) {
115
			$this->Session->setFlash(__('The manual deal has been deleted.'));
116
		} else {
117
			$this->Session->setFlash(__('The manual could not be deleted. Please, try again.'));
118
		}
119
		return $this->redirect(array('action' => 'index'));
120
	}
121
}