Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
14776 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Pushnotifications Controller
5
 *
6
 * @property Pushnotification $Pushnotification
7
 * @property PaginatorComponent $Paginator
8
 */
9
class PushnotificationsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
14778 anikendra 18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('add');
21
	}
14776 anikendra 22
/**
23
 * index method
24
 *
25
 * @return void
26
 */
27
	public function index() {
28
		$this->Pushnotification->recursive = 0;
29
		$this->set('pushnotifications', $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->Pushnotification->exists($id)) {
41
			throw new NotFoundException(__('Invalid pushnotification'));
42
		}
43
		$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
44
		$this->set('pushnotification', $this->Pushnotification->find('first', $options));
45
	}
46
 
47
/**
48
 * add method
49
 *
50
 * @return void
51
 */
52
	public function add() {
53
		if ($this->request->is('post')) {
14778 anikendra 54
			$this->log(print_r($this->request->data,1),'pushnotifications');
14783 anikendra 55
			$data = $this->request->data;
56
			$data['type'] = $data['result'];
57
			$data['status'] = 1;
14784 anikendra 58
			$data['response_time'] = date('Y-m-d h:i:s',strtotime($data['timestamp']));
14783 anikendra 59
			$data['notification_campaign_id'] = $data['cid'];
60
			unset($data['result']);
61
			unset($data['cid']);
14784 anikendra 62
			unset($data['timestamp']);
63
			$this->log(print_r($data,1),'pushnotifications');
14776 anikendra 64
			$this->Pushnotification->create();
14783 anikendra 65
			if ($this->Pushnotification->save($data)) {
66
				// $this->Session->setFlash(__('The pushnotification has been saved.'));
67
				// return $this->redirect(array('action' => 'index'));
68
				$result = array('success' => true,'message'=>'The pushnotification has been saved.');
14776 anikendra 69
			} else {
14783 anikendra 70
				$result = array('success' => false,'message'=>'The pushnotification could not be saved. Please, try again.');
71
				// $this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
14776 anikendra 72
			}
73
		}
14783 anikendra 74
		$this->set(array(
75
		    'result' => $result,
76
		    '_serialize' => array('result')
77
		));
78
		$this->render('/Elements/json');
14776 anikendra 79
	}
80
 
81
/**
82
 * edit method
83
 *
84
 * @throws NotFoundException
85
 * @param string $id
86
 * @return void
87
 */
88
	public function edit($id = null) {
89
		if (!$this->Pushnotification->exists($id)) {
90
			throw new NotFoundException(__('Invalid pushnotification'));
91
		}
92
		if ($this->request->is(array('post', 'put'))) {
93
			if ($this->Pushnotification->save($this->request->data)) {
94
				$this->Session->setFlash(__('The pushnotification has been saved.'));
95
				return $this->redirect(array('action' => 'index'));
96
			} else {
97
				$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
98
			}
99
		} else {
100
			$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
101
			$this->request->data = $this->Pushnotification->find('first', $options);
102
		}
103
		$users = $this->Pushnotification->User->find('list');
104
		$this->set(compact('users'));
105
	}
106
 
107
/**
108
 * delete method
109
 *
110
 * @throws NotFoundException
111
 * @param string $id
112
 * @return void
113
 */
114
	public function delete($id = null) {
115
		$this->Pushnotification->id = $id;
116
		if (!$this->Pushnotification->exists()) {
117
			throw new NotFoundException(__('Invalid pushnotification'));
118
		}
119
		$this->request->onlyAllow('post', 'delete');
120
		if ($this->Pushnotification->delete()) {
121
			$this->Session->setFlash(__('The pushnotification has been deleted.'));
122
		} else {
123
			$this->Session->setFlash(__('The pushnotification could not be deleted. Please, try again.'));
124
		}
125
		return $this->redirect(array('action' => 'index'));
126
	}
127
 
128
/**
129
 * admin_index method
130
 *
131
 * @return void
132
 */
133
	public function admin_index() {
134
		$this->Pushnotification->recursive = 0;
135
		$this->set('pushnotifications', $this->Paginator->paginate());
136
	}
137
 
138
/**
139
 * admin_view method
140
 *
141
 * @throws NotFoundException
142
 * @param string $id
143
 * @return void
144
 */
145
	public function admin_view($id = null) {
146
		if (!$this->Pushnotification->exists($id)) {
147
			throw new NotFoundException(__('Invalid pushnotification'));
148
		}
149
		$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
150
		$this->set('pushnotification', $this->Pushnotification->find('first', $options));
151
	}
152
 
153
/**
154
 * admin_add method
155
 *
156
 * @return void
157
 */
158
	public function admin_add() {
159
		if ($this->request->is('post')) {
160
			$this->Pushnotification->create();
161
			if ($this->Pushnotification->save($this->request->data)) {
162
				$this->Session->setFlash(__('The pushnotification has been saved.'));
163
				return $this->redirect(array('action' => 'index'));
164
			} else {
165
				$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
166
			}
167
		}
168
		$users = $this->Pushnotification->User->find('list');
169
		$this->set(compact('users'));
170
	}
171
 
172
/**
173
 * admin_edit method
174
 *
175
 * @throws NotFoundException
176
 * @param string $id
177
 * @return void
178
 */
179
	public function admin_edit($id = null) {
180
		if (!$this->Pushnotification->exists($id)) {
181
			throw new NotFoundException(__('Invalid pushnotification'));
182
		}
183
		if ($this->request->is(array('post', 'put'))) {
184
			if ($this->Pushnotification->save($this->request->data)) {
185
				$this->Session->setFlash(__('The pushnotification has been saved.'));
186
				return $this->redirect(array('action' => 'index'));
187
			} else {
188
				$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
189
			}
190
		} else {
191
			$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
192
			$this->request->data = $this->Pushnotification->find('first', $options);
193
		}
194
		$users = $this->Pushnotification->User->find('list');
195
		$this->set(compact('users'));
196
	}
197
 
198
/**
199
 * admin_delete method
200
 *
201
 * @throws NotFoundException
202
 * @param string $id
203
 * @return void
204
 */
205
	public function admin_delete($id = null) {
206
		$this->Pushnotification->id = $id;
207
		if (!$this->Pushnotification->exists()) {
208
			throw new NotFoundException(__('Invalid pushnotification'));
209
		}
210
		$this->request->onlyAllow('post', 'delete');
211
		if ($this->Pushnotification->delete()) {
212
			$this->Session->setFlash(__('The pushnotification has been deleted.'));
213
		} else {
214
			$this->Session->setFlash(__('The pushnotification could not be deleted. Please, try again.'));
215
		}
216
		return $this->redirect(array('action' => 'index'));
217
	}}