ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.SurveySearch.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  public const CONCAT_AND = 0;
28  public const CONCAT_OR = 1;
29 
31 
32  // An array containing all search terms
33  public array $search_terms;
34 
35  // self::CONCAT_AND | self::CONCAT_OR
36  public int $concatenation;
37 
38  // database field to restrict the search results
39  public string $search_field;
40 
41  // A question type to restrict the search results
42  public string $search_type;
43 
44  // array containing the results of a search
45  public array $search_results;
46 
48 
49 
50  public function __construct(
51  string $search_text = "",
52  int $concatenation = self::CONCAT_AND,
53  string $search_field = "all",
54  string $search_type = "all"
55  ) {
56  global $DIC;
57 
58  $this->rbacsystem = $DIC->rbac()->system();
59  $ilDB = $DIC->database();
60 
61  $this->ilDB = $ilDB;
62 
63  $this->search_terms = explode(" +", $search_text);
64  $this->concatenation = $concatenation;
65  $this->search_field = $search_field;
66  $this->search_type = $search_type;
67  $this->search_results = array();
68  }
69 
70  // perform search and store results in $this->search_results
71  public function search(): void
72  {
73  $ilDB = $this->ilDB;
74 
75  $where = "";
76  $fields = array();
77  if (strcmp($this->search_type, "all") !== 0) {
78  $where = "svy_qtype.type_tag = " . $ilDB->quote($this->search_type, 'text');
79  }
80  foreach ($this->search_terms as $term) {
81  $fields[(string) $term] = array();
82  switch ($this->search_field) {
83  case "all":
84  $fields[(string) $term][] = $ilDB->like("svy_question.title", 'text', "%" . $term . "%");
85  $fields[(string) $term][] = $ilDB->like("svy_question.description", 'text', "%" . $term . "%");
86  $fields[(string) $term][] = $ilDB->like("svy_question.author", 'text', "%" . $term . "%");
87  $fields[(string) $term][] = $ilDB->like("svy_question.questiontext", 'text', "%" . $term . "%");
88  break;
89  default:
90  $fields[(string) $term][] = $ilDB->like("svy_question." . $this->search_field, 'text', "%" . $term . "%");
91  break;
92  }
93  }
94  $cumulated_fields = array();
95  foreach ($fields as $params) {
96  $cumulated_fields[] = "(" . implode(" OR ", $params) . ")";
97  }
98  $str_where = "";
99  if ($this->concatenation === self::CONCAT_AND) {
100  $str_where = "(" . implode(" AND ", $cumulated_fields) . ")";
101  } else {
102  $str_where = "(" . implode(" OR ", $cumulated_fields) . ")";
103  }
104  if ($str_where) {
105  $str_where = " AND $str_where";
106  }
107  if ($where) {
108  $str_where .= " AND (" . $where . ")";
109  }
110  $result = $ilDB->query("SELECT svy_question.*, svy_qtype.type_tag, object_reference.ref_id FROM " .
111  "svy_question, svy_qtype, object_reference WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id " .
112  "AND svy_question.original_id IS NULL AND svy_question.obj_fi = object_reference.obj_id AND " .
113  "svy_question.obj_fi > 0$str_where");
114  $result_array = array();
115  $rbacsystem = $this->rbacsystem;
116  if ($result->numRows() > 0) {
117  while ($row = $ilDB->fetchAssoc($result)) {
118  if (((int) $row["complete"]) === 1 && $rbacsystem->checkAccess('write', $row["ref_id"])) {
119  $result_array[] = $row;
120  }
121  }
122  }
123  $this->search_results = $result_array;
124  }
125 }
fetchAssoc(ilDBStatement $statement)
like(string $column, string $type, string $value="?", bool $case_insensitive=true)
Generate a like subquery.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
quote($value, string $type)
ilRbacSystem $rbacsystem
checkAccess(string $a_operations, int $a_ref_id, string $a_type="")
checkAccess represents the main method of the RBAC-system in ILIAS3 developers want to use With this ...
__construct(string $search_text="", int $concatenation=self::CONCAT_AND, string $search_field="all", string $search_type="all")
global $DIC
Definition: shib_login.php:22
query(string $query)
Run a (read-only) Query on the database.
ilDBInterface $ilDB
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...