ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSearch Class Reference

search More...

+ Collaboration diagram for ilSearch:

Public Member Functions

 __construct ($a_user_id=0, $a_read=false)
 Constructor @access public. More...
 
 setSearchString ($a_search_str)
 
 setCombination ($a_combination)
 
 setSearchFor ($a_search_for)
 
 setSearchIn ($a_search_in)
 
 setResult ($a_result)
 
 setSearchType ($a_type)
 
 setPerformUpdate ($a_value)
 
 setEmptySearch ($a_value)
 
 setMinWordLength ($a_min_word_length)
 
 getMinWordLength ()
 
 getUserId ()
 
 getSearchString ()
 
 getCombination ()
 
 getSearchFor ()
 
 getSearchIn ()
 
 getSearchInByType ($a_type)
 
 getResults ()
 
 getResultByType ($a_type)
 
 getSearchType ()
 
 getPerformUpdate ()
 
 getEmptySearch ()
 
 getNumberOfResults ()
 
 validate (&$message)
 
 performSearch ()
 
 __parseSearchString ()
 
 __updateDBResult ()
 
 __readDBResult ()
 
 __checkAccess ($a_results, $a_type)
 
 __validateResults ()
 
 __prepareWord ($a_word)
 

Data Fields

 $ilias
 
 $lng
 
 $rbacsystem
 
 $user_id
 
 $search_string
 
 $parsed_str
 
 $combination
 
 $min_word_length = 3
 
 $search_for
 
 $search_in
 
 $search_type
 
 $result
 
 $perform_update
 
 $read_db_result
 
 $allow_empty_search
 

Protected Member Functions

 performUserSearch ()
 perform a search for users More...
 
 performObjectSearch ($a_type)
 perform object search More...
 
 performRoleSearch ()
 
 initQueryParser ()
 init query parser More...
 

Protected Attributes

 $qp = null
 

Detailed Description

search

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id$

Definition at line 14 of file class.ilSearch.php.

Constructor & Destructor Documentation

◆ __construct()

ilSearch::__construct (   $a_user_id = 0,
  $a_read = false 
)

Constructor @access public.

Definition at line 43 of file class.ilSearch.php.

44 {
45 global $ilias,$rbacsystem,$lng;
46
47 // Initiate variables
48 $this->ilias =&$ilias;
49 $this->lng =&$lng;
50 $this->lng->loadLanguageModule("search");
51 $this->rbacsystem =&$rbacsystem;
52 $this->user_id = $a_user_id;
53
54 $this->setPerformUpdate(true);
55 $this->setEmptySearch(false);
56 $this->read_db_result = $a_read;
57
58 // READ OLD SEARCH RESULTS FROM DATABASE
59 #$this->__readDBResult();
60 }
setEmptySearch($a_value)
setPerformUpdate($a_value)
redirection script todo: (a better solution should control the processing via a xml file)

References $ilias, $lng, $rbacsystem, setEmptySearch(), and setPerformUpdate().

+ Here is the call graph for this function:

Member Function Documentation

◆ __checkAccess()

ilSearch::__checkAccess (   $a_results,
  $a_type 
)

Definition at line 329 of file class.ilSearch.php.

330 {
331 global $ilAccess;
332
333 if (is_array($a_results)) {
334 foreach ($a_results as $result) {
335 if ($ilAccess->checkAccess('read', '', $result['id'])) {
336 $checked_result[] = $result;
337 break;
338 }
339 }
340 }
341 return $checked_result ? $checked_result : array();
342 }

References $result.

Referenced by __validateResults().

+ Here is the caller graph for this function:

◆ __parseSearchString()

ilSearch::__parseSearchString ( )

Definition at line 235 of file class.ilSearch.php.

