Subversion Repositories SmartDukaan

Rev

Rev 16755 | 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');	
16755 anikendra 113
		$conditions = array('offer_active'=>1);
114
		$offer_active = $this->request->query('offer_active');		
115
		if(strlen($offer_active)>0){
116
			print_r($offer_active);
117
			$conditions = array('offer_active'=>$offer_active);		
118
		}
16593 anikendra 119
		if(!empty($type) && !empty($search)){
16755 anikendra 120
			$conditions[] = array($type .' LIKE ' => "%$search%");
121
			// $options['conditions'][] = array($type.' LIKE ' =>"%$search%");			
122
			// $this->Paginator->settings = $options;
16593 anikendra 123
		}
16755 anikendra 124
		$options['conditions'] = $conditions;
125
		$this->Paginator->settings = $options;	
16549 anikendra 126
		$this->AppOffer->recursive = 0;
127
		$this->set('appOffers', $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->AppOffer->exists($id)) {
139
			throw new NotFoundException(__('Invalid app offer'));
140
		}
141
		$options = array('conditions' => array('AppOffer.' . $this->AppOffer->primaryKey => $id));
142
		$this->set('appOffer', $this->AppOffer->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->AppOffer->create();
153
			if ($this->AppOffer->save($this->request->data)) {
154
				$this->Session->setFlash(__('The app offer has been saved.'));
155
				return $this->redirect(array('action' => 'index'));
156
			} else {
157
				$this->Session->setFlash(__('The app offer could not be saved. Please, try again.'));
158
			}
159
		}
160
		$affiliate_ids = $this->AppOffer->AppAffiliate->find('list');
161
		$this->set(compact('affiliate_ids'));
162
	}
163
 
164
/**
165
 * admin_edit method
166
 *
167
 * @throws NotFoundException
168
 * @param string $id
169
 * @return void
170
 */
171
	public function admin_edit($id = null) {
172
		if (!$this->AppOffer->exists($id)) {
173
			throw new NotFoundException(__('Invalid app offer'));
174
		}
175
		if ($this->request->is(array('post', 'put'))) {
176
			if ($this->AppOffer->save($this->request->data)) {
177
				$this->Session->setFlash(__('The app offer has been saved.'));
178
				return $this->redirect(array('action' => 'index'));
179
			} else {
180
				$this->Session->setFlash(__('The app offer could not be saved. Please, try again.'));
181
			}
182
		} else {
183
			$options = array('conditions' => array('AppOffer.' . $this->AppOffer->primaryKey => $id));
184
			$this->request->data = $this->AppOffer->find('first', $options);
185
			$affiliate_ids = $this->AppOffer->AppAffiliate->find('list');
186
			$this->set(compact('affiliate_ids'));
187
		}
188
	}
189
 
16755 anikendra 190
	public function admin_update($appmasterid = null) {		
191
		if ($this->request->is(array('post', 'put'))) {
192
			if ($this->AppOffer->save($this->request->data)) {
193
				$this->Session->setFlash(__('The app offer has been saved.'));
194
				return $this->redirect(array('action' => 'index'));
195
			} else {
196
				$this->Session->setFlash(__('The app offer could not be saved. Please, try again.'));
197
			}
198
		} else {
199
			$options = array('conditions' => array('AppOffer.appmaster_id' => $appmasterid,'AppOffer.offer_active'=>1));
200
			$this->request->data = $this->AppOffer->find('first', $options);
201
			$affiliate_ids = $this->AppOffer->AppAffiliate->find('list');
202
			$this->set(compact('affiliate_ids'));
203
			$this->render('admin_edit');
204
		}
205
	}
206
 
16549 anikendra 207
/**
208
 * admin_delete method
209
 *
210
 * @throws NotFoundException
211
 * @param string $id
212
 * @return void
213
 */
214
	public function admin_delete($id = null) {
215
		$this->AppOffer->id = $id;
216
		if (!$this->AppOffer->exists()) {
217
			throw new NotFoundException(__('Invalid app offer'));
218
		}
219
		$this->request->onlyAllow('post', 'delete');
220
		if ($this->AppOffer->delete()) {
221
			$this->Session->setFlash(__('The app offer has been deleted.'));
222
		} else {
223
			$this->Session->setFlash(__('The app offer could not be deleted. Please, try again.'));
224
		}
225
		return $this->redirect(array('action' => 'index'));
226
	}}