ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilShopMetaDataSearch.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once 'Services/Search/classes/class.ilAbstractSearch.php';
25
34{
35 public $mode = '';
36
37 /*
38 * instance of query parser
39 */
40 public $query_parser = null;
41
42 public $db = null;
43
45
46 public function __construct($qp_obj)
47 {
48 parent::__construct($qp_obj);
49 }
50
51 public function setCustomSearchResultObject($a_search_result_obect)
52 {
53 $this->search_result = $a_search_result_obect;
54 }
55
56 public function setFilterShopTopicId($a_topic_id)
57 {
58 $this->filter_shop_topic_id = $a_topic_id;
59 }
60 public function getFilterShopTopicId()
61 {
63 }
64
65 public function setMode($a_mode)
66 {
67 $this->mode = $a_mode;
68 }
69 public function getMode()
70 {
71 return $this->mode;
72 }
73
74 public function performSearch()
75 {
76 switch($this->getMode())
77 {
78 case 'keyword':
79 return $this->__searchKeywords();
80
81 case 'contribute':
82 return $this->__searchContribute();
83
84 case 'title':
85 return $this->__searchTitles();
86
87 case 'description':
88 return $this->__searchDescriptions();
89
90 default:
91 echo __METHOD__.' no mode given';
92 return false;
93 }
94 }
95
96 private function __createInStatement()
97 {
98 if(!$this->getFilter())
99 {
100 return '';
101 }
102 else
103 {
104 return ' AND ' . $this->db->in('obj_type', $this->getFilter(), false, 'text');
105 }
106 }
107
108 private function __searchContribute()
109 {
110 $types = array();
111 $values = array();
112
113 $this->setFields(array('entity'));
114
115 $in = $this->__createInStatement();
116 $where = $this->__createContributeWhereCondition();
117 $locate = $this->__createLocateString();
118
119 $query = "SELECT object_reference.ref_id,rbac_id,il_meta_entity.obj_id,obj_type ".$locate."
120 FROM payment_objects
121 INNER JOIN object_reference ON object_reference.ref_id = payment_objects.ref_id
122 INNER JOIN il_meta_entity ON il_meta_entity.obj_id = object_reference.obj_id ";
123
124 $query .= $where['query'];
125 $types = array_merge($types, $where['types']);
126 $values = array_merge($values, $where['values']);
127 $query .= $in;
128
129 $query .= " GROUP BY object_reference.ref_id,il_meta_entity.obj_id,rbac_id,obj_type,il_meta_entity.entity ";
130
131 $statement = $this->db->queryf(
132 $query,
133 $types,
134 $values
135 );
136
137 while($row = $statement->fetchRow(DB_FETCHMODE_OBJECT))
138 {
139 $this->search_result->addEntry($row->ref_id,$row->obj_type,$this->__prepareFound($row),$row->obj_id);
140 }
141
143 }
144
145 private function __searchKeywords()
146 {
147 $types = array();
148 $values = array();
149
150 $this->setFields(array('keyword'));
151
152 $in = $this->__createInStatement();
153 $where = $this->__createKeywordWhereCondition();
154 $locate = $this->__createLocateString();
155
156 $query = "SELECT object_reference.ref_id,rbac_id,il_meta_keyword.obj_id,obj_type ".$locate."
157 FROM payment_objects
158 INNER JOIN object_reference ON object_reference.ref_id = payment_objects.ref_id
159 INNER JOIN il_meta_keyword ON il_meta_keyword.obj_id = object_reference.obj_id ";
160
161 $query .= $where['query'];
162 $types = array_merge($types, $where['types']);
163 $values = array_merge($values, $where['values']);
164 $query .= $in;
165
166 $query .= " GROUP BY object_reference.ref_id,il_meta_keyword.obj_id,rbac_id,obj_type,il_meta_keyword.keyword ";
167
168 $statement = $this->db->queryf(
169 $query,
170 $types,
171 $values
172 );
173
174 while($row = $statement->fetchRow(DB_FETCHMODE_OBJECT))
175 {
176 $this->search_result->addEntry($row->ref_id,$row->obj_type,$this->__prepareFound($row),$row->obj_id);
177 }
178
180 }
181
182 private function __searchTitles()
183 {
184 $types = array();
185 $values = array();
186
187 $this->setFields(array('title'));
188
189 $in = $this->__createInStatement();
190 $where = $this->__createTitleWhereCondition();
191 $locate = $this->__createLocateString();
192
193 $query = "SELECT object_reference.ref_id,rbac_id,il_meta_general.obj_id,obj_type ".$locate."
194 FROM payment_objects
195 INNER JOIN object_reference ON object_reference.ref_id = payment_objects.ref_id
196 INNER JOIN il_meta_general ON il_meta_general.obj_id = object_reference.obj_id ";
197
198 $query .= $where['query'];
199 $types = array_merge($types, $where['types']);
200 $values = array_merge($values, $where['values']);
201 $query .= $in;
202
203 $query .= " GROUP BY object_reference.ref_id,il_meta_general.obj_id,rbac_id,obj_type,il_meta_general.title ";
204
205 $statement = $this->db->queryf(
206 $query,
207 $types,
208 $values
209 );
210
211 while($row = $statement->fetchRow(DB_FETCHMODE_OBJECT))
212 {
213 $this->search_result->addEntry($row->ref_id,$row->obj_type,$this->__prepareFound($row),$row->obj_id);
214 }
215
217 }
218
219 private function __searchDescriptions()
220 {
221 $types = array();
222 $values = array();
223
224 $this->setFields(array('description'));
225
226 $in = $this->__createInStatement();
227 $where = $this->__createDescriptionWhereCondition();
228 $locate = $this->__createLocateString();
229
230 $query = "SELECT object_reference.ref_id,rbac_id,il_meta_description.obj_id,obj_type ".$locate."
231 FROM payment_objects
232 INNER JOIN object_reference ON object_reference.ref_id = payment_objects.ref_id
233 INNER JOIN il_meta_description ON il_meta_description.obj_id = object_reference.obj_id ";
234
235 $query .= $where['query'];
236 $types = array_merge($types, $where['types']);
237 $values = array_merge($values, $where['values']);
238 $query .= $in;
239
240 $query .= " GROUP BY object_reference.ref_id,il_meta_description.obj_id,rbac_id,obj_type,il_meta_description.description ";
241
242 $statement = $this->db->queryf(
243 $query,
244 $types,
245 $values
246 );
247
248 while($row = $statement->fetchRow(DB_FETCHMODE_OBJECT))
249 {
250 $this->search_result->addEntry($row->ref_id,$row->obj_type,$this->__prepareFound($row),$row->obj_id);
251 }
252
254 }
255
261 public function __createLocateString()
262 {
263 global $ilDB;
264
265 if($this->query_parser->getCombination() == 'or')
266 {
267 return '';
268 }
269
270 if(!strlen($this->query_parser->getQueryString()))
271 {
272 return '';
273 }
274
275 $locate = '';
276
277 if(count($this->fields) > 1)
278 {
279 $tmp_fields = array();
280 foreach($this->fields as $field)
281 {
282 $tmp_fields[] = array($field,'text');
283 }
284 $complete_str = $ilDB->concat($tmp_fields);
285 }
286 else
287 {
288 $complete_str = $this->fields[0];
289 }
290
291 $counter = 0;
292 foreach($this->query_parser->getQuotedWords() as $word)
293 {
294 $locate .= ',';
295 $locate .= $ilDB->locate($ilDB->quote($word, 'text'), $complete_str, 1);
296 $locate .= (' found'.$counter++);
297 $locate .= ' ';
298 }
299
300 return $locate;
301 }
302
303 public function __prepareFound(&$row)
304 {
305 if($this->query_parser->getCombination() == 'or')
306 {
307 return array();
308 }
309
310 if(!strlen($this->query_parser->getQueryString()))
311 {
312 return array();
313 }
314
315 $counter = 0;
316 foreach($this->query_parser->getQuotedWords() as $word)
317 {
318 $res_found = 'found'.$counter++;
319 $found[] = $row->$res_found;
320 }
321 return $found ? $found : array();
322 }
323}
324?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
setFields($a_fields)
Set fields to search.
getFilter()
get object type to search in
setCustomSearchResultObject($a_search_result_obect)
__createLocateString()
build locate string in case of AND search
global $ilDB
$errors fields
Definition: imgupload.php:48