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