Subversion Repositories SmartDukaan

Rev

Rev 16593 | Rev 16755 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16549 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * AppOffers Controller
5
 *
6
 * @property AppOffer $AppOffer
7
 * @property PaginatorComponent $Paginator
8
 */
9
class AppOffersController 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
 */
16614 anikendra 23
	public function index() {		
16549 anikendra 24
		$this->AppOffer->recursive = 0;
16614 anikendra 25
		$this->set('appOffers', $this->Paginator->paginate());		
16549 anikendra 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->AppOffer->exists($id)) {
37
			throw new NotFoundException(__('Invalid app offer'));
38
		}
39
		$options = array('conditions' => array('AppOffer.' . $this->AppOffer->primaryKey => $id));
40
		$this->set('appOffer', $this->AppOffer->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->AppOffer->create();
51
			if ($this->AppOffer->save($this->request->data)) {
52
				$this->Session->setFlash(__('The app offer has been saved.'));
53
				return $this->redirect(array('action' => 'index'));
54
			} else {
55
				$this->Session->setFlash(__('The app offer could not be saved. Please, try again.'));
56
			}
57
		}
58
	}
59
 
60
/**
61
 * edit method
62
 *
63
 * @throws NotFoundException
64
 * @param string $id
65
 * @return void
66
 */
67
	public function edit($id = null) {
68
		if (!$this->AppOffer->exists($id)) {
69
			throw new NotFoundException(__('Invalid app offer'));
70
		}
71
		if ($this->request->is(array('post', 'put'))) {
72
			if ($this->AppOffer->save($this->request->data)) {
73
				$this->Session->setFlash(__('The app offer has been saved.'));
74
				return $this->redirect(array('action' => 'index'));
75
			} else {
76
				$this->Session->setFlash(__('The app offer could not be saved. Please, try again.'));
77
			}
78
		} else {
79
			$options = array('conditions' => array('AppOffer.' . $this->AppOffer->primaryKey => $id));
80
			$this->request->data = $this->AppOffer->find('first', $options);
81
		}
82
	}
83
 
84
/**
85
 * delete method
86
 *
87
 * @throws NotFoundException
88
 * @param string $id
89
 * @return void
90
 */
91
	public function delete($id = null) {
92
		$this->AppOffer->id = $id;
93
		if (!$this->AppOffer->exists()) {
94
			throw new NotFoundException(__('Invalid app offer'));
95
		}
96
		$this->request->onlyAllow('post', 'delete');
97
		if ($this->AppOffer->delete()) {
98
			$this->Session->setFlash(__('The app offer has been deleted.'));
99
		} else {
100
			$this->Session->setFlash(__('The app offer could not be deleted. Please, try again.'));
101
		}
102
		return $this->redirect(array('action' => 'index'));
103
	}
104
 
105
/**
106
 * admin_index method
107
 *
108
 * @return void
109
 */
110
	public function admin_index() {
16593 anikendra 111
		$type = $this->request->query('type');
112
		$search = $this->request->query('search');	
113
		$conditions = array();
114
		if(!empty($type) && !empty($search)){
115
			$conditions = array($type=>$search);
116
			$options['conditions'] = array($type.' LIKE ' =>"%$search%");			
117
			$this->Paginator->settings = $options;
118
		}
16549 anikendra 119
		$this->AppOffer->recursive = 0;
120
		$this->set('appOffers', $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->AppOffer->exists($id)) {
132
			throw new NotFoundException(__('Invalid app offer'));
133
		}
134
		$options = array('conditions' => array('AppOffer.' . $this->AppOffer->primaryKey => $id));
135
		$this->set('appOffer', $this->AppOffer->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->AppOffer->create();
146
			if ($this->AppOffer->save($this->request->data)) {
147
				$this->Session->setFlash(__('The app offer has been saved.'));
148
				return $this->redirect(array('action' => 'index'));
149
			} else {
150
				$this->Session->setFlash(__('The app offer could not be saved. Please, try again.'));
151
			}
152
		}
153
		$affiliate_ids = $this->AppOffer->AppAffiliate->find('list');
154
		$this->set(compact('affiliate_ids'));
155
	}
156
 
157
/**
158
 * admin_edit method
159
 *
160
 * @throws NotFoundException
161
 * @param string $id
162
 * @return void
163
 */
164
	public function admin_edit($id = null) {
165
		if (!$this->AppOffer->exists($id)) {
166
			throw new NotFoundException(__('Invalid app offer'));
167
		}
168
		if ($this->request->is(array('post', 'put'))) {
169
			if ($this->AppOffer->save($this->request->data)) {
170
				$this->Session->setFlash(__('The app offer has been saved.'));
171
				return $this->redirect(array('action' => 'index'));
172
			} else {
173
				$this->Session->setFlash(__('The app offer could not be saved. Please, try again.'));
174
			}
175
		} else {
176
			$options = array('conditions' => array('AppOffer.' . $this->AppOffer->primaryKey => $id));
177
			$this->request->data = $this->AppOffer->find('first', $options);
178
			$affiliate_ids = $this->AppOffer->AppAffiliate->find('list');
179
			$this->set(compact('affiliate_ids'));
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->AppOffer->id = $id;
192
		if (!$this->AppOffer->exists()) {
193
			throw new NotFoundException(__('Invalid app offer'));
194
		}
195
		$this->request->onlyAllow('post', 'delete');
196
		if ($this->AppOffer->delete()) {
197
			$this->Session->setFlash(__('The app offer has been deleted.'));
198
		} else {
199
			$this->Session->setFlash(__('The app offer could not be deleted. Please, try again.'));
200
		}
201
		return $this->redirect(array('action' => 'index'));
202
	}}