Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Orders Controller
5
 *
6
 * @property Order $Order
7
 * @property PaginatorComponent $Paginator
8
 */
9
class OrdersController 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->Order->recursive = 0;
25
		$this->set('orders', $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->Order->exists($id)) {
37
			throw new NotFoundException(__('Invalid order'));
38
		}
39
		$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
40
		$this->set('order', $this->Order->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->Order->create();
51
			if ($this->Order->save($this->request->data)) {
52
				$this->Session->setFlash(__('The order has been saved.'));
53
				return $this->redirect(array('action' => 'index'));
54
			} else {
55
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
56
			}
57
		}
58
		$users = $this->Order->User->find('list');
59
		$stores = $this->Order->Store->find('list');
60
		$storeOrders = $this->Order->StoreOrder->find('list');
61
		$this->set(compact('users', 'stores', 'storeOrders'));
62
	}
63
 
64
/**
65
 * edit method
66
 *
67
 * @throws NotFoundException
68
 * @param string $id
69
 * @return void
70
 */
71
	public function edit($id = null) {
72
		if (!$this->Order->exists($id)) {
73
			throw new NotFoundException(__('Invalid order'));
74
		}
75
		if ($this->request->is(array('post', 'put'))) {
76
			if ($this->Order->save($this->request->data)) {
77
				$this->Session->setFlash(__('The order has been saved.'));
78
				return $this->redirect(array('action' => 'index'));
79
			} else {
80
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
81
			}
82
		} else {
83
			$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
84
			$this->request->data = $this->Order->find('first', $options);
85
		}
86
		$users = $this->Order->User->find('list');
87
		$stores = $this->Order->Store->find('list');
88
		$storeOrders = $this->Order->StoreOrder->find('list');
89
		$this->set(compact('users', 'stores', 'storeOrders'));
90
	}
91
 
92
/**
93
 * delete method
94
 *
95
 * @throws NotFoundException
96
 * @param string $id
97
 * @return void
98
 */
99
	public function delete($id = null) {
100
		$this->Order->id = $id;
101
		if (!$this->Order->exists()) {
102
			throw new NotFoundException(__('Invalid order'));
103
		}
104
		$this->request->onlyAllow('post', 'delete');
105
		if ($this->Order->delete()) {
106
			$this->Session->setFlash(__('The order has been deleted.'));
107
		} else {
108
			$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
109
		}
110
		return $this->redirect(array('action' => 'index'));
111
	}
112
 
113
/**
114
 * admin_index method
115
 *
116
 * @return void
117
 */
118
	public function admin_index() {
119
		$this->Order->recursive = 0;
120
		$this->set('orders', $this->Paginator->paginate());
121
	}
122
 
123
/**
124
 * admin_view method
125
 *
126
 * @throws NotFoundException
127
 * @param string $id
128
 * @return void
129
 */
130
	public function admin_view($id = null) {
131
		if (!$this->Order->exists($id)) {
132
			throw new NotFoundException(__('Invalid order'));
133
		}
134
		$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
135
		$this->set('order', $this->Order->find('first', $options));
136
	}
137
 
138
/**
139
 * admin_add method
140
 *
141
 * @return void
142
 */
143
	public function admin_add() {
144
		if ($this->request->is('post')) {
145
			$this->Order->create();
146
			if ($this->Order->save($this->request->data)) {
147
				$this->Session->setFlash(__('The order has been saved.'));
148
				return $this->redirect(array('action' => 'index'));
149
			} else {
150
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
151
			}
152
		}
153
		$users = $this->Order->User->find('list');
154
		$stores = $this->Order->Store->find('list');
155
		$storeOrders = $this->Order->StoreOrder->find('list');
156
		$this->set(compact('users', 'stores', 'storeOrders'));
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->Order->exists($id)) {
168
			throw new NotFoundException(__('Invalid order'));
169
		}
170
		if ($this->request->is(array('post', 'put'))) {
171
			if ($this->Order->save($this->request->data)) {
172
				$this->Session->setFlash(__('The order has been saved.'));
173
				return $this->redirect(array('action' => 'index'));
174
			} else {
175
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
176
			}
177
		} else {
178
			$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
179
			$this->request->data = $this->Order->find('first', $options);
180
		}
181
		$users = $this->Order->User->find('list');
182
		$stores = $this->Order->Store->find('list');
183
		$storeOrders = $this->Order->StoreOrder->find('list');
184
		$this->set(compact('users', 'stores', 'storeOrders'));
185
	}
186
 
187
/**
188
 * admin_delete method
189
 *
190
 * @throws NotFoundException
191
 * @param string $id
192
 * @return void
193
 */
194
	public function admin_delete($id = null) {
195
		$this->Order->id = $id;
196
		if (!$this->Order->exists()) {
197
			throw new NotFoundException(__('Invalid order'));
198
		}
199
		$this->request->onlyAllow('post', 'delete');
200
		if ($this->Order->delete()) {
201
			$this->Session->setFlash(__('The order has been deleted.'));
202
		} else {
203
			$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
204
		}
205
		return $this->redirect(array('action' => 'index'));
206
	}}