Subversion Repositories SmartDukaan

Rev

Rev 15503 | Details | Compare with Previous | Last modification | View Log | RSS feed

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