Subversion Repositories SmartDukaan

Rev

Rev 15767 | Rev 19237 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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');
13532 anikendra 55
		if ($this->request->is('post')) {
15508 anikendra 56
			if(empty($this->request->data['user_id']) || empty($this->request->data['gcm_regid'])){
57
				$result = array('success'=>false);
18187 manas 58
				$this->log('error'.print_r($this->request->data,1),'gcm');
13532 anikendra 59
			} else {
15508 anikendra 60
				$dataForModel = $this->request->data;
61
				$this->log('before find '.print_r($dataForModel,1),'gcm');
15767 anikendra 62
				$data = $this->GcmUser->find('first',array('conditions'=>array('user_id'=>$this->request->data['user_id'],'imeinumber'=>$this->request->data['imeinumber']),'order'=>array('id'=>'desc')));
15508 anikendra 63
				$this->log("found row ".print_r($data,1),'gcm');
64
				if(!empty($data)){
65
					$dataForModel['id'] = $data['GcmUser']['id'];
15767 anikendra 66
					$dataForModel['failurecount'] = 0;
15508 anikendra 67
				}else{
68
					$this->GcmUser->create();
69
				}			
70
				$this->log('lets save '.print_r($dataForModel,1),'gcm');
71
				if ($this->GcmUser->save($dataForModel)) {
72
					$result = array('success'=>true);
73
	//				$this->Session->setFlash(__('The gcm user has been saved.'));
74
	//				return $this->redirect(array('action' => 'index'));
75
				} else {
76
					$result = array('success'=>false);
15767 anikendra 77
					$this->log("failure ".print_r($this->GcmUser->validationErrors,1));
15508 anikendra 78
	//				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
79
				}
13532 anikendra 80
			}
81
		}
13698 anikendra 82
		$this->set(array(
83
		    'result' => $result,
84
		    '_serialize' => array('result')
85
		));		
86
		$this->render('/Elements/json');
13532 anikendra 87
	}
88
 
89
/**
90
 * edit method
91
 *
92
 * @throws NotFoundException
93
 * @param string $id
94
 * @return void
95
 */
96
	public function edit($id = null) {
97
		if (!$this->GcmUser->exists($id)) {
98
			throw new NotFoundException(__('Invalid gcm user'));
99
		}
100
		if ($this->request->is(array('post', 'put'))) {
101
			if ($this->GcmUser->save($this->request->data)) {
102
				$this->Session->setFlash(__('The gcm user has been saved.'));
103
				return $this->redirect(array('action' => 'index'));
104
			} else {
105
				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
106
			}
107
		} else {
108
			$options = array('conditions' => array('GcmUser.' . $this->GcmUser->primaryKey => $id));
109
			$this->request->data = $this->GcmUser->find('first', $options);
110
		}
111
	}
112
 
113
/**
114
 * delete method
115
 *
116
 * @throws NotFoundException
117
 * @param string $id
118
 * @return void
119
 */
120
	public function delete($id = null) {
121
		$this->GcmUser->id = $id;
122
		if (!$this->GcmUser->exists()) {
123
			throw new NotFoundException(__('Invalid gcm user'));
124
		}
125
		$this->request->onlyAllow('post', 'delete');
126
		if ($this->GcmUser->delete()) {
127
			$this->Session->setFlash(__('The gcm user has been deleted.'));
128
		} else {
129
			$this->Session->setFlash(__('The gcm user could not be deleted. Please, try again.'));
130
		}
131
		return $this->redirect(array('action' => 'index'));
132
	}
133
 
134
/**
135
 * admin_index method
136
 *
137
 * @return void
138
 */
139
	public function admin_index() {
140
		$this->GcmUser->recursive = 0;
141
		$this->set('gcmUsers', $this->Paginator->paginate());
142
	}
143
 
144
/**
145
 * admin_view method
146
 *
147
 * @throws NotFoundException
148
 * @param string $id
149
 * @return void
150
 */
151
	public function admin_view($id = null) {
152
		if (!$this->GcmUser->exists($id)) {
153
			throw new NotFoundException(__('Invalid gcm user'));
154
		}
155
		$options = array('conditions' => array('GcmUser.' . $this->GcmUser->primaryKey => $id));
156
		$this->set('gcmUser', $this->GcmUser->find('first', $options));
157
	}
158
 
159
/**
160
 * admin_add method
161
 *
162
 * @return void
163
 */
164
	public function admin_add() {
165
		if ($this->request->is('post')) {
166
			$this->GcmUser->create();
167
			if ($this->GcmUser->save($this->request->data)) {
168
				$this->Session->setFlash(__('The gcm user has been saved.'));
169
				return $this->redirect(array('action' => 'index'));
170
			} else {
171
				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
172
			}
173
		}
174
	}
175
 
176
/**
177
 * admin_edit method
178
 *
179
 * @throws NotFoundException
180
 * @param string $id
181
 * @return void
182
 */
183
	public function admin_edit($id = null) {
184
		if (!$this->GcmUser->exists($id)) {
185
			throw new NotFoundException(__('Invalid gcm user'));
186
		}
187
		if ($this->request->is(array('post', 'put'))) {
188
			if ($this->GcmUser->save($this->request->data)) {
189
				$this->Session->setFlash(__('The gcm user has been saved.'));
190
				return $this->redirect(array('action' => 'index'));
191
			} else {
192
				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
193
			}
194
		} else {
195
			$options = array('conditions' => array('GcmUser.' . $this->GcmUser->primaryKey => $id));
196
			$this->request->data = $this->GcmUser->find('first', $options);
197
		}
198
	}
199
 
200
/**
201
 * admin_delete method
202
 *
203
 * @throws NotFoundException
204
 * @param string $id
205
 * @return void
206
 */
207
	public function admin_delete($id = null) {
208
		$this->GcmUser->id = $id;
209
		if (!$this->GcmUser->exists()) {
210
			throw new NotFoundException(__('Invalid gcm user'));
211
		}
212
		$this->request->onlyAllow('post', 'delete');
213
		if ($this->GcmUser->delete()) {
214
			$this->Session->setFlash(__('The gcm user has been deleted.'));
215
		} else {
216
			$this->Session->setFlash(__('The gcm user could not be deleted. Please, try again.'));
217
		}
218
		return $this->redirect(array('action' => 'index'));
219
	}}