Subversion Repositories SmartDukaan

Rev

Rev 14786 | Rev 15667 | 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) {
15410 manas 40
 
14776 anikendra 41
		if (!$this->Pushnotification->exists($id)) {
42
			throw new NotFoundException(__('Invalid pushnotification'));
43
		}
15410 manas 44
		$total = $this->Article->find('count');
45
		/*$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
46
		$this->set('pushnotification', $this->Pushnotification->find('first', $options));*/
14776 anikendra 47
	}
48
 
49
/**
50
 * add method
51
 *
52
 * @return void
53
 */
54
	public function add() {
55
		if ($this->request->is('post')) {
14778 anikendra 56
			$this->log(print_r($this->request->data,1),'pushnotifications');
14783 anikendra 57
			$data = $this->request->data;
58
			$data['type'] = $data['result'];
59
			$data['status'] = 1;
14786 anikendra 60
			$data['response_time'] = date('Y-m-d H:i:s',strtotime($data['timestamp']));
14783 anikendra 61
			$data['notification_campaign_id'] = $data['cid'];
62
			unset($data['result']);
63
			unset($data['cid']);
14784 anikendra 64
			unset($data['timestamp']);
14786 anikendra 65
			if(empty($data['user_id'])){
66
				unset($data['user_id']);
67
			}
14784 anikendra 68
			$this->log(print_r($data,1),'pushnotifications');
14776 anikendra 69
			$this->Pushnotification->create();
14783 anikendra 70
			if ($this->Pushnotification->save($data)) {
71
				// $this->Session->setFlash(__('The pushnotification has been saved.'));
72
				// return $this->redirect(array('action' => 'index'));
73
				$result = array('success' => true,'message'=>'The pushnotification has been saved.');
14776 anikendra 74
			} else {
14783 anikendra 75
				$result = array('success' => false,'message'=>'The pushnotification could not be saved. Please, try again.');
76
				// $this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
14776 anikendra 77
			}
78
		}
14783 anikendra 79
		$this->set(array(
80
		    'result' => $result,
81
		    '_serialize' => array('result')
82
		));
83
		$this->render('/Elements/json');
14776 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->Pushnotification->exists($id)) {
95
			throw new NotFoundException(__('Invalid pushnotification'));
96
		}
97
		if ($this->request->is(array('post', 'put'))) {
98
			if ($this->Pushnotification->save($this->request->data)) {
99
				$this->Session->setFlash(__('The pushnotification has been saved.'));
100
				return $this->redirect(array('action' => 'index'));
101
			} else {
102
				$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
103
			}
104
		} else {
105
			$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
106
			$this->request->data = $this->Pushnotification->find('first', $options);
107
		}
108
		$users = $this->Pushnotification->User->find('list');
109
		$this->set(compact('users'));
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->Pushnotification->id = $id;
121
		if (!$this->Pushnotification->exists()) {
122
			throw new NotFoundException(__('Invalid pushnotification'));
123
		}
124
		$this->request->onlyAllow('post', 'delete');
125
		if ($this->Pushnotification->delete()) {
126
			$this->Session->setFlash(__('The pushnotification has been deleted.'));
127
		} else {
128
			$this->Session->setFlash(__('The pushnotification 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->Pushnotification->recursive = 0;
140
		$this->set('pushnotifications', $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->Pushnotification->exists($id)) {
152
			throw new NotFoundException(__('Invalid pushnotification'));
153
		}
15410 manas 154
		$total = $this->Article->find('count');
155
/*		$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
156
		$this->set('pushnotification', $this->Pushnotification->find('first', $options));*/
14776 anikendra 157
	}
158
 
159
/**
160
 * admin_add method
161
 *
162
 * @return void
163
 */
164
	public function admin_add() {
165
		if ($this->request->is('post')) {
166
			$this->Pushnotification->create();
167
			if ($this->Pushnotification->save($this->request->data)) {
168
				$this->Session->setFlash(__('The pushnotification has been saved.'));
169
				return $this->redirect(array('action' => 'index'));
170
			} else {
171
				$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
172
			}
173
		}
174
		$users = $this->Pushnotification->User->find('list');
175
		$this->set(compact('users'));
176
	}
177
 
178
/**
179
 * admin_edit method
180
 *
181
 * @throws NotFoundException
182
 * @param string $id
183
 * @return void
184
 */
185
	public function admin_edit($id = null) {
186
		if (!$this->Pushnotification->exists($id)) {
187
			throw new NotFoundException(__('Invalid pushnotification'));
188
		}
189
		if ($this->request->is(array('post', 'put'))) {
190
			if ($this->Pushnotification->save($this->request->data)) {
191
				$this->Session->setFlash(__('The pushnotification has been saved.'));
192
				return $this->redirect(array('action' => 'index'));
193
			} else {
194
				$this->Session->setFlash(__('The pushnotification could not be saved. Please, try again.'));
195
			}
196
		} else {
197
			$options = array('conditions' => array('Pushnotification.' . $this->Pushnotification->primaryKey => $id));
198
			$this->request->data = $this->Pushnotification->find('first', $options);
199
		}
200
		$users = $this->Pushnotification->User->find('list');
201
		$this->set(compact('users'));
202
	}
203
 
204
/**
205
 * admin_delete method
206
 *
207
 * @throws NotFoundException
208
 * @param string $id
209
 * @return void
210
 */
211
	public function admin_delete($id = null) {
212
		$this->Pushnotification->id = $id;
213
		if (!$this->Pushnotification->exists()) {
214
			throw new NotFoundException(__('Invalid pushnotification'));
215
		}
216
		$this->request->onlyAllow('post', 'delete');
217
		if ($this->Pushnotification->delete()) {
218
			$this->Session->setFlash(__('The pushnotification has been deleted.'));
219
		} else {
220
			$this->Session->setFlash(__('The pushnotification could not be deleted. Please, try again.'));
221
		}
222
		return $this->redirect(array('action' => 'index'));
223
	}}