Subversion Repositories SmartDukaan

Rev

Rev 14517 | Rev 14561 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14517 anikendra 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() {
14533 anikendra 64
		if ($this->request->is('post')) {			
14517 anikendra 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']);
14533 anikendra 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');
14517 anikendra 76
			$url = $this->apihost."featuredDeals/addFeaturedDeals";
77
			$jsonVar = json_encode($this->request->data['FeaturedDeal'], JSON_NUMERIC_CHECK );
78
			$response = $this->make_request($url,$jsonVar);
79
			if (key($response)) {
80
				$this->Session->setFlash(current($response));
81
				return $this->redirect(array('action' => 'index'));
82
			} else {
83
				$this->Session->setFlash(current($response));
84
			}	
85
		}
86
	}
87
 
88
/**
89
 * admin_edit method
90
 *
91
 * @throws NotFoundException
92
 * @param string $id
93
 * @return void
94
 */
95
	public function admin_edit($id = null) {
96
		if (!$this->Exceptionalnlc->exists($id)) {
97
			throw new NotFoundException(__('Invalid exceptionalnlc'));
98
		}
99
		if ($this->request->is(array('post', 'put'))) {
100
			if ($this->Exceptionalnlc->save($this->request->data)) {
101
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
102
				return $this->redirect(array('action' => 'index'));
103
			} else {
104
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
105
			}
106
		} else {
107
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
108
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
109
		}
110
	}
111
 
112
/**
113
 * admin_delete method
114
 *
115
 * @throws NotFoundException
116
 * @param string $id
117
 * @return void
118
 */
119
 
120
	public function admin_delete($id = null) {		
121
		// $this->request->onlyAllow('post', 'delete');
122
		if ($this->remove($id,'FeaturedDeals')) {
123
			$this->Session->setFlash(__('The negative deal has been deleted.'));
124
		} else {
125
			$this->Session->setFlash(__('The negative could not be deleted. Please, try again.'));
126
		}
127
		return $this->redirect(array('action' => 'index'));
128
	}	
129
}