Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
15403 manish.sha 1
<?php
2
App::uses('AppController', 'Controller');
3
 
4
/**
5
 * Static content controller
6
 *
7
 * Override this controller by placing a copy in controllers directory of an application
8
 *
9
 * @package       app.Controller
10
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
11
 */
12
class PagesController extends AppController {
13
 
14
/**
15
 * This controller does not use a model
16
 *
17
 * @var array
18
 */
19
	public $uses = array('Api');
20
	public $helpers = array('Text');
21
 
22
	public $components = array('Paginator','RequestHandler');
23
/**
24
 * Displays a view
25
 *
26
 * @param mixed What page to display
27
 * @return void
28
 * @throws NotFoundException When the view file could not be found
29
 *	or MissingViewException in debug mode.
30
 */
31
 
32
	public function display() {
33
		$page = $this->request->query('page');
34
		if(!isset($page)){
35
			$page = 1;
36
		}
37
		if($this->request->is('ajax')){
38
			$this->layout = 'ajax';
39
		}
40
		$path = func_get_args();
41
 
42
		$count = count($path);
43
		if (!$count) {
44
			return $this->redirect('/');
45
		}
46
		$page = $subpage = $title_for_layout = null;
47
 
48
		if (!empty($path[0])) {
49
			$page = $path[0];
50
		}
51
		if (!empty($path[1])) {
52
			$subpage = $path[1];
53
		}
54
		if (!empty($path[$count - 1])) {
55
			$title_for_layout = Inflector::humanize($path[$count - 1]);
56
		}
57
		$title_for_layout = "Amazing Deals on the Go";
58
		$description = "Hottest Mobile Deals in Hot Hot Summer";
59
		$apideals = $this->Api->getDeals();
60
		$deals = $apideals['products'];
61
		$this->loadModel('Campaign');
62
		$campaigns = $this->Campaign->getActiveCampaigns();	
63
		//Load the most viewed videos
64
 
65
		$sort = '';
66
		$direction = '';
67
		$brandschosen = '';	  	
68
		$filter = '';
69
		$brands = '';
70
		$id =3;
71
 
72
		$urlpage = $page;
73
 
74
		if($page=='home'){
75
			$urlpage =1;
76
		}
77
 
78
		$url = $this->getDealsApiUrl($urlpage,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands);
79
		// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
80
 
81
		$deals = $this->make_request($url,null);
82
		$this->loadModel('Api');
83
		// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
84
		// $deals = $apideals['products'];
85
 
86
 
87
	  	$storeicons = Configure::read('storeicons');
88
 
89
		$this->set(compact('page', 'subpage', 'title_for_layout', 'description', 'deals','campaigns','id','sort','direction','storeicons'));
90
		try {
91
			$this->render(implode('/', $path));
92
		} catch (MissingViewException $e) {
93
			if (Configure::read('debug')) {
94
				throw $e;
95
			}
96
			throw new NotFoundException();
97
		}
98
	}
99
	/*
100
	public function display() {
101
		$page = $this->request->query('page');
102
		if(!isset($page)){
103
			$page = 1;
104
		}
105
		if($this->request->is('ajax')){
106
			$this->layout = 'ajax';
107
		}
108
		$path = func_get_args();
109
 
110
		$count = count($path);
111
		if (!$count) {
112
			return $this->redirect('/');
113
		}
114
		$page = $subpage = $title_for_layout = null;
115
 
116
		if (!empty($path[0])) {
117
			$page = $path[0];
118
		}
119
		if (!empty($path[1])) {
120
			$subpage = $path[1];
121
		}
122
		if (!empty($path[$count - 1])) {
123
			$title_for_layout = Inflector::humanize($path[$count - 1]);
124
		}
125
		$title_for_layout = "Amazing Deals on the Go";
126
		$description = "Get cashback on your favourite products.Mouth watering deals";
127
		$apideals = $this->Api->getDeals();
128
 
129
		$userId = 1;
130
		if(isset($userId) && !empty($userId)){
131
			$this->loadModel('User');
132
			$dbuser = $this->User->findById($userId);
133
			$this->Auth->login($dbuser['User']);	
134
		}
135
		$likedDeals = $disLikedDeals = array();
136
		// $this->loadModel('Api');
137
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
138
		// $categorydeals = $apideals['products'];
139
		$page = $this->request->query('page');
140
		if(!isset($page)){
141
			$page = 1;
142
		}
143
		$offset = ($page - 1) * $this->limit;
144
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
145
		$deals = $this->make_request($url,null);		
146
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
147
		if(!empty($myactions)) {
148
			foreach ($myactions['actions'] as $key => $value) {
149
				if($value['UserAction']['action'] == 'like'){
150
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
151
				}else{
152
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
153
				}
154
			}
155
		}
156
		$storeicons = Configure::read('storeicons');
157
		$this->loadModel('Campaign');
158
		$campaigns = $this->Campaign->getActiveCampaigns();	
159
 
160
		$this->set(compact('page', 'subpage', 'title_for_layout', 'description','deals','likedDeals','disLikedDeals','storeicons','campaigns'));
161
 
162
		try {
163
			$this->render(implode('/', $path));
164
		} catch (MissingViewException $e) {
165
			if (Configure::read('debug')) {
166
				throw $e;
167
			}
168
			throw new NotFoundException();
169
		}
170
	}
171
 
172
	public function deals(){
173
		$userId = 1;
174
		if(isset($userId) && !empty($userId)){
175
			$this->loadModel('User');
176
			$dbuser = $this->User->findById($userId);
177
			$this->Auth->login($dbuser['User']);	
178
		}
179
		$likedDeals = $disLikedDeals = array();
180
		// $this->loadModel('Api');
181
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
182
		// $categorydeals = $apideals['products'];
183
		$page = $this->request->query('page');
184
		if(!isset($page)){
185
			$page = 1;
186
		}
187
		$offset = ($page - 1) * $this->limit;
188
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
189
		$deals = $this->make_request($url,null);		
190
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
191
		if(!empty($myactions)) {
192
			foreach ($myactions['actions'] as $key => $value) {
193
				if($value['UserAction']['action'] == 'like'){
194
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
195
				}else{
196
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
197
				}
198
			}
199
		}
200
		$storeicons = Configure::read('storeicons');
201
		$this->loadModel('Campaign');
202
		$campaigns = $this->Campaign->getActiveCampaigns();	
203
		print $storeicons;
204
		$rows = sizeof($categorydeals);
205
		if($rows>=1){
206
			$this->set('deals',$categorydeals);
207
			$this->set('likedDeals',$likedDeals);
208
			$this->set('disLikedDeals',$disLikedDeals);
209
			$this->set('storeicons',$storeicons);
210
			$this->set('campaigns',$campaigns);
211
			$this->render('categorydeals');
212
		}else{
213
			foreach ($categorydeals as $key => $dealarr) {
214
				foreach ($dealarr as $key => $deal) {
215
					$deals[] = $deal[0];
216
				}				
217
			}
218
			$this->set(compact('deals','likedDeals','disLikedDeals','storeicons','campaigns'));
219
		}		
220
	}*/
221
}