ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLikeUserMultiFieldSearch.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
6 
18 {
19  public function performSearch(): ilSearchResult
20  {
21  $where = $this->__createWhereCondition();
22  $locate = $this->__createLocateString();
23 
24  $query = "SELECT usr_id " .
25  $locate .
26  "FROM usr_data_multi " .
27  $where;
28 
29  $res = $this->db->query($query);
30  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
31  $this->search_result->addEntry($row->usr_id, 'usr', $this->__prepareFound($row));
32  }
33  return $this->search_result;
34  }
35 
36 
37  public function setFields(array $a_fields): void
38  {
39  $fields = [];
40  foreach ($a_fields as $field) {
41  $fields[] = $field;
42  }
43  parent::setFields($fields);
44  }
45 
46 
47  public function __createWhereCondition(): string
48  {
49  $fields = $this->getFields();
50  $field = $fields[0];
51 
52  $and = " WHERE field_id = " . $this->db->quote($field, "text") . " AND ( ";
53  $counter = 0;
54  foreach ($this->query_parser->getQuotedWords() as $word) {
55  if ($counter++) {
56  $and .= " OR ";
57  }
58 
59  if (strpos($word, '^') === 0) {
60  $and .= $this->db->like("value", "text", substr($word, 1) . "%");
61  } else {
62  $and .= $this->db->like("value", "text", "%" . $word . "%");
63  }
64  }
65  return $and . ") ";
66  }
67 }
$res
Definition: ltiservices.php:69
$query
ilSearchResult $search_result