Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
16773 manas 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * AppTransactions Controller
5
 *
6
 * @property AppTransaction $AppTransaction
7
 * @property PaginatorComponent $Paginator
8
 */
9
class AppTransactionsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter()
19
    {
20
       parent::beforeFilter();
21
       $this->Paginator->settings=array(
22
              'limit'=>100
23
       );
24
    } 
25
/**
26
 * index method
27
 *
28
 * @return void
29
 */
30
	public function index() {
31
		$this->AppTransaction->recursive = 0;
32
		$this->set('appTransactions', $this->Paginator->paginate());
33
	}
34
 
35
/**
36
 * view method
37
 *
38
 * @throws NotFoundException
39
 * @param string $id
40
 * @return void
41
 */
42
	public function view($id = null) {
43
		if (!$this->AppTransaction->exists($id)) {
44
			throw new NotFoundException(__('Invalid app transaction'));
45
		}
46
		$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
47
		$this->set('appTransaction', $this->AppTransaction->find('first', $options));
48
	}
49
 
50
/**
51
 * add method
52
 *
53
 * @return void
54
 */
55
	public function add() {
56
		if ($this->request->is('post')) {
57
			$this->AppTransaction->create();
58
			if ($this->AppTransaction->save($this->request->data)) {
59
				$this->Session->setFlash(__('The app transaction has been saved.'));
60
				return $this->redirect(array('action' => 'index'));
61
			} else {
62
				$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
63
			}
64
		}
65
	}
66
 
67
/**
68
 * edit method
69
 *
70
 * @throws NotFoundException
71
 * @param string $id
72
 * @return void
73
 */
74
	public function edit($id = null) {
75
		if (!$this->AppTransaction->exists($id)) {
76
			throw new NotFoundException(__('Invalid app transaction'));
77
		}
78
		if ($this->request->is(array('post', 'put'))) {
79
			if ($this->AppTransaction->save($this->request->data)) {
80
				$this->Session->setFlash(__('The app transaction has been saved.'));
81
				return $this->redirect(array('action' => 'index'));
82
			} else {
83
				$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
84
			}
85
		} else {
86
			$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
87
			$this->request->data = $this->AppTransaction->find('first', $options);
88
		}
89
	}
90
 
91
/**
92
 * delete method
93
 *
94
 * @throws NotFoundException
95
 * @param string $id
96
 * @return void
97
 */
98
	public function delete($id = null) {
99
		$this->AppTransaction->id = $id;
100
		if (!$this->AppTransaction->exists()) {
101
			throw new NotFoundException(__('Invalid app transaction'));
102
		}
103
		$this->request->onlyAllow('post', 'delete');
104
		if ($this->AppTransaction->delete()) {
105
			$this->Session->setFlash(__('The app transaction has been deleted.'));
106
		} else {
107
			$this->Session->setFlash(__('The app transaction could not be deleted. Please, try again.'));
108
		}
109
		return $this->redirect(array('action' => 'index'));
110
	}
111
 
112
/**
113
 * admin_index method
114
 *
115
 * @return void
116
 */
117
	public function admin_index() {
118
		$this->AppTransaction->recursive = 0;
119
		$this->set('appTransactions', $this->Paginator->paginate(array('AppTransaction.' . $this->AppTransaction.'payout_description'=>'Approved')));
120
	}
121
 
122
/**
123
 * admin_view method
124
 *
125
 * @throws NotFoundException
126
 * @param string $id
127
 * @return void
128
 */
129
	public function admin_view($id = null) {
130
		if (!$this->AppTransaction->exists($id)) {
131
			throw new NotFoundException(__('Invalid app transaction'));
132
		}
133
		$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
134
		$this->set('appTransaction', $this->AppTransaction->find('first', $options));
135
	}
136
 
137
/**
138
 * admin_add method
139
 *
140
 * @return void
141
 */
142
	public function admin_add() {
143
		if ($this->request->is('post')) {
144
			$this->AppTransaction->create();
145
			if ($this->AppTransaction->save($this->request->data)) {
146
				$this->Session->setFlash(__('The app transaction has been saved.'));
147
				return $this->redirect(array('action' => 'index'));
148
			} else {
149
				$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
150
			}
151
		}
152
	}
153
 
154
/**
155
 * admin_edit method
156
 *
157
 * @throws NotFoundException
158
 * @param string $id
159
 * @return void
160
 */