236 {
237 $tmp_arr = explode(" ", $this->getSearchString());
238 $this->parsed_str["and"] = $this->parsed_str["or"] = $this->parsed_str["not"] = array();
239
240 foreach ($tmp_arr as $word) {
241 #$word = trim($word);
242 $word = $this->__prepareWord($word);
243 if ($word) {
244 if (substr($word, 0, 1) == '+') {
245 $this->parsed_str["all"][] = substr($word, 1);
246 $this->parsed_str["and"][] = substr($word, 1);
247 continue;
248 }
249
250 if (substr($word, 0, 1) == '-') {
251 // better parsed_str["allmost_all"] ;-)
252 #$this->parsed_str["all"][] = substr($word,1);
253 $this->parsed_str["not"][] = substr($word, 1);
254 continue;
255 }
256
257 if ($this->getCombination() == 'and') {
258 $this->parsed_str["all"][] = $word;
259 $this->parsed_str["and"][] = $word;
260 continue;
261 }
262
263 if ($this->getCombination() == 'or') {
264 $this->parsed_str["all"][] = $word;
265 $this->parsed_str["or"][] = $word;
266 continue;
267 }
268 }
269 }
270 }
__prepareWord($a_word)

References __prepareWord(), getCombination(), and getSearchString().

+ Here is the call graph for this function:

◆ __prepareWord()

ilSearch::__prepareWord (   $a_word)

Definition at line 413 of file class.ilSearch.php.

414 {
415 $word = trim($a_word);
416
417 if (!preg_match('/\*/', $word)) {
418 return '%' . $word . '%';
419 }
420 if (preg_match('/^\*/', $word)) {
421 return str_replace('*', '%', $word);
422 } else {
423 return '% ' . str_replace('*', '%', $word);
424 }
425 }

Referenced by __parseSearchString().

+ Here is the caller graph for this function:

◆ __readDBResult()

ilSearch::__readDBResult ( )

Definition at line 297 of file class.ilSearch.php.

298 {
299 global $ilDB;
300
301 if ($this->getUserId() != 0 and $this->getUserId() != ANONYMOUS_USER_ID and $this->read_db_result) {
302 $query = "SELECT search_result FROM usr_search " .
303 "WHERE usr_id = " . $ilDB->quote($this->getUserId(), 'integer');
304
305
306 $res = $ilDB->query($query);
307 if ($res->numRows()) {
309 $this->setResult(unserialize(stripslashes($row->search_result)));
310 } else {
311 $this->setResult(array("usr" => array(),
312 "grp" => array(),
313 "lm" => array(),
314 "dbk" => array()));
315 }
316 } else {
317 $this->setResult(array("usr" => array(),
318 "grp" => array(),
319 "lm" => array(),
320 "dbk" => array()));
321 }
322
323 $this->__validateResults();
324 $this->__updateDBResult();
325 return true;
326 }
setResult($a_result)
$query
foreach($_POST as $key=> $value) $res
global $ilDB

References $ilDB, $query, $res, $row, __updateDBResult(), __validateResults(), ilDBConstants\FETCHMODE_OBJECT, getUserId(), and setResult().

+ Here is the call graph for this function:

◆ __updateDBResult()

ilSearch::__updateDBResult ( )

Definition at line 272 of file class.ilSearch.php.

273 {
274 global $ilDB;
275
276 if ($this->getUserId() != 0 and $this->getUserId() != ANONYMOUS_USER_ID) {
277 $ilDB->manipulate("DELETE FROM usr_search " .
278 "WHERE usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " " .
279 "AND search_type = 0 ");
280
281 $ilDB->insert('usr_search', array(
282 'usr_id' => array('integer',$this->getUserId()),
283 'search_result' => array('clob',serialize($this->getResults())),
284 'checked' => array('clob',serialize(array())),
285 'failed' => array('clob',serialize(array())),
286 'page' => array('integer',0),
287 'search_type' => array('integer',0),
288 'query' => array('text',''),
289 'root' => array('integer',ROOT_FOLDER_ID)));
290
291 return true;
292 }
293
294 return false;
295 }

References $ilDB, getResults(), and getUserId().

