• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

survey/classes/class.SurveySearch.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00024 define ("CONCAT_AND", 0);
00025 define ("CONCAT_OR", 1);
00026 
00038 class SurveySearch {
00046   var $search_terms;
00047 
00055   var $concatenation;
00056 
00064   var $search_field;
00065 
00073   var $search_type;
00074 
00082   var $search_results;
00083 
00091   var $ilDB;
00092 
00093 
00105   function SurveySearch(
00106     $search_text = "",
00107     $concatenation = CONCAT_AND,
00108     $search_field = "all",
00109                 $search_type = "all"
00110   )
00111 
00112   {
00113                 global $ilDB;
00114 
00115                 $this->ilDB =& $ilDB;
00116 
00117     $this->search_terms = split(" +", $search_text);
00118     $this->concatenation = $concatenation;
00119                 $this->search_field = $search_field;
00120     $this->search_type = $search_type;
00121                 $this->search_results = array();
00122         }
00123         
00131         function search()
00132         {
00133                 $where = "";
00134                 $fields = array();
00135                 if (strcmp($this->search_type, "all") != 0)
00136                 {
00137                         $where = sprintf("survey_questiontype.type_tag = %s",
00138                                 $this->ilDB->quote($this->search_type)
00139                         );
00140                 }
00141                 foreach ($this->search_terms as $term)
00142                 {
00143                         switch ($this->search_field)
00144                         {
00145                                 case "all":
00146                                         $fields["$term"] = array();
00147                                         array_push($fields["$term"], sprintf("survey_question.title LIKE %s",
00148                                                 $this->ilDB->quote("%$term%")
00149                                         ));
00150                                         array_push($fields["$term"], sprintf("survey_question.description LIKE %s",
00151                                                 $this->ilDB->quote("%$term%")
00152                                         ));
00153                                         array_push($fields["$term"], sprintf("survey_question.author LIKE %s",
00154                                                 $this->ilDB->quote("%$term%")
00155                                         ));
00156                                         array_push($fields["$term"], sprintf("survey_question.questiontext LIKE %s",
00157                                                 $this->ilDB->quote("%$term%")
00158                                         ));
00159                                         break;
00160                                 default:
00161                                         $fields["$term"] = array();
00162                                         array_push($fields["$term"], sprintf("survey_question.$this->search_field LIKE %s",
00163                                                 $this->ilDB->quote("%$term%")
00164                                         ));
00165                                         break;                          
00166                         }
00167                 }
00168                 $cumulated_fields = array();
00169                 foreach ($fields as $params)
00170                 {
00171                         array_push($cumulated_fields, "(" . join($params, " OR ") . ")");
00172                 }
00173                 $str_where = "";
00174                 if ($this->concatenation == CONCAT_AND)
00175                 {
00176                         $str_where = "(" . join($cumulated_fields, " AND ") . ")";
00177                 }
00178                 else
00179                 {
00180                         $str_where = "(" . join($cumulated_fields, " OR ") . ")";
00181                 }
00182                 if ($str_where)
00183                 {
00184                         $str_where = " AND $str_where";
00185                 }
00186                 if ($where)
00187                 {
00188                         $str_where .= " AND (" . $where . ")";
00189                 }
00190                 $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";
00191                 $result = $this->ilDB->query($query);
00192                 $result_array = array();
00193                 global $rbacsystem;
00194     if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00195                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00196                         {
00197                                 if (($row["complete"] == 1) and ($rbacsystem->checkAccess('write', $row["ref_id"])))
00198                                 {
00199                                         array_push($result_array, $row);
00200                                 }
00201                         }
00202                 }
00203                 $this->search_results =& $result_array;
00204         }
00205 }
00206 ?>

Generated on Fri Dec 13 2013 09:06:38 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1