3
* This file implements the ItemCache class.
5
* This file is part of Quam Plures - {@link http://quamplures.net/}
6
* See also {@link https://launchpad.net/quam-plures}.
8
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
9
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
10
* Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
12
* {@internal License choice
13
* - If you have received this file as part of a package, please find the license.txt file in
14
* the same folder or the closest folder above for complete license terms.
15
* - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
16
* then you must choose one of the following licenses before using the file:
17
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
18
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
21
* {@internal Open Source relicensing agreement:
22
* Daniel HAHLER grants Francois PLANQUE the right to license
23
* Daniel HAHLER's contributions to this file and the b2evolution project
24
* under any OSI approved OSS license (http://www.opensource.org/licenses/).
27
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
28
* @author blueyed: Daniel HAHLER.
29
* @author fplanque: Francois PLANQUE.
3
* This file implements the ItemCache class
5
* @author {@link http://wonderwinds.com/ Ed Bennett}
6
* @author {@link http://daniel.hahler.de/ Daniel HAHLER}
7
* @author {@link http://fplanque.net/ Francois PLANQUE}
8
* @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
9
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
33
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
35
load_class('_core/model/dataobjects/_dataobjectcache.class.php');
37
load_class('items/model/_item.class.php');
12
if(!defined('QP_MAIN_INIT')) die('fail');
56
32
* @param string Prefix of fields in the table
57
33
* @param string Name of the ID field (including prefix)
59
function ItemCache( $objType = 'Item', $dbtablename = 'T_items__item', $dbprefix = 'post_', $dbIDname = 'post_ID' )
35
function ItemCache( $objType = 'Item', $dbtablename = 'T_items', $dbprefix = 'post_', $dbIDname = 'post_ID' )
37
// Call parent constructor
61
38
parent::DataObjectCache( $objType, false, $dbtablename, $dbprefix, $dbIDname );
65
43
* Get an object from cache by its urltitle
72
50
function & get_by_urltitle( $req_urltitle, $halt_on_error = true )
74
global $DB, $Debuglog;
76
if( !isset( $this->urltitle_index[$req_urltitle] ) )
77
{ // not yet in cache:
78
// Load just the requested object:
79
$Debuglog->add( "Loading <strong>$this->objtype($req_urltitle)</strong> into cache", 'dataobjects' );
54
if( ! isset( $this->urltitle_index[$req_urltitle] ) )
57
// Load just the requested object
81
FROM $this->dbtablename
82
WHERE post_urltitle = ".$DB->quote($req_urltitle);
59
FROM $this->dbtablename
60
WHERE post_urltitle = ".$DB->quote( $req_urltitle );
83
61
$row = $DB->get_row( $sql );
84
62
if( empty( $row ) )
85
{ // Requested object does not exist
86
if( $halt_on_error ) debug_die( "Requested $this->objtype does not exist!" );
64
// Requested object does not exist
67
debug_die( "Requested $this->objtype does not exist!" );
88
70
$this->urltitle_index[$req_urltitle] = false;
90
71
return $this->urltitle_index[$req_urltitle];
93
73
$this->instantiate( $row );
96
$this->urltitle_index[$req_urltitle] = & $this->cache[ $row->post_ID ];
100
$Debuglog->add( "Retrieving <strong>$this->objtype($req_urltitle)</strong> from cache" );
75
$this->urltitle_index[$req_urltitle] = & $this->cache[$row->post_ID];
103
77
return $this->urltitle_index[$req_urltitle];
112
86
function load_urltitle_array( $req_array )
114
global $DB, $Debuglog;
116
90
$req_list = "'".implode( "','", $req_array)."'";
117
$Debuglog->add( "Loading <strong>$this->objtype($req_list)</strong> into cache", 'dataobjects' );
118
91
$sql = "SELECT * FROM $this->dbtablename WHERE post_urltitle IN ( $req_list )";
119
92
$dbIDname = $this->dbIDname;
120
93
$objtype = $this->objtype;
121
94
foreach( $DB->get_results( $sql ) as $row )
123
$this->cache[ $row->$dbIDname ] = new $objtype( $row ); // COPY!
124
// $obj = $this->cache[ $row->$dbIDname ];
96
$this->cache[$row->$dbIDname] = new $objtype( $row ); // COPY!
97
// $obj = $this->cache[$row->$dbIDname];
125
98
// $obj->disp( 'name' );
128
$this->urltitle_index[$row->post_urltitle] = & $this->cache[ $row->$dbIDname ];
130
$Debuglog->add( "Cached <strong>$this->objtype($row->post_urltitle)</strong>" );
101
$this->urltitle_index[$row->post_urltitle] = & $this->cache[$row->$dbIDname];
133
// Set cache for non found objects:
104
// Set cache for non found objects
134
105
foreach( $req_array as $urltitle )
136
if( !isset( $this->urltitle_index[$urltitle] ) )
137
{ // not yet in cache:
107
if( ! isset( $this->urltitle_index[$urltitle] ) )
138
110
$this->urltitle_index[$urltitle] = false; // Remember it doesn't exist in DB either
139
$Debuglog->add( "Cached <strong>$this->objtype($urltitle)</strong> as NON EXISTENT" );
b'\\ No newline at end of file'