Referenced by __readDBResult(), and performSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __validateResults()

ilSearch::__validateResults ( )

Definition at line 345 of file class.ilSearch.php.

346 {
347 global $tree;
348
349 $new_result = array();
350
351
352 // check lm meta
353
354 $this->result['lm']['meta'] = $this->__checkAccess($this->result['lm']['meta'], 'lm');
355 if (is_array($this->result['lm']['meta'])) {
356 foreach ($this->result['lm']['meta'] as $data) {
357 if ($tree->isInTree($data['id'])) {
358 $new_result['lm']['meta'][] = $data;
359 }
360 }
361 }
362 $this->result['lm']['content'] = $this->__checkAccess($this->result['lm']['content'], 'lm');
363 if (is_array($this->result['lm']['content'])) {
364 foreach ($this->result['lm']['content'] as $data) {
365 if ($tree->isInTree($data['id'])) {
366 $new_result['lm']['content'][] = $data;
367 }
368 }
369 }
370 $this->result['dbk']['meta'] = $this->__checkAccess($this->result['dbk']['meta'], 'dbk');
371 if (is_array($this->result['dbk']['meta'])) {
372 foreach ($this->result['dbk']['meta'] as $data) {
373 if ($tree->isInTree($data['id'])) {
374 $new_result['dbk']['meta'][] = $data;
375 }
376 }
377 }
378 $this->result['dbk']['content'] = $this->__checkAccess($this->result['dbk']['content'], 'dbk');
379 if (is_array($this->result['dbk']['content'])) {
380 foreach ($this->result['dbk']['content'] as $data) {
381 if ($tree->isInTree($data['id'])) {
382 $new_result['dbk']['content'][] = $data;
383 }
384 }
385 }
386 $this->result['grp'] = $this->__checkAccess($this->result['grp'], 'grp');
387 if (is_array($this->result['grp'])) {
388 foreach ($this->result['grp'] as $data) {
389 if ($tree->isInTree($data['id'])) {
390 $new_result['grp'][] = $data;
391 }
392 }
393 }
394 if (is_array($this->result['usr'])) {
395 foreach ($this->result['usr'] as $user) {
396 if ($tmp_obj =&ilObjectFactory::getInstanceByObjId($user['id'], false)) {
397 $new_result['usr'][] = $user;
398 }
399 }
400 }
401 if (is_array($this->result['role'])) {
402 foreach ($this->result['role'] as $user) {
403 if ($tmp_obj =&ilObjectFactory::getInstanceByObjId($user['id'], false)) {
404 $new_result['role'][] = $user;
405 }
406 }
407 }
408 $this->setResult($new_result);
409
410 return true;
411 }
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
__checkAccess($a_results, $a_type)

References $data, __checkAccess(), ilObjectFactory\getInstanceByObjId(), and setResult().

Referenced by __readDBResult(), and performSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCombination()

ilSearch::getCombination ( )

Definition at line 115 of file class.ilSearch.php.

116 {
117 return $this->combination ? $this->combination : "or";
118 }

Referenced by __parseSearchString(), initQueryParser(), and performObjectSearch().

+ Here is the caller graph for this function:

◆ getEmptySearch()

ilSearch::getEmptySearch ( )

Definition at line 151 of file class.ilSearch.php.

152 {
154 }

References $allow_empty_search.

◆ getMinWordLength()

ilSearch::getMinWordLength ( )

Definition at line 101 of file class.ilSearch.php.

102 {
104 }

References $min_word_length.

Referenced by initQueryParser().

+ Here is the caller graph for this function:

◆ getNumberOfResults()

ilSearch::getNumberOfResults ( )

Definition at line 158 of file class.ilSearch.php.

159 {
160 $number = count($this->getResultByType("usr")) + count($this->getResultByType("grp")) + count($this->getResultByType("role"));
161
162 $tmp_res = $this->getResultByType("dbk");
163 $number += count($tmp_res["meta"]) + count($tmp_res["content"]);
164
165 $tmp_res = $this->getResultByType("lm");
166 $number += count($tmp_res["meta"]) + count($tmp_res["content"]);
167
168 return $number;
169 }
getResultByType($a_type)

