ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLikeUserMultiFieldSearch.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Search/classes/class.ilAbstractSearch.php';
5
18{
19
24 public function __construct($qp_obj)
25 {
26 parent::__construct($qp_obj);
27 }
28
33 public function performSearch()
34 {
35 $where = $this->__createWhereCondition();
36 $locate = $this->__createLocateString();
37
38 $query = "SELECT usr_id " .
39 $locate .
40 "FROM usr_data_multi " .
41 $where;
42
43 $res = $this->db->query($query);
44 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
45 $this->search_result->addEntry($row->usr_id, 'usr', $this->__prepareFound($row));
46 }
48 }
49
50
56 public function setFields($a_fields)
57 {
58 foreach ($a_fields as $field) {
59 $fields[] = $field;
60 }
61 parent::setFields($fields ? $fields : array());
62 }
63
64
65 public function __createWhereCondition()
66 {
67 global $ilDB;
68
69 $fields = $this->getFields();
70 $field = $fields[0];
71
72 $and = " WHERE field_id = " . $ilDB->quote($field, "text") . " AND ( ";
73 $counter = 0;
74 foreach ($this->query_parser->getQuotedWords() as $word) {
75 if ($counter++) {
76 $and .= " OR ";
77 }
78
79 if (strpos($word, '^') === 0) {
80 $and .= $ilDB->like("value", "text", substr($word, 1) . "%");
81 } else {
82 $and .= $ilDB->like("value", "text", "%" . $word . "%");
83 }
84 }
85 return $and . ") ";
86 }
87}
An exception for terminatinating execution or to throw for unit testing.
__createLocateString()
build locate string in case of AND search
getFields()
Get fields to search.
__construct($qp_obj)
Constructor @access public.
$counter
$query
foreach($_POST as $key=> $value) $res
global $ilDB