ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilAbstractSearch.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
32 abstract class ilAbstractSearch
33 {
34  protected ilDBInterface $db;
37 
41  protected array $object_types = [];
42 
46  private array $id_filter = [];
47 
51  private array $fields = [];
52 
53 
54 
55  public function __construct(ilQueryParser $qp_obj)
56  {
57  global $DIC;
58 
59  $this->db = $DIC->database();
60  $this->query_parser = $qp_obj;
61  $this->search_result = new ilSearchResult();
62 
63  $this->object_types = $this->getValidObjectTypes($DIC['objDefinition']);
64  }
65 
66  protected function getValidObjectTypes(ilObjectDefinition $object_definition): array
67  {
68  $valid_types = [];
69  foreach ($object_definition->getAllObjects() as $type) {
70  if (
71  !$object_definition->isSystemObject($type) &&
72  !$object_definition->isAdministrationObject($type) &&
73  !$object_definition->isSideBlock($type) &&
74  $object_definition->isRBACObject($type) &&
75  $object_definition->isAllowedInRepository($type)
76  ) {
77  $valid_types[] = $type;
78  }
79  }
80 
81  $grouped_types = [];
82  foreach ($object_definition->getAllObjects() as $type) {
83  if (in_array($object_definition->getGroupOfObj($type), $valid_types)) {
84  $grouped_types[] = $type;
85  }
86  }
87 
88  return array_unique(array_merge($valid_types, $grouped_types));
89  }
90 
91  public function setFields(array $a_fields): void
92  {
93  $this->fields = $a_fields;
94  }
95 
99  public function getFields(): array
100  {
101  return $this->fields;
102  }
103 
104  public function setFilter(array $a_filter): void
105  {
106  $this->object_types = $a_filter;
107  }
108 
109  public function setIdFilter(array $a_id_filter): void
110  {
111  $this->id_filter = $a_id_filter;
112  }
113 
117  public function getIdFilter(): array
118  {
119  return $this->id_filter;
120  }
121 
122  public function appendToFilter(string $a_type): void
123  {
124  if (!in_array($a_type, $this->object_types)) {
125  $this->object_types[] = $a_type;
126  }
127  }
128 
129 
133  public function getFilter(): array
134  {
135  return $this->object_types;
136  }
137 
138  public function __createLocateString(): string
139  {
140  if ($this->query_parser->getCombination() == ilQueryParser::QP_COMBINATION_OR) {
141  return '';
142  }
143  if (count($this->fields) > 1) {
144  $tmp_fields = [];
145  foreach ($this->fields as $field) {
146  $tmp_fields[] = array($field,'text');
147  }
148  $complete_str = $this->db->concat($tmp_fields);
149  } else {
150  $complete_str = $this->fields[0];
151  }
152 
153  $counter = 0;
154  $locate = '';
155  foreach ($this->query_parser->getQuotedWords() as $word) {
156  $word = str_replace('\%', '%', $word);
157  $word = str_replace('\_', '_', $word);
158 
159  $locate .= ',';
160  $locate .= $this->db->locate($this->db->quote($word, 'text'), $complete_str);
161  $locate .= (' found' . $counter++);
162  $locate .= ' ';
163  }
164 
165  return $locate;
166  }
167 
168  public function __prepareFound(object $row): array
169  {
170  if ($this->query_parser->getCombination() == 'or') {
171  return array();
172  }
173  $counter = 0;
174  $found = [];
175  foreach ($this->query_parser->getQuotedWords() as $word) {
176  $res_found = "found" . $counter++;
177  $found[] = (int) $row->$res_found;
178  }
179  return $found;
180  }
181 
182  abstract public function performSearch(): ?ilSearchResult;
183 }
isSystemObject(string $obj_name)
checks if object type is a system object
isAdministrationObject(string $obj_name)
Check if administration object.
getValidObjectTypes(ilObjectDefinition $object_definition)
getGroupOfObj(string $obj_name)
Get Group of object type.
isRBACObject(string $obj_name)
get RBAC status by type returns true if object type is a RBAC object type
setFields(array $a_fields)
__construct(ilQueryParser $qp_obj)
isAllowedInRepository(string $obj_name)
checks if object type can be used in repository context
global $DIC
Definition: shib_login.php:22
isSideBlock(string $obj_name)
Check, whether object type is a side block.
appendToFilter(string $a_type)
getAllObjects()
get all object types
setFilter(array $a_filter)
ilSearchResult $search_result
setIdFilter(array $a_id_filter)