Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15403 manish.sha 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";
52
		$response = $this->make_request($url,null);
53
		$this->set('featureddeals', $response);
54
		$this->set('page',1);
55
		$this->render('admin_index');
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['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']);
66
			$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']);
67
			// $this->request->data['FeaturedDeal']['rankDetails']= array($this->request->data['FeaturedDeal']['type'] => $this->request->data['FeaturedDeal']['rankDetails']);
68
			// unset($this->request->data['FeaturedDeal']['rankDetails']);
69
			unset($this->request->data['FeaturedDeal']['type']);
70
			foreach ($this->request->data['FeaturedDeal']['rankDetails'] as $key => $value) {
71
				if(empty($value)){
72
					unset($this->request->data['FeaturedDeal']['rankDetails'][$key]);
73
				}
74
			}
75
			$this->log(print_r($this->request->data,1),'featuredeals');
76
			$url = $this->apihost."featuredDeals/addFeaturedDeals";
77
			$data = $this->request->data['FeaturedDeal'];
78
			$url = $this->generateMultiUrl($url,$data);
79
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
80
			$response = $this->make_request($url,$jsonVar);
81
			if (key($response)) {
82
				$this->Session->setFlash(current($response));
83
				return $this->redirect(array('action' => 'index'));
84
			} else {
85
				$this->Session->setFlash(current($response));
86
			}	
87
		}
88
	}
89
 
90
/**
91
 * admin_edit method
92
 *
93
 * @throws NotFoundException
94
 * @param string $id
95
 * @return void
96
 */
97
	public function admin_edit($id = null) {
98
		if (!$this->Exceptionalnlc->exists($id)) {
99
			throw new NotFoundException(__('Invalid exceptionalnlc'));
100
		}
101
		if ($this->request->is(array('post', 'put'))) {
102
			if ($this->Exceptionalnlc->save($this->request->data)) {
103
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
104
				return $this->redirect(array('action' => 'index'));
105
			} else {
106
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
107
			}
108
		} else {
109
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
110
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
111
		}
112
	}
113
 
114
/**
115
 * admin_delete method
116
 *
117
 * @throws NotFoundException
118
 * @param string $id
119
 * @return void
120
 */
121
 
122
	public function admin_delete($id = null) {		
123
		// $this->request->onlyAllow('post', 'delete');
124
		if ($this->remove($id,'FeaturedDeals')) {
125
			$this->Session->setFlash(__('The negative deal has been deleted.'));
126
		} else {
127
			$this->Session->setFlash(__('The negative could not be deleted. Please, try again.'));
128
		}
129
		return $this->redirect(array('action' => 'index'));
130
	}	
131
}