161
	public function admin_edit($id = null) {
162
		if (!$this->AppTransaction->exists($id)) {
163
			throw new NotFoundException(__('Invalid app transaction'));
164
		}
165
		if ($this->request->is(array('post', 'put'))) {
166
			if ($this->AppTransaction->save($this->request->data)) {
167
				$this->Session->setFlash(__('The app transaction has been saved.'));
168
				return $this->redirect(array('action' => 'index'));
169
			} else {
170
				$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
171
			}
172
		} else {
173
			$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
174
			$this->request->data = $this->AppTransaction->find('first', $options);
175
		}
176
	}
177
 
178
/**
179
 * admin_delete method
180
 *
181
 * @throws NotFoundException
182
 * @param string $id
183
 * @return void
184
 */
185
	public function admin_delete($id = null) {
186
		$this->AppTransaction->id = $id;
187
		if (!$this->AppTransaction->exists()) {
188
			throw new NotFoundException(__('Invalid app transaction'));
189
		}
190
		$this->request->onlyAllow('post', 'delete');
191
		if ($this->AppTransaction->delete()) {
192
			$this->Session->setFlash(__('The app transaction has been deleted.'));
193
		} else {
194
			$this->Session->setFlash(__('The app transaction could not be deleted. Please, try again.'));
195
		}
196
		return $this->redirect(array('action' => 'index'));
197
	}
198
 
