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

Modules/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 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
00025 
00036 class SurveySearch 
00037 {
00045   var $search_terms;
00046 
00054   var $concatenation;
00055 
00063   var $search_field;
00064 
00072   var $search_type;
00073 
00081   var $search_results;
00082 
00090   var $ilDB;
00091 
00092 
00104   function SurveySearch(
00105     $search_text = "",
00106     $concatenation = CONCAT_AND,
00107     $search_field = "all",
00108                 $search_type = "all"
00109   )
00110 
00111   {
00112                 global $ilDB;
00113 
00114                 $this->ilDB =& $ilDB;
00115 
00116     $this->search_terms = split(" +", $search_text);
00117     $this->concatenation = $concatenation;
00118                 $this->search_field = $search_field;
00119     $this->search_type = $search_type;
00120                 $this->search_results = array();
00121         }
00122         
00130         function search()
00131         {
00132                 $where = "";
00133                 $fields = array();
00134                 if (strcmp($this->search_type, "all") != 0)
00135                 {
00136                         $where = sprintf("survey_questiontype.type_tag = %s",
00137                                 $this->ilDB->quote($this->search_type)
00138                         );
00139                 }
00140                 foreach ($this->search_terms as $term)
00141                 {
00142                         switch ($this->search_field)
00143                         {
00144                                 case "all":
00145                                         $fields["$term"] = array();
00146                                         array_push($fields["$term"], sprintf("survey_question.title LIKE %s",
00147                                                 $this->ilDB->quote("%$term%")
00148                                         ));
00149                                         array_push($fields["$term"], sprintf("survey_question.description LIKE %s",
00150                                                 $this->ilDB->quote("%$term%")
00151                                         ));
00152                                         array_push($fields["$term"], sprintf("survey_question.author LIKE %s",
00153                                                 $this->ilDB->quote("%$term%")
00154                                         ));
00155                                         array_push($fields["$term"], sprintf("survey_question.questiontext LIKE %s",
00156                                                 $this->ilDB->quote("%$term%")
00157                                         ));
00158                                         break;
00159                                 default:
00160                                         $fields["$term"] = array();
00161                                         array_push($fields["$term"], sprintf("survey_question.$this->search_field LIKE %s",
00162                                                 $this->ilDB->quote("%$term%")
00163                                         ));
00164                                         break;                          
00165                         }
00166                 }
00167                 $cumulated_fields = array();
00168                 foreach ($fields as $params)
00169                 {
00170                         array_push($cumulated_fields, "(" . join($params, " OR ") . ")");
00171                 }
00172                 $str_where = "";
00173                 if ($this->concatenation == CONCAT_AND)
00174                 {
00175                         $str_where = "(" . join($cumulated_fields, " AND ") . ")";
00176                 }
00177                 else
00178                 {
00179                         $str_where = "(" . join($cumulated_fields, " OR ") . ")";
00180                 }
00181                 if ($str_where)
00182                 {
00183                         $str_where = " AND $str_where";
00184                 }
00185                 if ($where)
00186                 {
00187                         $str_where .= " AND (" . $where . ")";
00188                 }
00189                 $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";
00190                 $result = $this->ilDB->query($query);
00191                 $result_array = array();
00192                 global $rbacsystem;
00193     if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00194                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00195                         {
00196                                 if (($row["complete"] == 1) and ($rbacsystem->checkAccess('write', $row["ref_id"])))
00197                                 {
00198                                         array_push($result_array, $row);
00199                                 }
00200                         }
00201                 }
00202                 $this->search_results =& $result_array;
00203         }
00204 }
00205 ?>

Generated on Fri Dec 13 2013 17:56:52 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1