~quam-plures-core/quam-plures/fix-auto_p_plugin

« back to all changes in this revision

Viewing changes to qp_inc/items/model/_itemcache.class.php

  • Committer: EdB
  • Date: 2013-03-18 19:30:14 UTC
  • mfrom: (7602.1.58 quam-plures)
  • Revision ID: 1912webworks@gmail.com-20130318193014-qogr0c0lwd5ix8lj
quam-plures/qp5_colls-blogs_chaps-cats

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
 
 * This file implements the ItemCache class.
4
 
 *
5
 
 * This file is part of Quam Plures - {@link http://quamplures.net/}
6
 
 * See also {@link https://launchpad.net/quam-plures}.
7
 
 *
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}.
11
 
 *
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
19
 
 * }}
20
 
 *
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/).
25
 
 * }}
26
 
 *
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.
30
 
 *
 
3
 * This file implements the ItemCache class
 
4
 *
 
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
31
10
 * @package items
32
11
 */
33
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
34
 
 
35
 
load_class('_core/model/dataobjects/_dataobjectcache.class.php');
36
 
 
37
 
load_class('items/model/_item.class.php');
 
12
if(!defined('QP_MAIN_INIT')) die('fail');
38
13
 
39
14
/**
40
 
 * Item Cache Class
 
15
 * ItemCache class
41
16
 *
42
17
 * @package items
43
18
 */
45
20
{
46
21
        /**
47
22
         * Lazy filled index of url titles
 
23
         * @var array
48
24
         */
49
25
        var $urltitle_index = array();
50
26
 
56
32
         * @param string Prefix of fields in the table
57
33
         * @param string Name of the ID field (including prefix)
58
34
         */
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' )
60
36
        {
 
37
                // Call parent constructor
61
38
                parent::DataObjectCache( $objType, false, $dbtablename, $dbprefix, $dbIDname );
62
39
        }
63
40
 
 
41
 
64
42
        /**
65
43
         * Get an object from cache by its urltitle
66
44
         *
71
49
         */
72
50
        function & get_by_urltitle( $req_urltitle, $halt_on_error = true )
73
51
        {
74
 
                global $DB, $Debuglog;
 
52
                global $DB;
75
53
 
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] ) )
 
55
                {
 
56
                        // not yet in cache
 
57
                        // Load just the requested object
80
58
                        $sql = "SELECT *
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!" );
87
 
                                // put into index:
 
63
                        {
 
64
                                // Requested object does not exist
 
65
                                if( $halt_on_error )
 
66
                                {
 
67
                                        debug_die( "Requested $this->objtype does not exist!" );
 
68
                                }
 
69
                                // put into index
88
70
                                $this->urltitle_index[$req_urltitle] = false;
89
 
 
90
71
                                return $this->urltitle_index[$req_urltitle];
91
72
                        }
92
 
 
93
73
                        $this->instantiate( $row );
94
 
 
95
 
                        // put into index:
96
 
                        $this->urltitle_index[$req_urltitle] = & $this->cache[ $row->post_ID ];
97
 
                }
98
 
                else
99
 
                {
100
 
                        $Debuglog->add( "Retrieving <strong>$this->objtype($req_urltitle)</strong> from cache" );
101
 
                }
102
 
 
 
74
                        // put into index
 
75
                        $this->urltitle_index[$req_urltitle] = & $this->cache[$row->post_ID];
 
76
                }
103
77
                return $this->urltitle_index[$req_urltitle];
104
78
        }
105
79
 
111
85
         */
112
86
        function load_urltitle_array( $req_array )
113
87
        {
114
 
                global $DB, $Debuglog;
 
88
                global $DB;
115
89
 
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 )
122
95
                {
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' );
126
99
 
127
 
                        // put into index:
128
 
                        $this->urltitle_index[$row->post_urltitle] = & $this->cache[ $row->$dbIDname ];
129
 
 
130
 
                        $Debuglog->add( "Cached <strong>$this->objtype($row->post_urltitle)</strong>" );
 
100
                        // put into index
 
101
                        $this->urltitle_index[$row->post_urltitle] = & $this->cache[$row->$dbIDname];
131
102
                }
132
103
 
133
 
                // Set cache for non found objects:
 
104
                // Set cache for non found objects
134
105
                foreach( $req_array as $urltitle )
135
106
                {
136
 
                        if( !isset( $this->urltitle_index[$urltitle] ) )
137
 
                        { // not yet in cache:
 
107
                        if( ! isset( $this->urltitle_index[$urltitle] ) )
 
108
                        {
 
109
                                // not yet in cache
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" );
140
111
                        }
141
112
                }
142
113
        }
143
114
 
144
115
}
145
116
 
146
 
?>
 
 
b'\\ No newline at end of file'
 
117
?>