References getResultByType().

+ Here is the call graph for this function:

◆ getPerformUpdate()

ilSearch::getPerformUpdate ( )

Definition at line 147 of file class.ilSearch.php.

148 {
150 }

References $perform_update.

Referenced by performSearch().

+ Here is the caller graph for this function:

◆ getResultByType()

ilSearch::getResultByType (   $a_type)

Definition at line 139 of file class.ilSearch.php.

140 {
141 return $this->result[$a_type] ? $this->result[$a_type] : array();
142 }
$a_type
Definition: workflow.php:92

References $a_type.

Referenced by getNumberOfResults().

+ Here is the caller graph for this function:

◆ getResults()

ilSearch::getResults ( )

Definition at line 135 of file class.ilSearch.php.

136 {
137 return $this->result ? $this->result : array();
138 }

Referenced by __updateDBResult().

+ Here is the caller graph for this function:

◆ getSearchFor()

ilSearch::getSearchFor ( )

Definition at line 119 of file class.ilSearch.php.

120 {
121 return $this->search_for ? $this->search_for : array();
122 }

Referenced by performSearch().

+ Here is the caller graph for this function:

◆ getSearchIn()

ilSearch::getSearchIn ( )

Definition at line 123 of file class.ilSearch.php.

124 {
125 return $this->search_in ? $this->search_in : array();
126 }

◆ getSearchInByType()

ilSearch::getSearchInByType (   $a_type)

Definition at line 127 of file class.ilSearch.php.

128 {
129 if ($a_type == 'lm' or $a_type == 'dbk') {
130 return $this->search_in[$a_type];
131 } else {
132 return false;
133 }
134 }

References $a_type.

◆ getSearchString()

ilSearch::getSearchString ( )

Definition at line 111 of file class.ilSearch.php.

112 {
114 }

References $search_string.

Referenced by __parseSearchString(), and initQueryParser().

+ Here is the caller graph for this function:

◆ getSearchType()

ilSearch::getSearchType ( )

Definition at line 143 of file class.ilSearch.php.

144 {
145 return $this->search_type;
146 }

References $search_type.

◆ getUserId()

ilSearch::getUserId ( )

Definition at line 107 of file class.ilSearch.php.

108 {
109 return $this->user_id;
110 }

References $user_id.

Referenced by __readDBResult(), __updateDBResult(), and performUserSearch().

+ Here is the caller graph for this function:

◆ initQueryParser()

ilSearch::initQueryParser ( )
protected

init query parser

Returns

Definition at line 496 of file class.ilSearch.php.

