Subversion Repositories SmartDukaan

Rev

Rev 15043 | Rev 15767 | 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');
61
				$data = $this->GcmUser->find('first',array('conditions'=>array('user_id'=>$this->request->data['user_id'],'imeinumber'=>$this->request->data['imeinumber'])));
62
				$this->log("found row ".print_r($data,1),'gcm');
63
				if(!empty($data)){
64
					$dataForModel['id'] = $data['GcmUser']['id'];
65
				}else{
66
					$this->GcmUser->create();
67
				}			
68
				$this->log('lets save '.print_r($dataForModel,1),'gcm');
69
				if ($this->GcmUser->save($dataForModel)) {
70
					$result = array('success'=>true);
71
	//				$this->Session->setFlash(__('The gcm user has been saved.'));
72
	//				return $this->redirect(array('action' => 'index'));
73
				} else {
74
					$result = array('success'=>false);
75
	//				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
76
				}
13532 anikendra 77
			}
78
		}
13698 anikendra 79
		$this->set(array(
80
		    'result' => $result,
81
		    '_serialize' => array('result')
82
		));		
83
		$this->render('/Elements/json');
13532 anikendra 84
	}
85
 
86
/**
87
 * edit method
88
 *
89
 * @throws NotFoundException
90
 * @param string $id
91
 * @return void
92
 */
93
	public function edit($id = null) {
94
		if (!$this->GcmUser->exists($id)) {
95
			throw new NotFoundException(__('Invalid gcm user'));
96
		}
97
		if ($this->request->is(array('post', 'put'))) {
98
			if ($this->GcmUser->save($this->request->data)) {
99
				$this->Session->setFlash(__('The gcm user has been saved.'));
100
				return $this->redirect(array('action' => 'index'));
101
			} else {
102
				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
103
			}
104
		} else {
105
			$options = array('conditions' => array('GcmUser.' . $this->GcmUser->primaryKey => $id));
106
			$this->request->data = $this->GcmUser->find('first', $options);
107
		}
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->GcmUser->id = $id;
119
		if (!$this->GcmUser->exists()) {
120
			throw new NotFoundException(__('Invalid gcm user'));
121
		}
122
		$this->request->onlyAllow('post', 'delete');
123
		if ($this->GcmUser->delete()) {
124
			$this->Session->setFlash(__('The gcm user has been deleted.'));
125
		} else {
126
			$this->Session->setFlash(__('The gcm user 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->GcmUser->recursive = 0;
138
		$this->set('gcmUsers', $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->GcmUser->exists($id)) {
150
			throw new NotFoundException(__('Invalid gcm user'));
151
		}
152
		$options = array('conditions' => array('GcmUser.' . $this->GcmUser->primaryKey => $id));
153
		$this->set('gcmUser', $this->GcmUser->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->GcmUser->create();
164
			if ($this->GcmUser->save($this->request->data)) {
165
				$this->Session->setFlash(__('The gcm user has been saved.'));
166
				return $this->redirect(array('action' => 'index'));
167
			} else {
168
				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
169
			}
170
		}
171
	}
172
 
173
/**
174
 * admin_edit method
175
 *
176
 * @throws NotFoundException
177
 * @param string $id
178
 * @return void
179
 */
180
	public function admin_edit($id = null) {
181
		if (!$this->GcmUser->exists($id)) {
182
			throw new NotFoundException(__('Invalid gcm user'));
183
		}
184
		if ($this->request->is(array('post', 'put'))) {
185
			if ($this->GcmUser->save($this->request->data)) {
186
				$this->Session->setFlash(__('The gcm user has been saved.'));
187
				return $this->redirect(array('action' => 'index'));
188
			} else {
189
				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
190
			}
191
		} else {
192
			$options = array('conditions' => array('GcmUser.' . $this->GcmUser->primaryKey => $id));
193
			$this->request->data = $this->GcmUser->find('first', $options);
194
		}
195
	}
196
 
197
/**
198
 * admin_delete method
199
 *
200
 * @throws NotFoundException
201
 * @param string $id
202
 * @return void
203
 */
204
	public function admin_delete($id = null) {
205
		$this->GcmUser->id = $id;
206
		if (!$this->GcmUser->exists()) {
207
			throw new NotFoundException(__('Invalid gcm user'));
208
		}
209
		$this->request->onlyAllow('post', 'delete');
210
		if ($this->GcmUser->delete()) {
211
			$this->Session->setFlash(__('The gcm user has been deleted.'));
212
		} else {
213
			$this->Session->setFlash(__('The gcm user could not be deleted. Please, try again.'));
214
		}
215
		return $this->redirect(array('action' => 'index'));
216
	}}