Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00035 class ilUserSearchCache
00036 {
00037 const DEFAULT_SEARCH = 0;
00038 const ADVANCED_SEARCH = 1;
00039 const ADVANCED_MD_SEARCH = 4;
00040
00041 private static $instance = null;
00042 private $db;
00043
00044 private $usr_id;
00045 private $search_type = self::DEFAULT_SEARCH;
00046
00047 private $search_result = array();
00048 private $checked = array();
00049 private $failed = array();
00050 private $page_number = 1;
00051
00052
00059 private function __construct($a_usr_id)
00060 {
00061 global $ilDB;
00062
00063 $this->db = $ilDB;
00064 $this->usr_id = $a_usr_id;
00065 $this->search_type = self::DEFAULT_SEARCH;
00066 $this->read();
00067 }
00068
00077 public static function _getInstance($a_usr_id)
00078 {
00079 if(is_object(self::$instance) and self::$instance)
00080 {
00081 return self::$instance;
00082 }
00083 return self::$instance = new ilUserSearchCache($a_usr_id);
00084 }
00085
00094 public function switchSearchType($a_type)
00095 {
00096 $this->search_type = $a_type;
00097 $this->read();
00098 return true;
00099 }
00100
00107 public function getResults()
00108 {
00109 return $this->search_result ? $this->search_result : array();
00110 }
00111
00119 public function setResults($a_results)
00120 {
00121 $this->search_result = $a_results;
00122 }
00123
00131 public function addResult($a_result_item)
00132 {
00133 $this->search_result[$a_result_item['ref_id']]['ref_id'] = $a_result_item['ref_id'];
00134 $this->search_result[$a_result_item['ref_id']]['obj_id'] = $a_result_item['obj_id'];
00135 $this->search_result[$a_result_item['ref_id']]['type'] = $a_result_item['type'];
00136 return true;
00137 }
00138
00146 public function appendToFailed($a_ref_id)
00147 {
00148 $this->failed[$a_ref_id] = $a_ref_id;
00149 }
00150
00158 public function isFailed($a_ref_id)
00159 {
00160 return in_array($a_ref_id,$this->failed) ? true : false;
00161 }
00162
00171 public function appendToChecked($a_ref_id,$a_obj_id)
00172 {
00173 $this->checked[$a_ref_id] = $a_obj_id;
00174 }
00175
00183 public function isChecked($a_ref_id)
00184 {
00185 return array_key_exists($a_ref_id,$this->checked) and $this->checked[$a_ref_id];
00186 }
00187
00195 public function getCheckedItems()
00196 {
00197 return $this->checked ? $this->checked : array();
00198 }
00199
00206 public function setResultPageNumber($a_number)
00207 {
00208 if($a_number)
00209 {
00210 $this->page_number = $a_number;
00211 }
00212 }
00213
00220 public function getResultPageNumber()
00221 {
00222 return $this->page_number ? $this->page_number : 1;
00223 }
00224
00231 public function delete()
00232 {
00233 $query = "DELETE FROM usr_search ".
00234 "WHERE usr_id = ".$this->db->quote($this->usr_id)." ".
00235 "AND search_type = ".$this->db->quote($this->search_type);
00236
00237 $res = $this->db->query($query);
00238 $this->read();
00239 return true;
00240 }
00241
00248 public function save()
00249 {
00250 if($this->usr_id == ANONYMOUS_USER_ID)
00251 {
00252 return false;
00253 }
00254
00255 $query = "DELETE FROM usr_search ".
00256 "WHERE usr_id = ".$this->db->quote($this->usr_id)." ".
00257 "AND search_type = ".$this->db->quote($this->search_type);
00258 $res = $this->db->query($query);
00259
00260 $query = "INSERT INTO usr_search ".
00261 "SET usr_id = ".$this->db->quote($this->usr_id).", ".
00262 "search_result = '".addslashes(serialize($this->search_result))."', ".
00263 "checked = '".addslashes(serialize($this->checked))."', ".
00264 "failed = '".addslashes(serialize($this->failed))."', ".
00265 "page = ".$this->db->quote($this->page_number).", ".
00266 "search_type = ".$this->db->quote($this->search_type);
00267 $res = $this->db->query($query);
00268 }
00269
00270
00277 private function read()
00278 {
00279 $this->failed = array();
00280 $this->checked = array();
00281 $this->search_result = array();
00282 $this->page_number = 0;
00283
00284 if($this->usr_id == ANONYMOUS_USER_ID)
00285 {
00286 return false;
00287 }
00288
00289 $query = "SELECT * FROM usr_search ".
00290 "WHERE usr_id = ".$this->db->quote($this->usr_id)." ".
00291 "AND search_type = ".$this->db->quote($this->search_type);
00292
00293 $res = $this->db->query($query);
00294 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00295 {
00296 $this->search_result = unserialize(stripslashes($row->search_result));
00297 if(strlen($row->checked))
00298 {
00299 $this->checked = unserialize(stripslashes($row->checked));
00300 }
00301 if(strlen($row->failed))
00302 {
00303 $this->failed = unserialize(stripslashes($row->failed));
00304 }
00305 $this->page_number = $row->page;
00306 }
00307 return true;
00308 }
00309 }
00310
00311
00312 ?>