Subversion Repositories SmartDukaan

Rev

Rev 16842 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16628 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * UserAppInstalls Controller
5
 *
6
 * @property UserAppInstall $UserAppInstall
7
 * @property PaginatorComponent $Paginator
8
 */
9
class UserAppInstallsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
/**
19
 * admin_index method
20
 *
21
 * @return void
22
 */
23
	public function admin_index() {
24
		$this->UserAppInstall->recursive = 0;
25
		$this->set('userAppInstalls', $this->Paginator->paginate());
26
	}
27
 
28
/**
29
 * admin_view method
30
 *
31
 * @throws NotFoundException
32
 * @param string $id
33
 * @return void
34
 */
35
	public function admin_view($id = null) {
36
		if (!$this->UserAppInstall->exists($id)) {
37
			throw new NotFoundException(__('Invalid user app install'));
38
		}
39
		$options = array('conditions' => array('UserAppInstall.' . $this->UserAppInstall->primaryKey => $id));
40
		$this->set('userAppInstall', $this->UserAppInstall->find('first', $options));
41
	}
42
 
43
/**
44
 * admin_add method
45
 *
46
 * @return void
47
 */
48
	public function admin_add() {
49
		if ($this->request->is('post')) {
50
			$this->UserAppInstall->create();
51
			if ($this->UserAppInstall->save($this->request->data)) {
52
				$this->Session->setFlash(__('The user app install has been saved.'));
53
				return $this->redirect(array('action' => 'index'));
54
			} else {
55
				$this->Session->setFlash(__('The user app install could not be saved. Please, try again.'));
56
			}
57
		}
58
	}
59
 
60
/**
61
 * admin_edit method
62
 *
63
 * @throws NotFoundException
64
 * @param string $id
65
 * @return void
66
 */
67
	public function admin_edit($id = null) {
68
		if (!$this->UserAppInstall->exists($id)) {
69
			throw new NotFoundException(__('Invalid user app install'));
70
		}
71
		if ($this->request->is(array('post', 'put'))) {
72
			if ($this->UserAppInstall->save($this->request->data)) {
73
				$this->Session->setFlash(__('The user app install has been saved.'));
74
				return $this->redirect(array('action' => 'index'));
75
			} else {
76
				$this->Session->setFlash(__('The user app install could not be saved. Please, try again.'));
77
			}
78
		} else {
79
			$options = array('conditions' => array('UserAppInstall.' . $this->UserAppInstall->primaryKey => $id));
80
			$this->request->data = $this->UserAppInstall->find('first', $options);
81
		}
82
	}
83
 
84
/**
85
 * admin_delete method
86
 *
87
 * @throws NotFoundException
88
 * @param string $id
89
 * @return void
90
 */
91
	public function admin_delete($id = null) {
92
		$this->UserAppInstall->id = $id;
93
		if (!$this->UserAppInstall->exists()) {
94
			throw new NotFoundException(__('Invalid user app install'));
95
		}
96
		$this->request->onlyAllow('post', 'delete');
97
		if ($this->UserAppInstall->delete()) {
98
			$this->Session->setFlash(__('The user app install has been deleted.'));
99
		} else {
100
			$this->Session->setFlash(__('The user app install could not be deleted. Please, try again.'));
101
		}
102
		return $this->redirect(array('action' => 'index'));
103
	}
104
 
105
	public function getDateInstalls($date) {
16840 naman 106
		// $conditions = array('user_id'=>$this->Auth->User('id'),'transaction_date'=>$date);
107
		// $fields = array('app_name','sum(installCount) AS installs','sum(payoutAmount) AS amount');
108
		// $installs = $this->UserAppInstall->find('all',array('fields'=>$fields,'conditions'=>$conditions,'group'=>'app_id'));
109
		// if(!empty($installs)){
110
		// 	foreach ($installs as $key => $value) {
111
		// 		$result[$value['UserAppInstall']['app_name']] = $value[0];
112
		// 	}
113
		// 	$response = array('installs' => $result,'success'=>true);
114
		// }else{
115
		// 	$response = array('installs' => null,'success'=>false);
116
		// }		
117
		// $this->response->type('json');
118
		// $this->layout = 'ajax';
119
		// $this->set(array(
120
		//     'result' => $response,
121
		//     // 'callback' => $callback,
122
		//     '_serialize' => array('result')
123
		// ));
124
		// $this->render('/Elements/json');	
125
		$this->autoRender = false;	
126
		$this->request->onlyAllow('ajax');
16842 anikendra 127
		$url = $this->apihost.'appUserBatchDateDrillDown/'.$this->Auth->User('id').'/'.$date;
16840 naman 128
		$getApp = $this->make_request($url,null);
129
		return json_encode($getApp);	
16628 anikendra 130
	}
17351 naman 131
 
132
	public function getDateInstallsBy($date, $user_id){
133
 
134
		$this->autoRender = false;	
135
		$this->request->onlyAllow('ajax');
136
		$url = $this->apihost.'appUserBatchDateDrillDown/'.$user_id.'/'.$date;
137
		$getApp = $this->make_request($url,null);
138
		return json_encode($getApp);	
139
	}
16628 anikendra 140
}