[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the LinkCache 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 * 10 * {@internal License choice 11 * - If you have received this file as part of a package, please find the license.txt file in 12 * the same folder or the closest folder above for complete license terms. 13 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) 14 * then you must choose one of the following licenses before using the file: 15 * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php 16 * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php 17 * }} 18 * 19 * {@internal Open Source relicensing agreement: 20 * }} 21 * 22 * @package evocore 23 * 24 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 25 * @author fplanque: Francois PLANQUE. 26 * 27 * @version $Id: _linkcache.class.php,v 1.1 2007/06/25 11:00:29 fplanque Exp $ 28 */ 29 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 30 31 load_class('_core/model/dataobjects/_dataobjectcache.class.php'); 32 33 /** 34 * LinkCache Class 35 * 36 * @package evocore 37 */ 38 class LinkCache extends DataObjectCache 39 { 40 /** 41 * Cache for item -> array of object references 42 * @access private 43 * @var array 44 */ 45 var $cache_item = array(); 46 47 /** 48 * Constructor 49 */ 50 function LinkCache() 51 { 52 parent::DataObjectCache( 'Link', false, 'T_links', 'link_', 'link_ID' ); 53 } 54 55 56 /** 57 * Add a dataobject to the cache 58 */ 59 function add( & $Obj ) 60 { 61 if( isset($Obj->ID) && $Obj->ID != 0 ) 62 { // If the object wasn't already cached and is valid: 63 $this->cache[$Obj->ID] = & $Obj; 64 // Also cache indexed by Item ID: 65 $this->cache_item[$Obj->Item->ID][$Obj->ID] = & $Obj; 66 return true; 67 } 68 return false; 69 } 70 71 72 /** 73 * Returns links for a given Item 74 * 75 * Loads if necessary 76 * 77 * @param integer item ID to load links for 78 * @return array of refs to Link objects 79 */ 80 function & get_by_item_ID( $item_ID ) 81 { 82 // Make sure links are loaded: 83 $this->load_by_item_ID( $item_ID ); 84 85 return $this->cache_item[$item_ID]; 86 } 87 88 89 /** 90 * Load links for a given Item 91 * 92 * Optimization: If the Item happens to be in the current MainList, Links for the whole MainList will be cached. 93 * 94 * @todo cache Link targets before letting the Link constructor handle it 95 * 96 * @param integer item ID to load links for 97 */ 98 function load_by_item_ID( $item_ID ) 99 { 100 global $DB, $Debuglog, $MainList; 101 102 if( isset( $this->cache_item[$item_ID] ) ) 103 { 104 $Debuglog->add( "Already loaded <strong>$this->objtype(Item #$item_ID)</strong> into cache" ); 105 return false; 106 } 107 108 // Check if this Item is part of the MainList 109 if( isset( $MainList ) && in_array( $item_ID, $MainList->postIDarray ) ) 110 { // YES! We found the current Item in the MainList, let's load/cache the links for the WholeMainList 111 $Debuglog->add( "Loading <strong>$this->objtype(Item #$item_ID)</strong> into cache as part of MainList..."); 112 $this->load_by_item_list( $MainList->postIDarray ); 113 } 114 else 115 { // NO, load Links for this single Item: 116 117 // Remember this special load: 118 $this->cache_item[$item_ID] = array(); 119 120 $Debuglog->add( "Loading <strong>$this->objtype(Item #$item_ID)</strong> into cache" ); 121 122 $sql = 'SELECT * 123 FROM T_links 124 WHERE link_itm_ID = '.$item_ID.' 125 ORDER BY link_ltype_ID, link_dest_itm_ID, link_file_ID'; 126 foreach( $DB->get_results( $sql ) as $row ) 127 { // Cache each matching object: 128 $this->add( new Link( $row ) ); 129 } 130 } 131 132 return true; 133 } 134 135 136 /** 137 * Load links for a given Item list 138 * 139 * @todo cache Link targets before letting the Link constructor handle it 140 * 141 * @param array of of item IDs to load links for 142 */ 143 function load_by_item_list( $itemIDarray ) 144 { 145 global $DB, $Debuglog; 146 147 $item_list = implode( ',', $itemIDarray ); 148 149 $Debuglog->add( "Loading <strong>$this->objtype(Items #$item_list)</strong> into cache" ); 150 151 // For each item in list... 152 foreach( $itemIDarray as $item_ID ) 153 { // Remember this special load: 154 $this->cache_item[$item_ID] = array(); 155 } 156 157 foreach( $DB->get_results( 'SELECT * 158 FROM T_links 159 WHERE link_itm_ID IN ('.$item_list.')' ) as $row ) 160 { // Cache each matching object: 161 $this->add( new Link( $row ) ); 162 } 163 164 return true; 165 } 166 167 } 168 169 /* 170 * $Log: _linkcache.class.php,v $ 171 * Revision 1.1 2007/06/25 11:00:29 fplanque 172 * MODULES (refactored MVC) 173 * 174 */ 175 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |