| 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;
|
|
|
116 |
$this->Paginator->settings = array('order' => array('id'=>'desc'));
|
|
|
117 |
$this->set('searchTerms', $this->Paginator->paginate());
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* admin_view method
|
|
|
122 |
*
|
|
|
123 |
* @throws NotFoundException
|
|
|
124 |
* @param string $id
|
|
|
125 |
* @return void
|
|
|
126 |
*/
|
|
|
127 |
public function admin_view($id = null) {
|
|
|
128 |
if (!$this->SearchTerm->exists($id)) {
|
|
|
129 |
throw new NotFoundException(__('Invalid search term'));
|
|
|
130 |
}
|
|
|
131 |
$options = array('conditions' => array('SearchTerm.' . $this->SearchTerm->primaryKey => $id));
|
|
|
132 |
$this->set('searchTerm', $this->SearchTerm->find('first', $options));
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
/**
|
|
|
136 |
* admin_add method
|
|
|
137 |
*
|
|
|
138 |
* @return void
|
|
|
139 |
*/
|
|
|
140 |
public function admin_add() {
|
|
|
141 |
if ($this->request->is('post')) {
|
|
|
142 |
$this->SearchTerm->create();
|
|
|
143 |
if ($this->SearchTerm->save($this->request->data)) {
|
|
|
144 |
$this->Session->setFlash(__('The search term has been saved.'));
|
|
|
145 |
return $this->redirect(array('action' => 'index'));
|
|
|
146 |
} else {
|
|
|
147 |
$this->Session->setFlash(__('The search term could not be saved. Please, try again.'));
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
$users = $this->SearchTerm->User->find('list');
|
|
|
151 |
$this->set(compact('users'));
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* admin_edit method
|
|
|
156 |
*
|
|
|
157 |
* @throws NotFoundException
|
|
|
158 |
* @param string $id
|
|
|
159 |
* @return void
|
|
|
160 |
*/
|
|
|
161 |
public function admin_edit($id = null) {
|
|
|
162 |
if (!$this->SearchTerm->exists($id)) {
|
|
|
163 |
throw new NotFoundException(__('Invalid search term'));
|
|
|
164 |
}
|
|
|
165 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
166 |
if ($this->SearchTerm->save($this->request->data)) {
|
|
|
167 |
$this->Session->setFlash(__('The search term has been saved.'));
|
|
|
168 |
return $this->redirect(array('action' => 'index'));
|
|
|
169 |
} else {
|
|
|
170 |
$this->Session->setFlash(__('The search term could not be saved. Please, try again.'));
|
|
|
171 |
}
|
|
|
172 |
} else {
|
|
|
173 |
$options = array('conditions' => array('SearchTerm.' . $this->SearchTerm->primaryKey => $id));
|
|
|
174 |
$this->request->data = $this->SearchTerm->find('first', $options);
|
|
|
175 |
}
|
|
|
176 |
$users = $this->SearchTerm->User->find('list');
|
|
|
177 |
$this->set(compact('users'));
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
/**
|
|
|
181 |
* admin_delete method
|
|
|
182 |
*
|
|
|
183 |
* @throws NotFoundException
|
|
|
184 |
* @param string $id
|
|
|
185 |
* @return void
|
|
|
186 |
*/
|
|
|
187 |
public function admin_delete($id = null) {
|
|
|
188 |
$this->SearchTerm->id = $id;
|
|
|
189 |
if (!$this->SearchTerm->exists()) {
|
|
|
190 |
throw new NotFoundException(__('Invalid search term'));
|
|
|
191 |
}
|
|
|
192 |
$this->request->onlyAllow('post', 'delete');
|
|
|
193 |
if ($this->SearchTerm->delete()) {
|
|
|
194 |
$this->Session->setFlash(__('The search term has been deleted.'));
|
|
|
195 |
} else {
|
|
|
196 |
$this->Session->setFlash(__('The search term could not be deleted. Please, try again.'));
|
|
|
197 |
}
|
|
|
198 |
return $this->redirect(array('action' => 'index'));
|
|
|
199 |
}
|
|
|
200 |
public function admin_user($id=null){
|
|
|
201 |
$options = array('conditions' => array('User.id'=> $id));
|
|
|
202 |
$list = $this->SearchTerm->find('all',$options);
|
|
|
203 |
$this->set('searchTerms', $list);
|
|
|
204 |
$this->set('userId', $id);
|
|
|
205 |
|
|
|
206 |
}
|
| 15503 |
manas |
207 |
public function admin_search($id=null){
|
|
|
208 |
$data=$this->request->query('search');
|
|
|
209 |
$options = array('conditions' => array('SearchTerm.search_term LIKE '=> '%'.$data.'%'));
|
|
|
210 |
$list = $this->SearchTerm->find('all',$options);
|
|
|
211 |
$this->set('searchTerms', $list);
|
|
|
212 |
$this->set('search_term', $data);
|
|
|
213 |
}
|
| 14989 |
manas |
214 |
}
|