ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_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  }
47  return $this->search_result;
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 $DIC;
68 
69  $ilDB = $DIC['ilDB'];
70 
71  $fields = $this->getFields();
72  $field = $fields[0];
73 
74  $and = " WHERE field_id = " . $ilDB->quote($field, "text") . " AND ( ";
75  $counter = 0;
76  foreach ($this->query_parser->getQuotedWords() as $word) {
77  if ($counter++) {
78  $and .= " OR ";
79  }
80 
81  if (strpos($word, '^') === 0) {
82  $and .= $ilDB->like("value", "text", substr($word, 1) . "%");
83  } else {
84  $and .= $ilDB->like("value", "text", "%" . $word . "%");
85  }
86  }
87  return $and . ") ";
88  }
89 }
getFields()
Get fields to search.
global $DIC
Definition: saml.php:7
__createLocateString()
build locate string in case of AND search
foreach($_POST as $key=> $value) $res
__construct($qp_obj)
Constructor public.
$query
$row
global $ilDB