Subversion Repositories SmartDukaan

Rev

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