Subversion Repositories SmartDukaan

Rev

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