Subversion Repositories SmartDukaan

Rev

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