Subversion Repositories SmartDukaan

Rev

Rev 15403 | Details | Compare with Previous | 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
		}
15839 manish.sha 77
		$showCategories = True;
78
		if($urlpage ==1){
79
			$showCategories = True;
80
		}else{
81
			$showCategories = False;
82
		}
15403 manish.sha 83
		$url = $this->getDealsApiUrl($urlpage,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands);
84
		// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
85
 
86
		$deals = $this->make_request($url,null);
87
		$this->loadModel('Api');
88
		// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
89
		// $deals = $apideals['products'];
90
 
91
 
92
	  	$storeicons = Configure::read('storeicons');
93
 
15839 manish.sha 94
		$this->set(compact('page', 'subpage', 'title_for_layout', 'description', 'deals','campaigns','id','sort','direction','storeicons','showCategories'));
15403 manish.sha 95
		try {
96
			$this->render(implode('/', $path));
97
		} catch (MissingViewException $e) {
98
			if (Configure::read('debug')) {
99
				throw $e;
100
			}
101
			throw new NotFoundException();
102
		}
103
	}
15839 manish.sha 104
 
105
	public function about() {
106
	}
107
 
108
	public function faq() {
109
	}
15403 manish.sha 110
	/*
111
	public function display() {
112
		$page = $this->request->query('page');
113
		if(!isset($page)){
114
			$page = 1;
115
		}
116
		if($this->request->is('ajax')){
117
			$this->layout = 'ajax';
118
		}
119
		$path = func_get_args();
120
 
121
		$count = count($path);
122
		if (!$count) {
123
			return $this->redirect('/');
124
		}
125
		$page = $subpage = $title_for_layout = null;
126
 
127
		if (!empty($path[0])) {
128
			$page = $path[0];
129
		}
130
		if (!empty($path[1])) {
131
			$subpage = $path[1];
132
		}
133
		if (!empty($path[$count - 1])) {
134
			$title_for_layout = Inflector::humanize($path[$count - 1]);
135
		}
136
		$title_for_layout = "Amazing Deals on the Go";
137
		$description = "Get cashback on your favourite products.Mouth watering deals";
138
		$apideals = $this->Api->getDeals();
139
 
140
		$userId = 1;
141
		if(isset($userId) && !empty($userId)){
142
			$this->loadModel('User');
143
			$dbuser = $this->User->findById($userId);
144
			$this->Auth->login($dbuser['User']);	
145
		}
146
		$likedDeals = $disLikedDeals = array();
147
		// $this->loadModel('Api');
148
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
149
		// $categorydeals = $apideals['products'];
150
		$page = $this->request->query('page');
151
		if(!isset($page)){
152
			$page = 1;
153
		}
154
		$offset = ($page - 1) * $this->limit;
155
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
156
		$deals = $this->make_request($url,null);		
157
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
158
		if(!empty($myactions)) {
159
			foreach ($myactions['actions'] as $key => $value) {
160
				if($value['UserAction']['action'] == 'like'){
161
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
162
				}else{
163
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
164
				}
165
			}
166
		}
167
		$storeicons = Configure::read('storeicons');
168
		$this->loadModel('Campaign');
169
		$campaigns = $this->Campaign->getActiveCampaigns();	
170
 
171
		$this->set(compact('page', 'subpage', 'title_for_layout', 'description','deals','likedDeals','disLikedDeals','storeicons','campaigns'));
172
 
173
		try {
174
			$this->render(implode('/', $path));
175
		} catch (MissingViewException $e) {
176
			if (Configure::read('debug')) {
177
				throw $e;
178
			}
179
			throw new NotFoundException();
180
		}
181
	}
182
 
183
	public function deals(){
184
		$userId = 1;
185
		if(isset($userId) && !empty($userId)){
186
			$this->loadModel('User');
187
			$dbuser = $this->User->findById($userId);
188
			$this->Auth->login($dbuser['User']);	
189
		}
190
		$likedDeals = $disLikedDeals = array();
191
		// $this->loadModel('Api');
192
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
193
		// $categorydeals = $apideals['products'];
194
		$page = $this->request->query('page');
195
		if(!isset($page)){
196
			$page = 1;
197
		}
198
		$offset = ($page - 1) * $this->limit;
199
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
200
		$deals = $this->make_request($url,null);		
201
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
202
		if(!empty($myactions)) {
203
			foreach ($myactions['actions'] as $key => $value) {
204
				if($value['UserAction']['action'] == 'like'){
205
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
206
				}else{
207
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
208
				}
209
			}
210
		}
211
		$storeicons = Configure::read('storeicons');
212
		$this->loadModel('Campaign');
213
		$campaigns = $this->Campaign->getActiveCampaigns();	
214
		print $storeicons;
215
		$rows = sizeof($categorydeals);
216
		if($rows>=1){
217
			$this->set('deals',$categorydeals);
218
			$this->set('likedDeals',$likedDeals);
219
			$this->set('disLikedDeals',$disLikedDeals);
220
			$this->set('storeicons',$storeicons);
221
			$this->set('campaigns',$campaigns);
222
			$this->render('categorydeals');
223
		}else{
224
			foreach ($categorydeals as $key => $dealarr) {
225
				foreach ($dealarr as $key => $deal) {
226
					$deals[] = $deal[0];
227
				}				
228
			}
229
			$this->set(compact('deals','likedDeals','disLikedDeals','storeicons','campaigns'));
230
		}		
231
	}*/
232
}