Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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