ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
35{
36 const CONCAT_AND = 0;
37 const CONCAT_OR = 1;
38
47
56
65
74
83
91 var $ilDB;
92
93
105 function SurveySearch(
106 $search_text = "",
107 $concatenation = self::CONCAT_AND,
108 $search_field = "all",
109 $search_type = "all"
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 global $ilDB;
133
134 $where = "";
135 $fields = array();
136 if (strcmp($this->search_type, "all") != 0)
137 {
138 $where = "svy_qtype.type_tag = " . $ilDB->quote($this->search_type, 'text');
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"], $ilDB->like("svy_question.title", 'text', "%" .$term . "%"));
147 array_push($fields["$term"], $ilDB->like("svy_question.description", 'text', "%" .$term . "%"));
148 array_push($fields["$term"], $ilDB->like("svy_question.author", 'text', "%" .$term . "%"));
149 array_push($fields["$term"], $ilDB->like("svy_question.questiontext", 'text', "%" .$term . "%"));
150 break;
151 default:
152 $fields["$term"] = array();
153 array_push($fields["$term"], $ilDB->like("svy_question." . $this->search_field, 'text', "%" .$term . "%"));
154 break;
155 }
156 }
157 $cumulated_fields = array();
158 foreach ($fields as $params)
159 {
160 array_push($cumulated_fields, "(" . join($params, " OR ") . ")");
161 }
162 $str_where = "";
163 if ($this->concatenation == self::CONCAT_AND)
164 {
165 $str_where = "(" . join($cumulated_fields, " AND ") . ")";
166 }
167 else
168 {
169 $str_where = "(" . join($cumulated_fields, " OR ") . ")";
170 }
171 if ($str_where)
172 {
173 $str_where = " AND $str_where";
174 }
175 if ($where)
176 {
177 $str_where .= " AND (" . $where . ")";
178 }
179 $result = $ilDB->query("SELECT svy_question.*, svy_qtype.type_tag, object_reference.ref_id FROM " .
180 "svy_question, svy_qtype, object_reference WHERE svy_question.questiontype_fi = svy_qtype.questiontype_id ".
181 "AND svy_question.original_id IS NULL AND svy_question.obj_fi = object_reference.obj_id AND ".
182 "svy_question.obj_fi > 0$str_where");
183 $result_array = array();
184 global $rbacsystem;
185 if ($result->numRows() > 0)
186 {
187 while ($row = $ilDB->fetchAssoc($result))
188 {
189 if (($row["complete"] == 1) and ($rbacsystem->checkAccess('write', $row["ref_id"])))
190 {
191 array_push($result_array, $row);
192 }
193 }
194 }
195 $this->search_results =& $result_array;
196 }
197}
198
199?>
$result
Class for search actions in ILIAS survey tool.
search()
Executes a search.
SurveySearch( $search_text="", $concatenation=self::CONCAT_AND, $search_field="all", $search_type="all")
SurveySearch constructor.
Database Wrapper.
Definition: class.ilDB.php:29
$params
Definition: example_049.php:96