| [ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the WidgetCache 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 * @author fplanque: Francois PLANQUE 25 * 26 * @version $Id: _widgetcache.class.php,v 1.1 2007/06/25 11:01:57 fplanque Exp $ 27 */ 28 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 29 30 load_class('_core/model/dataobjects/_dataobjectcache.class.php'); 31 32 load_class( 'widgets/model/_widget.class.php' ); 33 34 /** 35 * Widget Cache Class 36 * 37 * @package evocore 38 */ 39 class WidgetCache extends DataObjectCache 40 { 41 /** 42 * Cache by container 43 * @var array of coll_ID => array of container_name => array of Widget 44 */ 45 var $cache_container_Widget_array = array(); 46 47 /** 48 * Constructor 49 */ 50 function WidgetCache() 51 { 52 parent::DataObjectCache( 'ComponentWidget', false, 'T_widget', 'wi_', 'wi_ID', NULL, NULL, NULL ); 53 } 54 55 56 /** 57 * @param integer 58 * @return array of coll_ID => array of container_name => array of Widget 59 */ 60 function & get_by_coll_ID( $coll_ID ) 61 { 62 global $DB; 63 64 if( ! isset( $this->cache_container_Widget_array[$coll_ID] ) ) 65 { // Not in Cache yet: 66 $sql = 'SELECT * 67 FROM T_widget 68 WHERE wi_coll_ID = '.$coll_ID.' 69 ORDER BY wi_sco_name, wi_order'; 70 $widget_rs = $DB->get_results( $sql, OBJECT, 'Get list of widgets for collection' ); 71 72 $this->cache_container_Widget_array[$coll_ID] = array(); 73 for( $i = 0; $i < count( $widget_rs ); $i++ ) 74 { 75 // fp> NOTE: object COPYing is weird here but it needs to be like this in PHP4 or all abjects from the loop will look the same 76 if( $ComponentWidget = & $this->new_obj( $widget_rs[$i] ) ) // fp> NOTE: no copy because we need copy on the next line anyway!! 77 { // We were able to instantiate the widget: 78 // Add to regular cache (but not with $this->add() because we need a COPY!!): 79 $this->cache[$ComponentWidget->ID] = $ComponentWidget; // COPY!!!! WEIRD BUT NECESSARY / PHP 4 (fp) 80 // This is the cache we're interested in: 81 $this->cache_container_Widget_array[$ComponentWidget->coll_ID][$ComponentWidget->sco_name][] = & $this->cache[$ComponentWidget->ID]; 82 } 83 84 // TODO: dh> try the next line, and you may be able to assign by reference to $cache or use add() 85 unset($ComponentWidget); 86 } 87 // pre_dump($this->cache_container_Widget_array[$coll_ID]); 88 } 89 90 return $this->cache_container_Widget_array[$coll_ID]; 91 } 92 93 94 /** 95 * Instanciate a new object within this cache 96 */ 97 function & new_obj( $row = NULL ) 98 { 99 if( $row->wi_type == 'core' ) 100 { 101 if( ! load_class( 'widgets/widgets/_'.$row->wi_code.'.widget.php', false ) ) 102 { // For some reason, that widget doesn't seem to exist... (any more?) 103 // echo "Widget $row->wi_code could not be loaded! "; 104 // TODO: replace with dummy widget in order to give a chance to clean up. 105 $r = NULL; 106 return $r; 107 } 108 $objtype = $row->wi_code.'_Widget'; 109 } 110 else 111 { 112 $objtype = 'ComponentWidget'; 113 } 114 115 // Instantiate a custom object 116 $obj = new $objtype( $row ); // COPY !! 117 118 return $obj; 119 } 120 121 122 /** 123 * @param integer 124 * @param string 125 * @return array of Widget 126 */ 127 function & get_by_coll_container( $coll_ID, $container ) 128 { 129 // Make sure collection is loaded: 130 $this->get_by_coll_ID( $coll_ID ); 131 132 return $this->cache_container_Widget_array[$coll_ID][$container]; 133 } 134 } 135 136 137 /* 138 * $Log: _widgetcache.class.php,v $ 139 * Revision 1.1 2007/06/25 11:01:57 fplanque 140 * MODULES (refactored MVC) 141 * 142 * Revision 1.3 2007/06/20 21:42:13 fplanque 143 * implemented working widget/plugin params 144 * 145 * Revision 1.2 2007/06/20 14:25:00 fplanque 146 * fixes 147 * 148 * Revision 1.1 2007/06/18 21:25:48 fplanque 149 * one class per core widget 150 * 151 * Revision 1.5 2007/04/26 00:11:06 fplanque 152 * (c) 2007 153 * 154 * Revision 1.4 2007/03/26 17:12:40 fplanque 155 * allow moving of widgets 156 * 157 * Revision 1.3 2007/02/26 03:19:40 fplanque 158 * hum... I cannot reproduce the old bug anymore :/ 159 * 160 * Revision 1.2 2007/02/10 18:37:16 blueyed 161 * doc/todo 162 * 163 * Revision 1.1 2007/01/11 20:44:19 fplanque 164 * skin containers proof of concept 165 * (no params handling yet though) 166 */ 167 ?>
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 |
|