Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
17630 naman 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class DealobjectsController 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/getAllFeaturedDealObject/?limit=$limit&offset=$offset";
36
		$response = $this->make_request($url,null);
37
		$this->set('dealobjects', $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
 
49
 
50
/**
51
 * admin_add method
52
 *
53
 * @return void
54
 */
55
	public function admin_add() {
56
		if ($this->request->is('post')) {			
57
			// date_default_timezone_set('UTC'); 
58
			$otherrank = array();
59
			$othercat = array();
60
			$othercat['mobilerank'] = $this->request->data['Dealobjects']['Mobiles'];
61
			$othercat['tabletrank'] = $this->request->data['Dealobjects']['Tablets'];
62
			$othercat['accessrank'] = $this->request->data['Dealobjects']['Accessories'];
63
			$rankandcat['3'] = $othercat['mobilerank'];
64
			$rankandcat['5'] = $othercat['tabletrank'];
65
			$rankandcat['6'] = $othercat['accessrank'];
66
			$this->request->data['Dealobjects']['startDate'] = 1000*mktime($this->request->data['Dealobjects']['startDate']['hour'],$this->request->data['Dealobjects']['startDate']['min'],0,$this->request->data['Dealobjects']['startDate']['month'],$this->request->data['Dealobjects']['startDate']['day'],$this->request->data['Dealobjects']['startDate']['year']);
67
			$this->request->data['Dealobjects']['endDate'] = 1000*mktime($this->request->data['Dealobjects']['endDate']['hour'],$this->request->data['Dealobjects']['endDate']['min'],0,$this->request->data['Dealobjects']['endDate']['month'],$this->request->data['Dealobjects']['endDate']['day'],$this->request->data['Dealobjects']['endDate']['year']);
68
			$form_val = array();
69
			$form_val['_id'] = $this->request->data['Dealobjects']['id'];
70
 
71
			$form_val['startDate'] = $this->request->data['Dealobjects']['startDate'];
72
			$form_val['endDate'] = $this->request->data['Dealobjects']['endDate'];
73
			$form_val['otherInfo'] = $rankandcat;
74
 
75
			$url = $this->apihost."featuredDeals/addFeaturedDealObject";
76
			$response = $this->make_request($url,json_encode($form_val,JSON_NUMERIC_CHECK));
77
 
78
 
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
/**
90
 * admin_delete method
91
 *
92
 * @throws NotFoundException
93
 * @param string $id
94
 * @return void
95
 */
96
 
97
	public function admin_delete($id = null) {		
98
		$url = $this->apihost."deleteFeaturedDealObject/".$id;
99
		$response = $this->make_request($url,null);
100
		if (key($response)) {
101
			$this->Session->setFlash(current($response));
102
			return $this->redirect(array('action' => 'index'));
103
		} else {
104
			$this->Session->setFlash(current($response));
105
		}
106
	}	
107
}