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