Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
14954 manas 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * NotificationCampaigns Controller
5
 *
6
 * @property NotificationCampaign $NotificationCampaign
7
 * @property PaginatorComponent $Paginator
8
 */
9
class NotificationCampaignsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
/**
19
 * index method
20
 *
21
 * @return void
22
 */
23
	public function index() {
24
		$this->NotificationCampaign->recursive = 0;
25
		$this->set('notificationCampaigns', $this->Paginator->paginate());
26
	}
27
 
28
/**
29
 * view method
30
 *
31
 * @throws NotFoundException
32
 * @param string $id
33
 * @return void
34
 */
35
	public function view($id = null) {
36
		if (!$this->NotificationCampaign->exists($id)) {
37
			throw new NotFoundException(__('Invalid notification campaign'));
38
		}
39
		$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
40
		$this->set('notificationCampaign', $this->NotificationCampaign->find('first', $options));
41
	}
42
 
43
/**
44
 * add method
45
 *
46
 * @return void
47
 */
48
	public function add() {
49
		if ($this->request->is('post')) {
50
			$this->NotificationCampaign->create();
51
			if ($this->NotificationCampaign->save($this->request->data)) {
52
				$this->Session->setFlash(__('The notification campaign has been saved.'));
53
				return $this->redirect(array('action' => 'index'));
54
			} else {
55
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
56
			}
57
		}
58
	}
59
 
60
/**
61
 * edit method
62
 *
63
 * @throws NotFoundException
64
 * @param string $id
65
 * @return void
66
 */
67
	public function edit($id = null) {
68
		if (!$this->NotificationCampaign->exists($id)) {
69
			throw new NotFoundException(__('Invalid notification campaign'));
70
		}
71
		if ($this->request->is(array('post', 'put'))) {
72
			if ($this->NotificationCampaign->save($this->request->data)) {
73
				$this->Session->setFlash(__('The notification campaign has been saved.'));
74
				return $this->redirect(array('action' => 'index'));
75
			} else {
76
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
77
			}
78
		} else {
79
			$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
80
			$this->request->data = $this->NotificationCampaign->find('first', $options);
81
		}
82
	}
83
 
84
/**
85
 * delete method
86
 *
87
 * @throws NotFoundException
88
 * @param string $id
89
 * @return void
90
 */
91
	public function delete($id = null) {
92
		$this->NotificationCampaign->id = $id;
93
		if (!$this->NotificationCampaign->exists()) {
94
			throw new NotFoundException(__('Invalid notification campaign'));
95
		}
96
		$this->request->onlyAllow('post', 'delete');
97
		if ($this->NotificationCampaign->delete()) {
98
			$this->Session->setFlash(__('The notification campaign has been deleted.'));
99
		} else {
100
			$this->Session->setFlash(__('The notification campaign could not be deleted. Please, try again.'));
101
		}
102
		return $this->redirect(array('action' => 'index'));
103
	}
104
 
105
/**
106
 * admin_index method
107
 *
108
 * @return void
109
 */
110
	public function admin_index() {
111
		$this->NotificationCampaign->recursive = 0;
112
		$this->Paginator->settings = array('order' => array('id'=>'desc'));
113
		$vari = $this->Paginator->paginate();
114
		foreach ($vari as $key => $value) {
115
			$cid=$value['NotificationCampaign']['id'];
116
			$sqlQuery = "SELECT status as status,notification_campaign_id,type,count(*) as count FROM pushnotifications group by notification_campaign_id, type,status";
117
			$resul=$this->NotificationCampaign->query($sqlQuery);	
118
		}
119
		$finalResult = array();
120
		foreach ($resul as $key => $value) {
121
			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['count'];
122
			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['status']]=$value[0]['count'];
123
			//$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['status'];			
124
		}
125
		/*debug($finalResult);*/
126
		$this->set('notificationCampaigns', $vari);
127
		$this->set('notificationCampaignsCount', $finalResult);
128
 
129
	}
130
 
131
/**
132
 * admin_view method
133
 *
134
 * @throws NotFoundException
135
 * @param string $id
136
 * @return void
137
 */
138
	public function admin_view($id = null) {
139
		if (!$this->NotificationCampaign->exists($id)) {
140
			throw new NotFoundException(__('Invalid notification campaign'));
141
		}
142
		$sort = $this->request->query('type');
143
		$direction = $this->request->query('order');
144
		$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
145
		$userData=$this->NotificationCampaign->find('first', $options);
146
		$userActions = array();
147
		foreach ($userData['Pushnotification'] as $key => $value) {
148
			if($value['type']=='sent'){
149
			$userActions[$value['user_id']][$value['type']] = $value['created'];
150
			$userActions[$value['user_id']]['status'] =$value['status'];
151
			}else{
152
				$userActions[$value['user_id']][$value['type']] = $value['response_time'];
153
			}
154
			 //debug($value);
155
		}
156
		$cid=$userData['NotificationCampaign']['id'];
157
		$sqlQuery = "SELECT status as status,notification_campaign_id,type,count(*) as count FROM pushnotifications where notification_campaign_id=$cid group by type,status";
158
		$resul=$this->NotificationCampaign->query($sqlQuery);	
159
		$finalResult = array();
160
		foreach ($resul as $key => $value) {
161
			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['count'];
162
			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['status']]=$value[0]['count'];
163
			//$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['status'];			
164
		}
