| 14776 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Pushnotifications Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Pushnotification $Pushnotification
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class PushnotificationsController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
|
|
17 |
|
| 14778 |
anikendra |
18 |
public function beforeFilter() {
|
|
|
19 |
parent::beforeFilter();
|
|
|
20 |
$this->Auth->allow('add');
|
|
|
21 |
}
|
| 14776 |
anikendra |
22 |
/**
|
|
|
23 |
* index method
|
|
|
24 |
*
|
|
|
25 |
* @return void
|
|
|
26 |
*/
|
|
|
27 |
public function index() {
|
|
|
28 |
$this->Pushnotification->recursive = 0;
|
|
|
29 |
$this->set('pushnotifications', $this->Paginator->paginate());
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* view method
|
|
|
34 |
*
|
|
|
35 |
* @throws NotFoundException
|
|
|
36 |
* @param string $id
|
|
|
37 |
* @return void
|
|
|
38 |
*/
|
|
|
39 |
public function view($id = null) {
|
|
|
40 |
if (!$this->Pushnotification->exists($id)) {
|
|
|
41 |
throw new NotFoundException(__('Invalid pushnotification'));
|
|
|
42 |
}
|
|
|
43 |
$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
|
|
|
44 |
$this->set('pushnotification', $this->Pushnotification->find('first', $options));
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* add method
|
|
|
49 |
*
|
|
|
50 |
* @return void
|
|
|
51 |
*/
|
|
|
52 |
public function add() {
|
|
|
53 |
if ($this->request->is('post')) {
|
| 14778 |
anikendra |
54 |
$this->log(print_r($this->request->data,1),'pushnotifications');
|
| 14783 |
anikendra |
55 |
$data = $this->request->data;
|
|
|
56 |
$data['type'] = $data['result'];
|
|
|
57 |
$data['status'] = 1;
|
| 14786 |
anikendra |
58 |
$data['response_time'] = date('Y-m-d H:i:s',strtotime($data['timestamp']));
|
| 14783 |
anikendra |
59 |
$data['notification_campaign_id'] = $data['cid'];
|
|
|
60 |
unset($data['result']);
|
|
|
61 |
unset($data['cid']);
|
| 14784 |
anikendra |
62 |
unset($data['timestamp']);
|
| 14786 |
anikendra |
63 |
if(empty($data['user_id'])){
|
|
|
64 |
unset($data['user_id']);
|
|
|
65 |
}
|
| 14784 |
anikendra |
66 |
$this->log(print_r($data,1),'pushnotifications');
|
| 14776 |
anikendra |
67 |
$this->Pushnotification->create();
|
| 14783 |
anikendra |
68 |
if ($this->Pushnotification->save($data)) {
|
|
|
69 |
// $this->Session->setFlash(__('The pushnotification has been saved.'));
|
|
|
70 |
// return $this->redirect(array('action' => 'index'));
|
|
|
71 |
$result = array('success' => true,'message'=>'The pushnotification has been saved.');
|
| 14776 |
anikendra |
72 |
} else {
|
| 14783 |
anikendra |
73 |
$result = array('success' => false,'message'=>'The pushnotification could not be saved. Please, try again.');
|
|
|
74 |
// $this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
|
| 14776 |
anikendra |
75 |
}
|
|
|
76 |
}
|
| 14783 |
anikendra |
77 |
$this->set(array(
|
|
|
78 |
'result' => $result,
|
|
|
79 |
'_serialize' => array('result')
|
|
|
80 |
));
|
|
|
81 |
$this->render('/Elements/json');
|
| 14776 |
anikendra |
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* edit method
|
|
|
86 |
*
|
|
|
87 |
* @throws NotFoundException
|
|
|
88 |
* @param string $id
|
|
|
89 |
* @return void
|
|
|
90 |
*/
|
|
|
91 |
public function edit($id = null) {
|
|
|
92 |
if (!$this->Pushnotification->exists($id)) {
|
|
|
93 |
throw new NotFoundException(__('Invalid pushnotification'));
|
|
|
94 |
}
|
|
|
95 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
96 |
if ($this->Pushnotification->save($this->request->data)) {
|
|
|
97 |
$this->Session->setFlash(__('The pushnotification has been saved.'));
|
|
|
98 |
return $this->redirect(array('action' => 'index'));
|
|
|
99 |
} else {
|
|
|
100 |
$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
|
|
|
101 |
}
|
|
|
102 |
} else {
|
|
|
103 |
$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
|
|
|
104 |
$this->request->data = $this->Pushnotification->find('first', $options);
|
|
|
105 |
}
|
|
|
106 |
$users = $this->Pushnotification->User->find('list');
|
|
|
107 |
$this->set(compact('users'));
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* delete method
|
|
|
112 |
*
|
|
|
113 |
* @throws NotFoundException
|
|
|
114 |
* @param string $id
|
|
|
115 |
* @return void
|
|
|
116 |
*/
|
|
|
117 |
public function delete($id = null) {
|
|
|
118 |
$this->Pushnotification->id = $id;
|
|
|
119 |
if (!$this->Pushnotification->exists()) {
|
|
|
120 |
throw new NotFoundException(__('Invalid pushnotification'));
|
|
|
121 |
}
|
|
|
122 |
$this->request->onlyAllow('post', 'delete');
|
|
|
123 |
if ($this->Pushnotification->delete()) {
|
|
|
124 |
$this->Session->setFlash(__('The pushnotification has been deleted.'));
|
|
|
125 |
} else {
|
|
|
126 |
$this->Session->setFlash(__('The pushnotification could not be deleted. Please, try again.'));
|
|
|
127 |
}
|
|
|
128 |
return $this->redirect(array('action' => 'index'));
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/**
|
|
|
132 |
* admin_index method
|
|
|
133 |
*
|
|
|
134 |
* @return void
|
|
|
135 |
*/
|
|
|
136 |
public function admin_index() {
|
|
|
137 |
$this->Pushnotification->recursive = 0;
|
|
|
138 |
$this->set('pushnotifications', $this->Paginator->paginate());
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
* admin_view method
|
|
|
143 |
*
|
|
|
144 |
* @throws NotFoundException
|
|
|
145 |
* @param string $id
|
|
|
146 |
* @return void
|
|
|
147 |
*/
|
|
|
148 |
public function admin_view($id = null) {
|
|
|
149 |
if (!$this->Pushnotification->exists($id)) {
|
|
|
150 |
throw new NotFoundException(__('Invalid pushnotification'));
|
|
|
151 |
}
|
|
|
152 |
$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
|
|
|
153 |
$this->set('pushnotification', $this->Pushnotification->find('first', $options));
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
/**
|
|
|
157 |
* admin_add method
|
|
|
158 |
*
|
|
|
159 |
* @return void
|
|
|
160 |
*/
|
|
|
161 |
public function admin_add() {
|
|
|
162 |
if ($this->request->is('post')) {
|
|
|
163 |
$this->Pushnotification->create();
|
|
|
164 |
if ($this->Pushnotification->save($this->request->data)) {
|
|
|
165 |
$this->Session->setFlash(__('The pushnotification has been saved.'));
|
|
|
166 |
return $this->redirect(array('action' => 'index'));
|
|
|
167 |
} else {
|
|
|
168 |
$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
$users = $this->Pushnotification->User->find('list');
|
|
|
172 |
$this->set(compact('users'));
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
/**
|
|
|
176 |
* admin_edit method
|
|
|
177 |
*
|
|
|
178 |
* @throws NotFoundException
|
|
|
179 |
* @param string $id
|
|
|
180 |
* @return void
|
|
|
181 |
*/
|
|
|
182 |
public function admin_edit($id = null) {
|
|
|
183 |
if (!$this->Pushnotification->exists($id)) {
|
|
|
184 |
throw new NotFoundException(__('Invalid pushnotification'));
|
|
|
185 |
}
|
|
|
186 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
187 |
if ($this->Pushnotification->save($this->request->data)) {
|
|
|
188 |
$this->Session->setFlash(__('The pushnotification has been saved.'));
|
|
|
189 |
return $this->redirect(array('action' => 'index'));
|
|
|
190 |
} else {
|
|
|
191 |
$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
|
|
|
192 |
}
|
|
|
193 |
} else {
|
|
|
194 |
$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
|
|
|
195 |
$this->request->data = $this->Pushnotification->find('first', $options);
|
|
|
196 |
}
|
|
|
197 |
$users = $this->Pushnotification->User->find('list');
|
|
|
198 |
$this->set(compact('users'));
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
/**
|
|
|
202 |
* admin_delete method
|
|
|
203 |
*
|
|
|
204 |
* @throws NotFoundException
|
|
|
205 |
* @param string $id
|
|
|
206 |
* @return void
|
|
|
207 |
*/
|
|
|
208 |
public function admin_delete($id = null) {
|
|
|
209 |
$this->Pushnotification->id = $id;
|
|
|
210 |
if (!$this->Pushnotification->exists()) {
|
|
|
211 |
throw new NotFoundException(__('Invalid pushnotification'));
|
|
|
212 |
}
|
|
|
213 |
$this->request->onlyAllow('post', 'delete');
|
|
|
214 |
if ($this->Pushnotification->delete()) {
|
|
|
215 |
$this->Session->setFlash(__('The pushnotification has been deleted.'));
|
|
|
216 |
} else {
|
|
|
217 |
$this->Session->setFlash(__('The pushnotification could not be deleted. Please, try again.'));
|
|
|
218 |
}
|
|
|
219 |
return $this->redirect(array('action' => 'index'));
|
|
|
220 |
}}
|