Subversion Repositories SmartDukaan

Rev

Rev 14484 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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