Subversion Repositories SmartDukaan

Rev

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