16811 manas 199
	public function admin_appwise(){
16773 manas 200
		$this->AppTransaction->recursive = -1;
16811 manas 201
		$type = $this->request->query('date');
202
		$date_from = $this->request->query('date_from');
203
		$date_to = $this->request->query('date_to');
204
		if(!isset($type) && !isset($date_from) && !isset($date_to)){
205
			$date = date('Y-m-d',time());		
206
			$this->Paginator->settings = array(
16773 manas 207
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
16811 manas 208
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
16873 manas 209
    	   'limit' => $this->AppTransaction->find('count',array('group'=>'app_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
16811 manas 210
	    	'order' => 'count desc' ,
16773 manas 211
	    	'group' => 'app_id'
16811 manas 212
	  		);
213
		  	$approvedCounts =  $this->Paginator->paginate();
214
		  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
215
		  	$approved = $this->AppTransaction->query($sql);
216
		  	foreach ($approved as $key => $value1) {
217
		  		$app_id=$value1['app_transactions']['app_id'];
218
		  		$value22=$value1['0']['count(1)'];
219
		  		foreach ($approvedCounts as $key2 => $value) {
220
					if($app_id==$value['AppTransaction']['app_id']){
221
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
222
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
223
					}
224
				}
16773 manas 225
			}
226
		}
16811 manas 227
		else if($type=='yesterday'){
228
			$date = date('Y-m-d',time()-86400);		
229
			$this->Paginator->settings = array(
230
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
231
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
16873 manas 232
	    	'limit' => $this->AppTransaction->find('count',array('group'=>'app_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
16811 manas 233
	    	'order' => 'count desc' ,
234
	    	'group' => 'app_id'
235
	  		);
236
		  	$approvedCounts =  $this->Paginator->paginate();
237
		  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
238
		  	$approved = $this->AppTransaction->query($sql);
239
		  	foreach ($approved as $key => $value1) {
240
		  		$app_id=$value1['app_transactions']['app_id'];
241
		  		$value22=$value1['0']['count(1)'];
242
		  		foreach ($approvedCounts as $key2 => $value) {
243
					if($app_id==$value['AppTransaction']['app_id']){
244
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
245
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
246
					}
247
				}
248
			}	
249
		}else if(isset($date_from) && isset($date_to)){
250
			$this->Paginator->settings = array(
251
			'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
252
	    	'conditions' => array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>array($date_from, $date_to)),
16873 manas 253
	    	'limit'=> $this->AppTransaction->find(
254
	    	'count',array('group'=>'app_id','conditions' => 
255
	    		array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>
256
	    			array($date_from, $date_to)))),
16811 manas 257
	    	'order' => 'count desc' ,
258
	    	'group' => 'app_id'
259
	  		);
260
		  	$approvedCounts =  $this->Paginator->paginate();
261
		  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time) BETWEEN '$date_from' and '$date_to' and payout_description='Approved' group by app_id";
262
		  	$approved = $this->AppTransaction->query($sql);
263
		  	foreach ($approved as $key => $value1) {
264
		  		$app_id=$value1['app_transactions']['app_id'];
265
		  		$value22=$value1['0']['count(1)'];
266
		  		foreach ($approvedCounts as $key2 => $value) {
267
					if($app_id==$value['AppTransaction']['app_id']){
268
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
269
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
270
					}
271
				}
272
			}		
273
		}else{
274
			$date = date('Y-m-d',time());		
275
			$this->Paginator->settings = array(
276
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
277
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
16873 manas 278
    	    'limit' => $this->AppTransaction->find('count',array('group'=>'app_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
16811 manas 279
	    	'order' => 'count desc' ,
280
	    	'group' => 'app_id'
281
	  		);
282
		  	$approvedCounts =  $this->Paginator->paginate();
283
		  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
284
		  	$approved = $this->AppTransaction->query($sql);
285
		  	foreach ($approved as $key => $value1) {
286
		  		$app_id=$value1['app_transactions']['app_id'];
287
		  		$value22=$value1['0']['count(1)'];
288
		  		foreach ($approvedCounts as $key2 => $value) {
289
					if($app_id==$value['AppTransaction']['app_id']){
290
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
291
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
292
					}
293
				}
294
			}
295
		}
16813 manas 296
	$totalClicks=0;	
297
	$totalApproved=0;
298
	foreach ($approvedCounts as $key => $value) {
299
		$totalClicks+=$value[0]['count'];
300
		if(!(isset($value['AppTransaction']['approved']))){
301
			$totalApproved+=0;
302
		}else{
303
			$totalApproved+=$value['AppTransaction']['approved'];
304
		}
16811 manas 305
	}
16873 manas 306
$url=$_SERVER['REQUEST_URI'];
307
	if (strpos($url,'sort') == false) {
308
 
309
	}else{
310
	$new1=explode("/sort:", $url);
311
	$new2=explode("/direction:", $new1[1]);
312
	$new2=explode("/direction:", $new1[1]);
313
	$sortType=$new2[0];
314
	if (strpos($new2[1],'page') == false) {
315
		$sortDirection=$new2[1];
316
	}else{
317
		$new3=explode("/page:", $new2[1]);
318
		$sortDirection=$new3[0];
319
	}
320
	if (strpos($new2[1],'date') == false) {
321
		$sortDirection=$new2[1];
322
	}else{
323
		$new3=explode("?date", $new2[1]);
324
		$sortDirection=$new3[0];
325
	}
326
	if($sortType=='approved' && $sortDirection=='desc'){
327
		$newApprovedCount = array();
328
		foreach ($approvedCounts as $key => $row)
329
		{
330
			if(!(isset($row['AppTransaction']['approved']))){
331
			$newApprovedCount[$key]['AppTransaction']['approved']=0;	
332
			}else{
333
		    $newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
334
		    }
335
		}
336
		array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
337
	}
338
	else if($sortType=='approved' && $sortDirection=='asc'){
339
			$newApprovedCount = array();
340
			foreach ($approvedCounts as $key => $row)
341
			{
342
				if(!(isset($row['AppTransaction']['approved']))){
343
				$newApprovedCount[$key]['AppTransaction']['approved']=0;	
344
				}else{
345
			    $newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
346
			    }
347
			}
348
			array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
349
	}
350
	else if($sortType=='conversion_percentage' && $sortDirection=='desc'){
351
		$newApprovedCount = array();
352
		foreach ($approvedCounts as $key => $row)
353
		{
354
			if(!(isset($row['AppTransaction']['conversion_percentage']))){
355
			$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;	
356
			}else{
357
		    $newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
358
		    }
359
		}
360
		array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
361
	}
362
	else if($sortType=='conversion_percentage' && $sortDirection=='asc'){
363
		$newApprovedCount = array();
364
		foreach ($approvedCounts as $key => $row)
365
		{
366
			if(!(isset($row['AppTransaction']['conversion_percentage']))){
367
			$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;	
368
			}else{
369
		    $newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
370
		    }
371
		}
372
		array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
373
	}
374
	else if($sortType=='clicks'&& $sortDirection=='asc'){
375
		$newApprovedCount = array();
376
		foreach ($approvedCounts as $key => $row){
377
		    $newApprovedCount[$key][0]['count'] = $row[0]['count'];
378
		}
379
		array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
380
	}
381
	else if($sortType=='clicks'&& $sortDirection=='desc'){
382
		$newApprovedCount = array();
383
		foreach ($approvedCounts as $key => $row){
384
		    $newApprovedCount[$key][0]['count'] = $row[0]['count'];
385
			}
386
		array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
387
		}
388
	}	
389
 
390
 
16813 manas 391
	$this->set('appTransactions', $approvedCounts);
392
	$this->set('totalClicks', $totalClicks);
393
	$this->set('totalApproved', $totalApproved);
394
}
16773 manas 395
 
16811 manas 396
	public function admin_retailer(){
397
		$this->AppTransaction->recursive = -1;
398
		$type = $this->request->query('date');
399
		$date_from = $this->request->query('date_from');
400
		$date_to = $this->request->query('date_to');
401
		if(!isset($type) && !isset($date_from) && !isset($date_to)){
402
			$date = date('Y-m-d',time());		
403
			$this->Paginator->settings = array(
16873 manas 404
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 
405
	    	'COUNT(*) AS count'),
16811 manas 406
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
16873 manas 407
	    	'limit' => $this->AppTransaction->find('count',array('group'=>'retailer_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
408
	    	'order' => 'count desc',
16811 manas 409
	    	'group' => 'retailer_id'
410
	  		);
411
		  	$approvedCounts =  $this->Paginator->paginate();
412
		  	$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
413
		  	$approved = $this->AppTransaction->query($sql);
414
		  	foreach ($approved as $key => $value1) {
415
		  		$app_id=$value1['app_transactions']['retailer_id'];
416
		  		$value22=$value1['0']['count(1)'];
417
		  		foreach ($approvedCounts as $key2 => $value) {
418
					if($app_id==$value['AppTransaction']['retailer_id']){
419
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
420
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
421
					}
422
				}
423
			}
424
		}
425
		else if($type=='yesterday'){
426
			$date = date('Y-m-d',time()-86400);		
427
			$this->Paginator->settings = array(
428
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
429
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
16873 manas 430
	    	'limit' => $this->AppTransaction->find('count',array('group'=>'retailer_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
431
	    	'order' => 'count desc',
16811 manas 432
	    	'group' => 'retailer_id'
433
	  		);
434
		  	$approvedCounts =  $this->Paginator->paginate();
435
		  	$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
436
		  	$approved = $this->AppTransaction->query($sql);
437
		  	foreach ($approved as $key => $value1) {
438
		  		$app_id=$value1['app_transactions']['retailer_id'];
439
		  		$value22=$value1['0']['count(1)'];
440
		  		foreach ($approvedCounts as $key2 => $value) {
441
					if($app_id==$value['AppTransaction']['retailer_id']){
442
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
443
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
444
					}
445
				}
446
			}	
447
		}else if(isset($date_from) && isset($date_to)){
448
			$this->Paginator->settings = array(
449
			'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
450
	    	'conditions' => array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>array($date_from, $date_to)),
16873 manas 451
	    	'limit'=> $this->AppTransaction->find(
452
	    	'count',array('group'=>'retailer_id','conditions' => 
453
	    		array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>
454
	    			array($date_from, $date_to)))),
16811 manas 455
	    	'order' => 'count desc' ,
456
	    	'group' => 'retailer_id'
457
	  		);
458
		  	$approvedCounts =  $this->Paginator->paginate();
459
		  	$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time) BETWEEN '$date_from' and '$date_to' and payout_description='Approved' group by retailer_id";
460
		  	$approved = $this->AppTransaction->query($sql);
461
		  	foreach ($approved as $key => $value1) {
462
		  		$app_id=$value1['app_transactions']['retailer_id'];
463
		  		$value22=$value1['0']['count(1)'];
464
		  		foreach ($approvedCounts as $key2 => $value) {
465
					if($app_id==$value['AppTransaction']['retailer_id']){
466
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
467
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
468
					}
469
				}
470
			}		
471
		}else{
472
			$date = date('Y-m-d',time());		
473
			$this->Paginator->settings = array(
474
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
475
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
16873 manas 476
	    	'limit' => $this->AppTransaction->find('count',array('group'=>'retailer_id','conditions'=>array('Date(AppTransaction.transaction_time)'=>$date))),
16811 manas 477
	    	'order' => 'count desc' ,
478
	    	'group' => 'retailer_id'
479
	  		);
480
		  	$approvedCounts =  $this->Paginator->paginate();
481
		  	$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
482
		  	$approved = $this->AppTransaction->query($sql);
483
		  	foreach ($approved as $key => $value1) {
484
		  		$app_id=$value1['app_transactions']['retailer_id'];
485
		  		$value22=$value1['0']['count(1)'];
486
		  		foreach ($approvedCounts as $key2 => $value) {
487
					if($app_id==$value['AppTransaction']['retailer_id']){
488
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
489
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
490
					}
491
				}
492
			}
493
		}
16813 manas 494
	$totalClicks=0;	
495
	$totalApproved=0;
496
	foreach ($approvedCounts as $key => $value) {
497
		$totalClicks+=$value[0]['count'];
498
		if(!(isset($value['AppTransaction']['approved']))){
499
			$totalApproved+=0;
500
		}else{
501
			$totalApproved+=$value['AppTransaction']['approved'];
502
		}
16773 manas 503
	}
16873 manas 504
	$url=$_SERVER['REQUEST_URI'];
505
	if (strpos($url,'sort') == false) {
506
 
507
	}else{
508
	$new1=explode("/sort:", $url);
509
	$new2=explode("/direction:", $new1[1]);
510
	$new2=explode("/direction:", $new1[1]);
511
	$sortType=$new2[0];
512
	if (strpos($new2[1],'page') == false) {
513
		$sortDirection=$new2[1];
514
	}else{
515
		$new3=explode("/page:", $new2[1]);
516
		$sortDirection=$new3[0];
517
	}
518
	if (strpos($new2[1],'date') == false) {
519
		$sortDirection=$new2[1];
520
	}else{
521
		$new3=explode("?date", $new2[1]);
522
		$sortDirection=$new3[0];
523
	}
524
	if($sortType=='approved' && $sortDirection=='desc'){
525
		$newApprovedCount = array();
526
		foreach ($approvedCounts as $key => $row)
527
		{
528
			if(!(isset($row['AppTransaction']['approved']))){
529
			$newApprovedCount[$key]['AppTransaction']['approved']=0;	
530
			}else{
531
		    $newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
532
		    }
533
		}
534
		array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
535
	}
536
	else if($sortType=='approved' && $sortDirection=='asc'){
537
			$newApprovedCount = array();
538
			foreach ($approvedCounts as $key => $row)
539
			{
540
				if(!(isset($row['AppTransaction']['approved']))){
541
				$newApprovedCount[$key]['AppTransaction']['approved']=0;	
542
				}else{
543
			    $newApprovedCount[$key]['AppTransaction']['approved'] = $row['AppTransaction']['approved'];
544
			    }
545
			}
546
			array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
547
	}
548
	else if($sortType=='conversion_percentage' && $sortDirection=='desc'){
549
		$newApprovedCount = array();
550
		foreach ($approvedCounts as $key => $row)
551
		{
552
			if(!(isset($row['AppTransaction']['conversion_percentage']))){
553
			$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;	
554
			}else{
555
		    $newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
556
		    }
557
		}
558
		array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
559
	}
560
	else if($sortType=='conversion_percentage' && $sortDirection=='asc'){
561
		$newApprovedCount = array();
562
		foreach ($approvedCounts as $key => $row)
563
		{
564
			if(!(isset($row['AppTransaction']['conversion_percentage']))){
565
			$newApprovedCount[$key]['AppTransaction']['conversion_percentage']=0;	
566
			}else{
567
		    $newApprovedCount[$key]['AppTransaction']['conversion_percentage'] = $row['AppTransaction']['conversion_percentage'];
568
		    }
569
		}
570
		array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
571
	}
572
	else if($sortType=='clicks'&& $sortDirection=='asc'){
573
		$newApprovedCount = array();
574
		foreach ($approvedCounts as $key => $row){
575
		    $newApprovedCount[$key][0]['count'] = $row[0]['count'];
576
		}
577
		array_multisort($newApprovedCount, SORT_ASC, $approvedCounts);
578
	}
579
	else if($sortType=='clicks'&& $sortDirection=='desc'){
580
		$newApprovedCount = array();
581
		foreach ($approvedCounts as $key => $row){
582
		    $newApprovedCount[$key][0]['count'] = $row[0]['count'];
583
			}
584
		array_multisort($newApprovedCount, SORT_DESC, $approvedCounts);
585
		}
586
	}	
16813 manas 587
	$this->set('appTransactions', $approvedCounts);
588
	$this->set('totalClicks', $totalClicks);
589
	$this->set('totalApproved', $totalApproved);
590
	}
16873 manas 591
}
592
 
593
 
594