165
		//debug($finalResult);
166
		$this->set('notificationData', $userData);
167
		$this->set('notificationCampaign', $userActions);
168
		$this->set('notificationCount', $finalResult);
169
	}
170
 
171
/**
172
 * admin_add method
173
 *
174
 * @return void
175
 */
176
	public function admin_add() {
177
		if ($this->request->is('post')) {
178
			$this->NotificationCampaign->create();
179
			if ($this->NotificationCampaign->save($this->request->data)) {
180
				$this->Session->setFlash(__('The notification campaign has been saved.'));
181
				return $this->redirect(array('action' => 'index'));
182
			} else {
183
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
184
			}
185
		}
186
	}
187
 
188
/**
189
 * admin_edit method
190
 *
191
 * @throws NotFoundException
192
 * @param string $id
193
 * @return void
194
 */
195
	public function admin_edit($id = null) {
196
		if (!$this->NotificationCampaign->exists($id)) {
197
			throw new NotFoundException(__('Invalid notification campaign'));
198
		}
199
		if ($this->request->is(array('post', 'put'))) {
200
			if ($this->NotificationCampaign->save($this->request->data)) {
201
				$this->Session->setFlash(__('The notification campaign has been saved.'));
202
				return $this->redirect(array('action' => 'index'));
203
			} else {
204
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
205
			}
206
		} else {
207
			$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
208
			$this->request->data = $this->NotificationCampaign->find('first', $options);
209
		}
210
	}
211
 
212
/**
213
 * admin_delete method
214
 *
215
 * @throws NotFoundException
216
 * @param string $id
217
 * @return void
218
 */
219
	public function admin_delete($id = null) {
220
		$this->NotificationCampaign->id = $id;
221
		if (!$this->NotificationCampaign->exists()) {
222
			throw new NotFoundException(__('Invalid notification campaign'));
223
		}
224
		$this->request->onlyAllow('post', 'delete');
225
		if ($this->NotificationCampaign->delete()) {
226
			$this->Session->setFlash(__('The notification campaign has been deleted.'));
227
		} else {
228
			$this->Session->setFlash(__('The notification campaign could not be deleted. Please, try again.'));
229
		}
230
		return $this->redirect(array('action' => 'index'));
231
	}
232
 
233
	public function admin_show($id = null,$type=null,$status=null) {
234
		$sqlQuery = "SELECT * FROM pushnotifications where notification_campaign_id=$id and type='$type' and status=$status" ;
235
		$resul=$this->NotificationCampaign->query($sqlQuery);
236
 
237
		$sqlQuery1 = "SELECT * FROM notification_campaigns where id=$id" ;
238
		$resultData=$this->NotificationCampaign->query($sqlQuery1);
239
 
240
		$this->set('data', $resul);
241
		$this->set('notificationData', $resultData);
242
		//$resul = $this->Paginator->paginate();
243
		//debug($resultData);
244
	}
245
 
246
	public function admin_user($id = null) {
247
		$sqlQuery = "SELECT * FROM pushnotifications where user_id=$id " ;
248
		$resul=$this->NotificationCampaign->query($sqlQuery);
249
		$this->set('userdata', $resul);
250
		//$this->set('notificationData', $resultData);
251
		//$resul = $this->Paginator->paginate();
252
		//debug($resul);
253
	}
254
	public function admin_sort($id = null) {
255
		$sort = $this->request->query('type');
256
		$direction = $this->request->query('order');
257
		//$cid = $this->request->query('cid');
258
		if($sort=='user_id'){
259
			$sqlQuery = "SELECT * FROM pushnotifications where notification_campaign_id =$id order by $sort $direction" ;			
260
		}
261
		else{
262
			$sqlQuery = "SELECT * FROM pushnotifications where notification_campaign_id =$id order by type='$sort' $direction" ;
263
		}
264
		$resul=$this->NotificationCampaign->query($sqlQuery);
265
		$userActions = array();
266
		foreach ($resul as $key => $value) {
267
			if($value['pushnotifications']['type']=='sent'){
268
			$userActions[$value['pushnotifications']['user_id']][$value['pushnotifications']['type']] = $value['pushnotifications']['created'];
269
			$userActions[$value['pushnotifications']['user_id']]['status'] =$value['pushnotifications']['status'];
270
			}else{
271
				$userActions[$value['pushnotifications']['user_id']][$value['pushnotifications']['type']] = $value['pushnotifications']['response_time'];
272
			}			
273
		}
274
		$this->set('notificationId',$id);
275
		$this->set('sortdata', $userActions);
276
	}
277
 
278
	public function admin_notificationactive(){
279
			$cid = $this->request->query('cid');
280
			$options = array('conditions' => array('id'=> $cid,'expiresAt >'=>date('Y-m-d H:i:s',time())));
281
			$count = $this->NotificationCampaign->find('count',$options);
282
 
283
			if(!$count){
284
				$result = array('success'=>false);
285
			}else{
286
				$result = array('success'=>true);
287
			}
288
 
289
			$this->response->type('json');
290
			$this->layout = 'ajax';
291
			$this->set(array(
292
			    'result' => $response,
293
			    '_serialize' => array('result')
294
			));
295
			$this->render('/Elements/json');
296
		}
297
}