Subversion Repositories SmartDukaan

Rev

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