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

classes/class.ilObjectDataCache.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 
00033 class ilObjectDataCache
00034 {
00035         var $db = null;
00036         var $reference_cache = array();
00037         var $object_data_cache = array();
00038 
00039         function ilObjectDataCache()
00040         {
00041                 global $ilDB;
00042 
00043                 $this->db =& $ilDB;
00044         }
00045 
00046         function deleteCachedEntry($a_obj_id)
00047         {
00048                 unset($this->object_data_cache[$a_obj_id]);
00049         }
00050 
00051         function lookupObjId($a_ref_id)
00052         {
00053                 if(!$this->__isReferenceCached($a_ref_id))
00054                 {
00055 //echo"-objidmissed-$a_ref_id-";
00056                         $obj_id = $this->__storeReference($a_ref_id);
00057                         $this->__storeObjectData($obj_id);
00058                 }
00059                 return (int) @$this->reference_cache[$a_ref_id];
00060         }
00061 
00062         function lookupTitle($a_obj_id)
00063         {
00064                 if(!$this->__isObjectCached($a_obj_id))
00065                 {
00066                         $this->__storeObjectData($a_obj_id);
00067                 }
00068                 return @$this->object_data_cache[$a_obj_id]['title'];
00069         }
00070 
00071         function lookupType($a_obj_id)
00072         {
00073                 if(!$this->__isObjectCached($a_obj_id))
00074                 {
00075 //echo"-typemissed-$a_obj_id-";
00076                         $this->__storeObjectData($a_obj_id);
00077                 }
00078                 return @$this->object_data_cache[$a_obj_id]['type'];
00079         }
00080 
00081         function lookupOwner($a_obj_id)
00082         {
00083                 if(!$this->__isObjectCached($a_obj_id))
00084                 {
00085                         $this->__storeObjectData($a_obj_id);
00086                 }
00087                 return @$this->object_data_cache[$a_obj_id]['owner'];
00088         }
00089 
00090         function lookupDescription($a_obj_id)
00091         {
00092                 if(!$this->__isObjectCached($a_obj_id))
00093                 {
00094                         $this->__storeObjectData($a_obj_id);
00095                 }
00096                 return @$this->object_data_cache[$a_obj_id]['description'];
00097         }
00098 
00099         function lookupLastUpdate($a_obj_id)
00100         {
00101                 if(!$this->__isObjectCached($a_obj_id))
00102                 {
00103                         $this->__storeObjectData($a_obj_id);
00104                 }
00105                 return @$this->object_data_cache[$a_obj_id]['last_update'];
00106         }
00107         // PRIVATE
00108 
00116         function __isReferenceCached($a_ref_id)
00117         {
00118                 #return false;
00119                 #static $cached = 0;
00120                 #static $not_cached = 0;
00121 
00122                 if(@$this->reference_cache[$a_ref_id])
00123                 {
00124                         #echo "Reference ". ++$cached ."cached<br>";
00125                         return true;
00126                 }
00127                 #echo "Reference ". ++$not_cached ." not cached<br>";
00128                 return false;
00129                 
00130         }
00131 
00139         function __isObjectCached($a_obj_id)
00140         {
00141                 static $cached = 0;
00142                 static $not_cached = 0;
00143                         
00144 
00145                 if(@$this->object_data_cache[$a_obj_id])
00146                 {
00147                         #echo "Object ". ++$cached ."cached<br>";
00148                         return true;
00149                 }
00150                 #echo "Object ". ++$not_cached ." not cached<br>";
00151                 return false;
00152         }
00153 
00154 
00164         function __storeReference($a_ref_id)
00165         {
00166                 global $ilDB;
00167                 
00168                 $query = "SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($a_ref_id);
00169                 $res = $this->db->query($query);
00170                 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00171                 {
00172                         $this->reference_cache[$a_ref_id] = $row['obj_id'];
00173                 }
00174                 return (int) @$this->reference_cache[$a_ref_id];
00175         }
00176 
00184         function __storeObjectData($a_obj_id, $a_lang = "")
00185         {
00186                 global $ilDB, $objDefinition, $ilUser;
00187                 
00188                 if (is_object($ilUser) && $a_lang == "")
00189                 {
00190                         $a_lang = $ilUser->getLanguage();
00191                 }
00192                 
00193                 $query = "SELECT * FROM object_data WHERE obj_id = ".
00194                         $ilDB->quote($a_obj_id);
00195                 $res = $this->db->query($query);
00196                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00197                 {
00198                         $this->object_data_cache[$a_obj_id]['title'] = $row->title;
00199                         $this->object_data_cache[$a_obj_id]['description'] = $row->description;
00200                         $this->object_data_cache[$a_obj_id]['type'] = $row->type;
00201                         $this->object_data_cache[$a_obj_id]['owner'] = $row->owner;
00202                         $this->object_data_cache[$a_obj_id]['last_update'] = $row->last_update;
00203                         
00204                         //$ilBench->start("Tree", "fetchNodeData_readDefinition");
00205                         if (is_object($objDefinition))
00206                         {
00207                                 $translation_type = $objDefinition->getTranslationType($row->type);
00208                         }
00209                         //$ilBench->stop("Tree", "fetchNodeData_readDefinition");
00210 
00211                         if ($translation_type == "db")
00212                         {
00213                                 //$ilBench->start("Tree", "fetchNodeData_getTranslation");
00214                                 $q = "SELECT title,description FROM object_translation ".
00215                                          "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ".
00216                                          "AND lang_code = ".$ilDB->quote($a_lang)." ".
00217                                          "AND NOT lang_default = 1";
00218                                 $r = $ilDB->query($q);
00219 
00220                                 $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
00221                                 if ($row)
00222                                 {
00223                                         $this->object_data_cache[$a_obj_id]['title'] = $row->title;
00224                                         $this->object_data_cache[$a_obj_id]['description'] = $row->description;
00225                                 }
00226                                 //$ilBench->stop("Tree", "fetchNodeData_getTranslation");
00227                         }
00228                 }
00229                 
00230                 return true;
00231         }
00232         
00240         function preloadObjectCache($a_obj_ids, $a_lang = "")
00241         {
00242                 global $ilDB, $objDefinition, $ilUser;
00243                 
00244                 if (is_object($ilUser) && $a_lang == "")
00245                 {
00246                         $a_lang = $ilUser->getLanguage();
00247                 }
00248                 
00249 //echo "<br>-preloading-"; var_dump($a_obj_ids);
00250                 if (!is_array($a_obj_ids)) return;
00251                 if (count($a_obj_ids) == 0) return;
00252                 
00253                 $query = "SELECT * FROM object_data WHERE obj_id IN (".
00254                         implode(",",ilUtil::quoteArray($a_obj_ids)).")";
00255                 $res = $ilDB->query($query);
00256                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00257                 {
00258 //echo "<br>store_obj-".$row->obj_id."-".$row->type."-".$row->title."-";
00259                         $this->object_data_cache[$row->obj_id]['title'] = $row->title;
00260                         $this->object_data_cache[$row->obj_id]['description'] = $row->description;
00261                         $this->object_data_cache[$row->obj_id]['type'] = $row->type;
00262                         $this->object_data_cache[$row->obj_id]['owner'] = $row->owner;
00263                         $this->object_data_cache[$row->obj_id]['last_update'] = $row->last_update;
00264 
00265                         if (is_object($objDefinition))
00266                         {
00267                                 $translation_type = $objDefinition->getTranslationType($row->type);
00268                         }
00269                         //$ilBench->stop("Tree", "fetchNodeData_readDefinition");
00270 
00271                         if ($translation_type == "db")
00272                         {
00273                                 //$ilBench->start("Tree", "fetchNodeData_getTranslation");
00274                                 $q = "SELECT title,description FROM object_translation ".
00275                                          "WHERE obj_id = ".$ilDB->quote($row->obj_id)." ".
00276                                          "AND lang_code = ".$ilDB->quote($a_lang)." ".
00277                                          "AND NOT lang_default = 1";
00278                                 $r = $ilDB->query($q);
00279 
00280                                 $row2 = $r->fetchRow(DB_FETCHMODE_OBJECT);
00281                                 if ($row2)
00282                                 {
00283                                         $this->object_data_cache[$row->obj_id]['title'] = $row2->title;
00284                                         $this->object_data_cache[$row->obj_id]['description'] = $row2->description;
00285                                 }
00286                                 //$ilBench->stop("Tree", "fetchNodeData_getTranslation");
00287                         }
00288                 }
00289         }
00290 
00291         function preloadReferenceCache($a_ref_ids, $a_incl_obj = true)
00292         {
00293                 global $ilDB;
00294                 
00295                 if (!is_array($a_ref_ids)) return;
00296                 if (count($a_ref_ids) == 0) return;
00297                 
00298                 $query = "SELECT ref_id, obj_id FROM object_reference WHERE ref_id IN (".
00299                         implode(",",ilUtil::quoteArray($a_ref_ids)).")";
00300                 $res = $this->db->query($query);
00301                 $obj_ids = array();
00302                 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00303                 {
00304                         $this->reference_cache[$row['ref_id']] = $row['obj_id'];
00305 //echo "<br>store_ref-".$row['ref_id']."-".$row['obj_id']."-";
00306                         $obj_ids[] = $row['obj_id'];
00307                 }
00308                 if ($a_incl_obj)
00309                 {
00310                         $this->preloadObjectCache($obj_ids);
00311                 }
00312         }
00313 
00314 }
00315 ?>

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