Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Offers Controller
5
 *
6
 * @property Offer $Offer
7
 * @property PaginatorComponent $Paginator
8
 */
9
class OffersController 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
		$callback = $this->request->query('callback');
21
	}
22
/**
23
 * index method
24
 *
25
 * @return void
26
 */
27
	public function index() {
28
		$this->Offer->recursive = 0;
29
		$this->response->type('json');
30
		$this->layout = 'ajax';
31
		$result = array('offers' => $this->Paginator->paginate());
32
		$this->set(array(
33
		    'result' => $result,
34
		    'callback' => $callback,
35
		    '_serialize' => array('result')
36
		));
37
		$this->render('/Elements/jsonp');
38
	}
39
 
40
/**
41
 * view method
42
 *
43
 * @throws NotFoundException
44
 * @param string $id
45
 * @return void
46
 */
47
	public function view($id = null) {
48
		if (!$this->Offer->exists($id)) {
49
			throw new NotFoundException(__('Invalid offer'));
50
		}
51
		$options = array('conditions' => array('Offer.' . $this->Offer->primaryKey => $id));
52
		$this->set('offer', $this->Offer->find('first', $options));
53
	}
54
 
55
/**
56
 * add method
57
 *
58
 * @return void
59
 */
60
	public function add() {
61
		if ($this->request->is('post')) {
62
			$this->Offer->create();
63
			if ($this->Offer->save($this->request->data)) {
64
				$this->Session->setFlash(__('The offer has been saved.'));
65
				return $this->redirect(array('action' => 'index'));
66
			} else {
67
				$this->Session->setFlash(__('The offer could not be saved. Please, try again.'));
68
			}
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->Offer->exists($id)) {
81
			throw new NotFoundException(__('Invalid offer'));
82
		}
83
		if ($this->request->is(array('post', 'put'))) {
84
			if ($this->Offer->save($this->request->data)) {
85
				$this->Session->setFlash(__('The offer has been saved.'));
86
				return $this->redirect(array('action' => 'index'));
87
			} else {
88
				$this->Session->setFlash(__('The offer could not be saved. Please, try again.'));
89
			}
90
		} else {
91
			$options = array('conditions' => array('Offer.' . $this->Offer->primaryKey => $id));
92
			$this->request->data = $this->Offer->find('first', $options);
93
		}
94
	}
95
 
96
/**
97
 * delete method
98
 *
99
 * @throws NotFoundException
100
 * @param string $id
101
 * @return void
102
 */
103
	public function delete($id = null) {
104
		$this->Offer->id = $id;
105
		if (!$this->Offer->exists()) {
106
			throw new NotFoundException(__('Invalid offer'));
107
		}
108
		$this->request->onlyAllow('post', 'delete');
109
		if ($this->Offer->delete()) {
110
			$this->Session->setFlash(__('The offer has been deleted.'));
111
		} else {
112
			$this->Session->setFlash(__('The offer could not be deleted. Please, try again.'));
113
		}
114
		return $this->redirect(array('action' => 'index'));
115
	}
116
 
117
/**
118
 * admin_index method
119
 *
120
 * @return void
121
 */
122
	public function admin_index() {
123
		$this->Offer->recursive = 0;
124
		$this->set('offers', $this->Paginator->paginate());
125
	}
126
 
127
/**
128
 * admin_view method
129
 *
130
 * @throws NotFoundException
131
 * @param string $id
132
 * @return void
133
 */
134
	public function admin_view($id = null) {
135
		if (!$this->Offer->exists($id)) {
136
			throw new NotFoundException(__('Invalid offer'));
137
		}
138
		$options = array('conditions' => array('Offer.' . $this->Offer->primaryKey => $id));
139
		$this->set('offer', $this->Offer->find('first', $options));
140
	}
141
 
142
/**
143
 * admin_add method
144
 *
145
 * @return void
146
 */
147
	public function admin_add() {
148
		if ($this->request->is('post')) {
149
			$this->Offer->create();
150
			if ($this->Offer->save($this->request->data)) {
151
				$this->Session->setFlash(__('The offer has been saved.'));
152
				return $this->redirect(array('action' => 'index'));
153
			} else {
154
				$this->Session->setFlash(__('The offer could not be saved. Please, try again.'));
155
			}
156
		}
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->Offer->exists($id)) {
168
			throw new NotFoundException(__('Invalid offer'));
169
		}
170
		if ($this->request->is(array('post', 'put'))) {
171
			if ($this->Offer->save($this->request->data)) {
172
				$this->Session->setFlash(__('The offer has been saved.'));
173
				return $this->redirect(array('action' => 'index'));
174
			} else {
175
				$this->Session->setFlash(__('The offer could not be saved. Please, try again.'));
176
			}
177
		} else {
178
			$options = array('conditions' => array('Offer.' . $this->Offer->primaryKey => $id));
179
			$this->request->data = $this->Offer->find('first', $options);
180
		}
181
	}
182
 
183
/**
184
 * admin_delete method
185
 *
186
 * @throws NotFoundException
187
 * @param string $id
188
 * @return void
189
 */
190
	public function admin_delete($id = null) {
191
		$this->Offer->id = $id;
192
		if (!$this->Offer->exists()) {
193
			throw new NotFoundException(__('Invalid offer'));
194
		}
195
		$this->request->onlyAllow('post', 'delete');
196
		if ($this->Offer->delete()) {
197
			$this->Session->setFlash(__('The offer has been deleted.'));
198
		} else {
199
			$this->Session->setFlash(__('The offer could not be deleted. Please, try again.'));
200
		}
201
		return $this->redirect(array('action' => 'index'));
202
	}}