| [ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the abstract DataObjectList2 base 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: _dataobjectlist2.class.php,v 1.3 2007/09/28 09:28:36 fplanque Exp $ 28 */ 29 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 30 31 load_funcs('_core/ui/results/_results.class.php'); 32 33 34 /** 35 * @package evocore 36 */ 37 class FilteredResults extends Results 38 { 39 /** 40 * Default filter set (used if no specific params are passed) 41 */ 42 var $default_filters = array(); 43 44 /** 45 * Current filter set (depending on user input) 46 */ 47 var $filters = array(); 48 49 50 /** 51 * Check if the Result set is filtered or not 52 */ 53 function is_filtered() 54 { 55 if( empty( $this->filters ) ) 56 { 57 return false; 58 } 59 60 return ( $this->filters != $this->default_filters ); 61 } 62 63 64 /** 65 * Get every active filter that is not the same as the defaults 66 */ 67 function get_active_filters() 68 { 69 $r = array(); 70 71 foreach( $this->default_filters as $key => $value ) 72 { 73 if( !isset( $this->filters[$key] ) ) 74 { // Some value has not been copied over from defaults to active or specifically set: 75 if( !is_null($value)) // Note: NULL value are not copied over. that's normal. 76 { // A NON NULL value is missing 77 $r[] = $key; 78 } 79 } 80 elseif( $value != $this->filters[$key] ) 81 { 82 $r[] = $key; 83 } 84 } 85 return $r; 86 } 87 88 89 /** 90 * Show every active filter that is not the same as the defaults 91 */ 92 function dump_active_filters() 93 { 94 foreach( $this->default_filters as $key => $value ) 95 { 96 if( !isset( $this->filters[$key] ) ) 97 { // SOme value has not been copied over from defaults to active or specifically set: 98 if( !is_null($value)) // Note: NULL value ar enot copied over. that's normal. 99 { // A NON NULL value is missing 100 pre_dump( 'no active value for default '.$key ); 101 } 102 } 103 elseif( $value != $this->filters[$key] ) 104 { 105 pre_dump( 'default '.$key, $value ); 106 pre_dump( 'active '.$key, $this->filters[$key] ); 107 } 108 } 109 } 110 } 111 112 113 114 /** 115 * Data Object List Base Class 2 116 * 117 * This is typically an abstract class, useful only when derived. 118 * Holds DataObjects in an array and allows walking through... 119 * 120 * This SECOND implementation will deprecate the first one when finished. 121 * 122 * @package evocore 123 * @version beta 124 * @abstract 125 */ 126 class DataObjectList2 extends FilteredResults 127 { 128 129 130 /** 131 * Constructor 132 * 133 * If provided, executes SQL query via parent Results object 134 * 135 * @param DataObjectCache 136 * @param integer number of lines displayed on one screen (null for default [20]) 137 * @param string prefix to differentiate page/order params when multiple Results appear one same page 138 * @param string default ordering of columns (special syntax) 139 */ 140 function DataObjectList2( & $Cache, $limit = null, $param_prefix = '', $default_order = NULL ) 141 { 142 // WARNING: we are not passing any SQL query to the Results object 143 // This will make the Results object behave a little bit differently than usual: 144 parent::Results( NULL, $param_prefix, $default_order, $limit, NULL, false ); 145 146 // The list objects will also be cached in this cache. 147 // Tje Cache object may also be useful to get table information for the Items. 148 $this->Cache = & $Cache; 149 150 // Colum used for IDs 151 $this->ID_col = $Cache->dbIDname; 152 } 153 154 155 /** 156 * Instantiate an object for requested row and cache it: 157 */ 158 function & get_by_idx( $idx ) 159 { 160 return $this->Cache->instantiate( $this->rows[$idx] ); 161 } 162 163 164 /** 165 * Get next object in list 166 */ 167 function & get_next() 168 { 169 // echo '<br />Get next, current idx was: '.$this->current_idx.'/'.$this->result_num_rows; 170 171 if( $this->current_idx >= $this->result_num_rows ) 172 { // No more object in list 173 $this->current_Obj = NULL; 174 $r = false; // TODO: try with NULL 175 return $r; 176 } 177 178 // We also keep a local ref in case we want to use it for display: 179 $this->current_Obj = & $this->get_by_idx( $this->current_idx ); 180 $this->next_idx(); 181 182 return $this->current_Obj; 183 } 184 185 186 /** 187 * Display a global title matching filter params 188 * 189 * @todo implement $order 190 * 191 * @param string prefix to display if a title is generated 192 * @param string suffix to display if a title is generated 193 * @param string glue to use if multiple title elements are generated 194 * @param string comma separated list of titles inthe order we would like to display them 195 * @param string format to output, default 'htmlbody' 196 */ 197 function get_filter_title( $prefix = ' ', $suffix = '', $glue = ' - ', $order = NULL, $format = 'htmlbody' ) 198 { 199 $title_array = $this->get_filter_titles(); 200 201 if( empty( $title_array ) ) 202 { 203 return ''; 204 } 205 206 // We have something to display: 207 $r = implode( $glue, $title_array ); 208 $r = $prefix.format_to_output( $r, $format ).$suffix; 209 return $r; 210 } 211 212 213 /** 214 * Move up the element order in database 215 * 216 * @param integer id element 217 * @return unknown 218 */ 219 function move_up( $id ) 220 { 221 global $DB, $Messages, $result_fadeout; 222 223 $DB->begin(); 224 225 if( ($obj = & $this->Cache->get_by_ID( $id )) === false ) 226 { 227 $Messages->head = T_('Cannot edit entry!'); 228 $Messages->add( T_('Requested entry does not exist any longer.'), 'error' ); 229 $DB->commit(); 230 return false; 231 } 232 $order = $obj->order; 233 234 // Get the ID of the inferior element which his order is the nearest 235 $rows = $DB->get_results( 'SELECT '.$this->Cache->dbIDname 236 .' FROM '.$this->Cache->dbtablename 237 .' WHERE '.$this->Cache->dbprefix.'order < '.$order 238 .' ORDER BY '.$this->Cache->dbprefix.'order DESC 239 LIMIT 0,1' ); 240 241 if( count( $rows ) ) 242 { 243 // instantiate the inferior element 244 $obj_inf = & $this->Cache->get_by_ID( $rows[0]->{$this->Cache->dbIDname} ); 245 246 // Update element order 247 $obj->set( 'order', $obj_inf->order ); 248 $obj->dbupdate(); 249 250 // Update inferior element order 251 $obj_inf->set( 'order', $order ); 252 $obj_inf->dbupdate(); 253 254 // EXPERIMENTAL FOR FADEOUT RESULT 255 $result_fadeout[$this->Cache->dbIDname][] = $id; 256 $result_fadeout[$this->Cache->dbIDname][] = $obj_inf->ID; 257 } 258 else 259 { 260 $Messages->add( T_('This element is already at the top.'), 'error' ); 261 } 262 $DB->commit(); 263 } 264 265 266 /** 267 * Move down the element order in database 268 * 269 * @param integer id element 270 * @return unknown 271 */ 272 function move_down( $id ) 273 { 274 global $DB, $Messages, $result_fadeout; 275 276 $DB->begin(); 277 278 if( ($obj = & $this->Cache->get_by_ID( $id )) === false ) 279 { 280 $Messages->head = T_('Cannot edit entry!'); 281 $Messages->add( T_('Requested entry does not exist any longer.'), 'error' ); 282 $DB->commit(); 283 return false; 284 } 285 $order = $obj->order; 286 287 // Get the ID of the inferior element which his order is the nearest 288 $rows = $DB->get_results( 'SELECT '.$this->Cache->dbIDname 289 .' FROM '.$this->Cache->dbtablename 290 .' WHERE '.$this->Cache->dbprefix.'order > '.$order 291 .' ORDER BY '.$this->Cache->dbprefix.'order ASC 292 LIMIT 0,1' ); 293 294 if( count( $rows ) ) 295 { 296 // instantiate the inferior element 297 $obj_sup = & $this->Cache->get_by_ID( $rows[0]->{$this->Cache->dbIDname} ); 298 299 // Update element order 300 $obj->set( 'order', $obj_sup->order ); 301 $obj->dbupdate(); 302 303 // Update inferior element order 304 $obj_sup->set( 'order', $order ); 305 $obj_sup->dbupdate(); 306 307 // EXPERIMENTAL FOR FADEOUT RESULT 308 $result_fadeout[$this->Cache->dbIDname][] = $id; 309 $result_fadeout[$this->Cache->dbIDname][] = $obj_sup->ID; 310 } 311 else 312 { 313 $Messages->add( T_('This element is already at the bottom.'), 'error' ); 314 } 315 $DB->commit(); 316 } 317 } 318 319 /* 320 * $Log: _dataobjectlist2.class.php,v $ 321 * Revision 1.3 2007/09/28 09:28:36 fplanque 322 * per blog advanced SEO settings 323 * 324 * Revision 1.2 2007/09/23 18:57:15 fplanque 325 * filter handling fixes 326 * 327 * Revision 1.1 2007/06/25 10:58:57 fplanque 328 * MODULES (refactored MVC) 329 * 330 * Revision 1.10 2007/06/11 22:01:52 blueyed 331 * doc fixes 332 * 333 * Revision 1.9 2007/05/26 22:21:32 blueyed 334 * Made $limit for Results configurable per user 335 * 336 * Revision 1.8 2007/04/26 00:11:09 fplanque 337 * (c) 2007 338 * 339 * Revision 1.7 2006/11/24 18:27:24 blueyed 340 * Fixed link to b2evo CVS browsing interface in file docblocks 341 */ 342 ?>
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 |
|