Subversion Repositories SmartDukaan

Rev

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