Subversion Repositories SmartDukaan

Rev

Rev 14928 | Details | Compare with Previous | Last modification | View Log | RSS feed

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