ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveySearch.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
25 
37 {
46 
55 
64 
73 
82 
90  var $ilDB;
91 
92 
104  function SurveySearch(
105  $search_text = "",
107  $search_field = "all",
108  $search_type = "all"
109  )
110 
111  {
112  global $ilDB;
113 
114  $this->ilDB =& $ilDB;
115 
116  $this->search_terms = split(" +", $search_text);
117  $this->concatenation = $concatenation;
118  $this->search_field = $search_field;
119  $this->search_type = $search_type;
120  $this->search_results = array();
121  }
122 
130  function search()
131  {
132  $where = "";
133  $fields = array();
134  if (strcmp($this->search_type, "all") != 0)
135  {
136  $where = sprintf("survey_questiontype.type_tag = %s",
137  $this->ilDB->quote($this->search_type)
138  );
139  }
140  foreach ($this->search_terms as $term)
141  {
142  switch ($this->search_field)
143  {
144  case "all":
145  $fields["$term"] = array();
146  array_push($fields["$term"], sprintf("survey_question.title LIKE %s",
147  $this->ilDB->quote("%$term%")
148  ));
149  array_push($fields["$term"], sprintf("survey_question.description LIKE %s",
150  $this->ilDB->quote("%$term%")
151  ));
152  array_push($fields["$term"], sprintf("survey_question.author LIKE %s",
153  $this->ilDB->quote("%$term%")
154  ));
155  array_push($fields["$term"], sprintf("survey_question.questiontext LIKE %s",
156  $this->ilDB->quote("%$term%")
157  ));
158  break;
159  default:
160  $fields["$term"] = array();
161  array_push($fields["$term"], sprintf("survey_question.$this->search_field LIKE %s",
162  $this->ilDB->quote("%$term%")
163  ));
164  break;
165  }
166  }
167  $cumulated_fields = array();
168  foreach ($fields as $params)
169  {
170  array_push($cumulated_fields, "(" . join($params, " OR ") . ")");
171  }
172  $str_where = "";
173  if ($this->concatenation == CONCAT_AND)
174  {
175  $str_where = "(" . join($cumulated_fields, " AND ") . ")";
176  }
177  else
178  {
179  $str_where = "(" . join($cumulated_fields, " OR ") . ")";
180  }
181  if ($str_where)
182  {
183  $str_where = " AND $str_where";
184  }
185  if ($where)
186  {
187  $str_where .= " AND (" . $where . ")";
188  }
189  $query = "SELECT survey_question.*, survey_questiontype.type_tag, object_reference.ref_id FROM survey_question, survey_questiontype, object_reference WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND ISNULL(survey_question.original_id) AND survey_question.obj_fi = object_reference.obj_id AND survey_question.obj_fi > 0$str_where";
190  $result = $this->ilDB->query($query);
191  $result_array = array();
192  global $rbacsystem;
193  if ($result->numRows() > 0)
194  {
195  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
196  {
197  if (($row["complete"] == 1) and ($rbacsystem->checkAccess('write', $row["ref_id"])))
198  {
199  array_push($result_array, $row);
200  }
201  }
202  }
203  $this->search_results =& $result_array;
204  }
205 }
206 ?>