497 {
498 if ($this->qp) {
499 return true;
500 }
501
502 $this->qp = new ilQueryParser($this->getSearchString());
503 $this->qp->setCombination($this->getCombination() == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
504 $this->qp->setMinWordLength($this->getMinWordLength());
505 $this->qp->parse();
506 }
const QP_COMBINATION_OR
const QP_COMBINATION_AND

References getCombination(), getMinWordLength(), getSearchString(), QP_COMBINATION_AND, and QP_COMBINATION_OR.

Referenced by performSearch(), and validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ performObjectSearch()

ilSearch::performObjectSearch (   $a_type)
protected

perform object search

Returns

Definition at line 457 of file class.ilSearch.php.

458 {
459 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
460 $object_search = new ilLikeObjectSearch($this->qp);
461 $object_search->setFilter(array($a_type));
462 $res = $object_search->performSearch();
463 $res->filter(ROOT_FOLDER_ID, $this->getCombination());
464
465 $counter = 0;
466 foreach ($res->getResultIds() as $id) {
467 $objs[$counter++]['id'] = $id;
468 }
469 return $objs ? $objs : array();
470 }
$counter
if(!array_key_exists('StateId', $_REQUEST)) $id

References $a_type, $counter, $id, $res, and getCombination().

Referenced by performSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ performRoleSearch()

ilSearch::performRoleSearch ( )
protected
Parameters

return

Definition at line 477 of file class.ilSearch.php.

478 {
479 // Perform like search
480 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
481 $object_search = new ilLikeObjectSearch($this->qp);
482 $object_search->setFilter(array('role'));
483
484 $res = $object_search->performSearch();
485 foreach ($res->getEntries() as $id => $data) {
486 $tmp['id'] = $id;
487 $roles[] = $tmp;
488 }
489 return $roles ? $roles : array();
490 }

References $data, $id, and $res.

Referenced by performSearch().

+ Here is the caller graph for this function:

◆ performSearch()

ilSearch::performSearch ( )

Definition at line 182 of file class.ilSearch.php.

183 {
184 global $objDefinition, $ilBench;
185
186 $ilBench->start("Search", "performSearch");
187
188 $this->initQueryParser();
189
190 $result = array("usr" => array(),
191 "grp" => array(),
192 "lm" => array(),
193 "dbk" => array(),
194 "role"=> array());
195
196 foreach ($this->getSearchFor() as $obj_type) {
197 switch ($obj_type) {
198 case "usr":
199 $result['usr'] = $this->performUserSearch();
200 break;
201
202 case "grp":
203 $result['grp'] = $this->performObjectSearch('grp');
204 break;
205
206 case "lm":
207 $result['lm'] = $this->performObjectSearch('lm');
208 break;
209
210 case "dbk":
211 $result['dbk'] = $this->performObjectSearch('dbk');
212 break;
213
214 case "role":
215 $result['role'] = $this->performRoleSearch();
216 break;
217 }
218 }
219
220 $this->setResult($result);
221 $this->__validateResults();
222
223 if ($this->getPerformUpdate()) {
224 $this->__updateDBResult();
225 }
226
227 $ilBench->stop("Search", "performSearch");
228
229 return true;
230 }
initQueryParser()
init query parser
performObjectSearch($a_type)
perform object search
performUserSearch()
perform a search for users
global $ilBench
Definition: ilias.php:18

References $ilBench, $result, __updateDBResult(), __validateResults(), getPerformUpdate(), getSearchFor(), initQueryParser(), performObjectSearch(), performRoleSearch(), performUserSearch(), and setResult().

+ Here is the call graph for this function:

◆ performUserSearch()

ilSearch::performUserSearch ( )
protected

perform a search for users

Returns

Definition at line 431 of file class.ilSearch.php.

432 {
433 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
434
435 $user_search = ilObjectSearchFactory::_getUserSearchInstance($this->qp);
436 $res = new ilSearchResult($this->getUserId());
437
438 foreach (array("login","firstname","lastname","title",
439 "email","institution","street","city","zipcode","country","phone_home","fax") as $field) {
440 $user_search->setFields(array($field));
441 $tmp_res = $user_search->performSearch();
442
443 $res->mergeEntries($tmp_res);
444 }
445
446 foreach ($res->getEntries() as $id => $data) {
447 $tmp['id'] = $id;
448 $users[] = $tmp;
449 }
450 return $users ? $users : array();
451 }
$users
Definition: authpage.php:44
static _getUserSearchInstance($query_parser)
get reference of ilLikeUserSearch

References $data, $id, $res, $users, ilObjectSearchFactory\_getUserSearchInstance(), and getUserId().

Referenced by performSearch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCombination()

ilSearch::setCombination (   $a_combination)

Definition at line 67 of file class.ilSearch.php.

68 {
69 // 'and' or 'or'
70 $this->combination = $a_combination;
71 }

◆ setEmptySearch()

ilSearch::setEmptySearch (   $a_value)

Definition at line 92 of file class.ilSearch.php.

93 {
94 $this->allow_empty_search = $a_value;
95 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setMinWordLength()

ilSearch::setMinWordLength (   $a_min_word_length)

Definition at line 97 of file class.ilSearch.php.

98 {
99 $this->min_word_length = $a_min_word_length;
100 }

◆ setPerformUpdate()

ilSearch::setPerformUpdate (   $a_value)

Definition at line 88 of file class.ilSearch.php.

89 {
90 $this->perform_update = $a_value;
91 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setResult()

ilSearch::setResult (   $a_result)

Definition at line 80 of file class.ilSearch.php.

81 {
82 $this->result = $a_result;
83 }

Referenced by __readDBResult(), __validateResults(), and performSearch().

+ Here is the caller graph for this function:

◆ setSearchFor()

ilSearch::setSearchFor (   $a_search_for)

Definition at line 72 of file class.ilSearch.php.

73 {
74 $this->search_for = $a_search_for;
75 }

◆ setSearchIn()

ilSearch::setSearchIn (   $a_search_in)

Definition at line 76 of file class.ilSearch.php.

77 {
78 $this->search_in = $a_search_in;
79 }

◆ setSearchString()

ilSearch::setSearchString (   $a_search_str)

Definition at line 63 of file class.ilSearch.php.

64 {
65 $this->search_string = trim($a_search_str);
66 }

◆ setSearchType()

ilSearch::setSearchType (   $a_type)

Definition at line 84 of file class.ilSearch.php.

85 {
86 $this->search_type = $a_type;
87 }

References $a_type.

◆ validate()

ilSearch::validate ( $message)

Definition at line 171 of file class.ilSearch.php.

172 {
173 $this->initQueryParser();
174
175 if (!$this->qp->validate()) {
176 $message = $this->qp->getMessage();
177 return false;
178 }
179 return true;
180 }
catch(Exception $e) $message

References $message, and initQueryParser().

+ Here is the call graph for this function:

Field Documentation

◆ $allow_empty_search

ilSearch::$allow_empty_search

Definition at line 38 of file class.ilSearch.php.

Referenced by getEmptySearch().

◆ $combination

ilSearch::$combination

Definition at line 29 of file class.ilSearch.php.

◆ $ilias

ilSearch::$ilias

Definition at line 23 of file class.ilSearch.php.

Referenced by __construct().

◆ $lng

ilSearch::$lng

Definition at line 24 of file class.ilSearch.php.

Referenced by __construct().

◆ $min_word_length

ilSearch::$min_word_length = 3

Definition at line 30 of file class.ilSearch.php.

Referenced by getMinWordLength().

◆ $parsed_str

ilSearch::$parsed_str

Definition at line 28 of file class.ilSearch.php.

◆ $perform_update

ilSearch::$perform_update

Definition at line 35 of file class.ilSearch.php.

Referenced by getPerformUpdate().

◆ $qp

ilSearch::$qp = null
protected

Definition at line 16 of file class.ilSearch.php.

◆ $rbacsystem

ilSearch::$rbacsystem

Definition at line 25 of file class.ilSearch.php.

Referenced by __construct().

◆ $read_db_result

ilSearch::$read_db_result

Definition at line 36 of file class.ilSearch.php.

◆ $result

ilSearch::$result

Definition at line 34 of file class.ilSearch.php.

Referenced by __checkAccess(), and performSearch().

◆ $search_for

ilSearch::$search_for

Definition at line 31 of file class.ilSearch.php.

◆ $search_in

ilSearch::$search_in

Definition at line 32 of file class.ilSearch.php.

◆ $search_string

ilSearch::$search_string

Definition at line 27 of file class.ilSearch.php.

Referenced by getSearchString().

◆ $search_type

ilSearch::$search_type

Definition at line 33 of file class.ilSearch.php.

Referenced by getSearchType().

◆ $user_id

ilSearch::$user_id

Definition at line 26 of file class.ilSearch.php.

Referenced by getUserId().


The documentation for this class was generated from the following file: