[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/items/model/ -> _itemcache.class.php (source)

   1  <?php
   2  /**

   3   * This file implements the ItemCache class.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   9   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.

  10   *

  11   * {@internal License choice

  12   * - If you have received this file as part of a package, please find the license.txt file in

  13   *   the same folder or the closest folder above for complete license terms.

  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  15   *   then you must choose one of the following licenses before using the file:

  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  18   * }}

  19   *

  20   * {@internal Open Source relicensing agreement:

  21   * Daniel HAHLER grants Francois PLANQUE the right to license

  22   * Daniel HAHLER's contributions to this file and the b2evolution project

  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  24   * }}

  25   *

  26   * @package evocore

  27   *

  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  29   * @author blueyed: Daniel HAHLER.

  30   * @author fplanque: Francois PLANQUE.

  31   *

  32   * @version $Id: _itemcache.class.php,v 1.1 2007/06/25 11:00:25 fplanque Exp $

  33   */
  34  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  35  
  36  load_class('_core/model/dataobjects/_dataobjectcache.class.php');
  37  
  38  load_class('items/model/_item.class.php');
  39  
  40  /**

  41   * Item Cache Class

  42   *

  43   * @package evocore

  44   */
  45  class ItemCache extends DataObjectCache
  46  {
  47      /**

  48       * Lazy filled index of url titles

  49       */
  50      var $urltitle_index = array();
  51  
  52      /**

  53       * Constructor

  54       *

  55       * @param string object type of elements in Cache

  56       * @param string Name of the DB table

  57       * @param string Prefix of fields in the table

  58       * @param string Name of the ID field (including prefix)

  59       */
  60  	function ItemCache( $objType = 'Item', $dbtablename = 'T_items__item', $dbprefix = 'post_', $dbIDname = 'post_ID' )
  61      {
  62          parent::DataObjectCache( $objType, false, $dbtablename, $dbprefix, $dbIDname );
  63      }
  64  
  65      /**

  66       * Get an object from cache by its urltitle

  67       *

  68       * Load into cache if necessary

  69       *

  70       * @param string stub of object to load

  71       * @param boolean false if you want to return false on error

  72       */
  73      function & get_by_urltitle( $req_urltitle, $halt_on_error = true )
  74      {
  75          global $DB, $Debuglog;
  76  
  77          if( !isset( $this->urltitle_index[$req_urltitle] ) )
  78          { // not yet in cache:
  79              // Load just the requested object:

  80              $Debuglog->add( "Loading <strong>$this->objtype($req_urltitle)</strong> into cache" );
  81              $sql = "SELECT *
  82                        FROM $this->dbtablename
  83                       WHERE post_urltitle = ".$DB->quote($req_urltitle);
  84              $row = $DB->get_row( $sql );
  85              if( empty( $row ) )
  86              {    // Requested object does not exist
  87                  if( $halt_on_error ) debug_die( "Requested $this->objtype does not exist!" );
  88                  // put into index:

  89                  $this->urltitle_index[$req_urltitle] = false;
  90  
  91                  return $this->urltitle_index[$req_urltitle];
  92              }
  93  
  94              $this->instantiate( $row );
  95  
  96              // put into index:

  97              $this->urltitle_index[$req_urltitle] = & $this->cache[ $row->post_ID ];
  98          }
  99          else
 100          {
 101              $Debuglog->add( "Retrieving <strong>$this->objtype($req_urltitle)</strong> from cache" );
 102          }
 103  
 104          return $this->urltitle_index[$req_urltitle];
 105      }
 106  
 107  
 108      /**

 109       * Load a list of item referenced by their urltitle into the cache

 110       *

 111       * @param array of urltitles of Items to load

 112       */
 113  	function load_urltitle_array( $req_array )
 114      {
 115          global $DB, $Debuglog;
 116  
 117          $req_list = "'".implode( "','", $req_array)."'";
 118          $Debuglog->add( "Loading <strong>$this->objtype($req_list)</strong> into cache" );
 119          $sql = "SELECT * FROM $this->dbtablename WHERE post_urltitle IN ( $req_list )";
 120          $dbIDname = $this->dbIDname;
 121          $objtype = $this->objtype;
 122          foreach( $DB->get_results( $sql ) as $row )
 123          {
 124              $this->cache[ $row->$dbIDname ] = new $objtype( $row ); // COPY!

 125              // $obj = $this->cache[ $row->$dbIDname ];

 126              // $obj->disp( 'name' );

 127  
 128              // put into index:

 129              $this->urltitle_index[$row->post_urltitle] = & $this->cache[ $row->$dbIDname ];
 130  
 131              $Debuglog->add( "Cached <strong>$this->objtype($row->post_urltitle)</strong>" );
 132          }
 133  
 134          // Set cache for non found objects:

 135          foreach( $req_array as $urltitle )
 136          {
 137              if( !isset( $this->urltitle_index[$urltitle] ) )
 138              { // not yet in cache:
 139                  $this->urltitle_index[$urltitle] = false; // Remember it doesn't exist in DB either

 140                  $Debuglog->add( "Cached <strong>$this->objtype($urltitle)</strong> as NON EXISTENT" );
 141              }
 142          }
 143      }
 144  
 145  }
 146  
 147  /*

 148   * $Log: _itemcache.class.php,v $

 149   * Revision 1.1  2007/06/25 11:00:25  fplanque

 150   * MODULES (refactored MVC)

 151   *

 152   * Revision 1.10  2007/05/14 02:43:05  fplanque

 153   * Started renaming tables. There probably won't be a better time than 2.0.

 154   *

 155   * Revision 1.9  2007/04/26 00:11:12  fplanque

 156   * (c) 2007

 157   *

 158   * Revision 1.8  2006/11/24 18:27:24  blueyed

 159   * Fixed link to b2evo CVS browsing interface in file docblocks

 160   */
 161  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics