b2evolution PHP Cross Reference Blogging Systems

Source: /inc/generic/model/_genericorderedcache.class.php - 158 lines - 4752 bytes - Summary - Text - Print

Description: This file implements the Generic Ordered Cache class. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the Generic Ordered Cache 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-2014 by Francois Planque - {@link http://fplanque.com/}
   9   * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}.
  10   *
  11   * {@internal License choice
  12   * - If you have received this file as part of a package, please find the license.txt file in
  13   *   the same folder or the closest folder above for complete license terms.
  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15   *   then you must choose one of the following licenses before using the file:
  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18   * }}
  19   *
  20   * {@internal Open Source relicensing agreement:
  21   * PROGIDISTRI S.A.S. grants Francois PLANQUE the right to license
  22   * PROGIDISTRI S.A.S.'s contributions to this file and the b2evolution project
  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  24   * }}
  25   *
  26   * @package evocore
  27   *
  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  29   * @author fplanque: Francois PLANQUE.
  30   * @author mbruneau: Marc BRUNEAU / PROGIDISTRI
  31   *
  32   * @version $Id: _genericorderedcache.class.php 6136 2014-03-08 07:59:48Z manuel $
  33   */
  34  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  35  
  36  load_class( 'generic/model/_genericcache.class.php', 'GenericCache' );
  37  
  38  /**
  39   * GenericOrderedCache Class
  40   * @package evocore
  41   */
  42  class GenericOrderedCache extends GenericCache
  43  {
  44      /**
  45       * Constructor
  46       */
  47  	function GenericOrderedCache( $objtype, $load_all, $tablename, $prefix = '', $dbIDname = 'ID', $name_field = NULL )
  48      {
  49          parent::GenericCache( $objtype, $load_all, $tablename, $prefix, $dbIDname, $name_field );
  50      }
  51  
  52  
  53      /**
  54       * Move up the element order in database
  55       *
  56       * @param integer id element
  57       * @return unknown
  58       */
  59  	function move_up_by_ID( $id )
  60      {
  61          global $DB, $Messages, $result_fadeout;
  62  
  63          $DB->begin();
  64  
  65          if( ($obj_sup = & $this->get_by_ID( $id )) === false )
  66          {
  67          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Entry') ), 'error' );
  68              $DB->commit();
  69              return false;
  70          }
  71          $order = $obj_sup->order;
  72  
  73          // Get the ID of the inferior element which his order is the nearest
  74          $rows = $DB->get_results( 'SELECT '.$this->dbIDname
  75                                                               .' FROM '.$this->dbtablename
  76                                                           .' WHERE '.$this->dbprefix.'order < '.$order
  77                                                      .' ORDER BY '.$this->dbprefix.'order DESC
  78                                                                   LIMIT 0,1' );
  79  
  80          if( count( $rows ) )
  81          {
  82              // instantiate the inferior element
  83              $obj_inf = & $this->get_by_ID( $rows[0]->{$this->dbIDname} );
  84  
  85              // Update element order
  86              $obj_sup->set( 'order', $obj_inf->order );
  87              $obj_sup->dbupdate();
  88  
  89              // Update inferior element order
  90              $obj_inf->set( 'order', $order );
  91              $obj_inf->dbupdate();
  92  
  93              // EXPERIMENTAL FOR FADEOUT RESULT
  94              $result_fadeout[$this->dbIDname][] = $id;
  95              $result_fadeout[$this->dbIDname][] = $obj_inf->ID;
  96          }
  97          else
  98          {
  99              $Messages->add( T_('This element is already at the top.'), 'error' );
 100          }
 101          $DB->commit();
 102      }
 103  
 104  
 105      /**
 106       * Move down the element order in database
 107       *
 108       * @param integer id element
 109       * @return unknown
 110       */
 111  	function move_down_by_ID( $id )
 112      {
 113          global $DB, $Messages, $result_fadeout;
 114  
 115          $DB->begin();
 116  
 117          if( ($obj_inf = & $this->get_by_ID( $id )) === false )
 118          {
 119              $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Entry') ), 'error' );
 120              $DB->commit();
 121              return false;
 122          }
 123          $order = $obj_inf->order;
 124  
 125          // Get the ID of the inferior element which his order is the nearest
 126          $rows = $DB->get_results( 'SELECT '.$this->dbIDname
 127                                                               .' FROM '.$this->dbtablename
 128                                                           .' WHERE '.$this->dbprefix.'order > '.$order
 129                                                      .' ORDER BY '.$this->dbprefix.'order ASC
 130                                                                   LIMIT 0,1' );
 131  
 132          if( count( $rows ) )
 133          {
 134              // instantiate the inferior element
 135              $obj_sup = & $this->get_by_ID( $rows[0]->{$this->dbIDname} );
 136  
 137              //  Update element order
 138              $obj_inf->set( 'order', $obj_sup->order );
 139              $obj_inf->dbupdate();
 140  
 141              // Update inferior element order
 142              $obj_sup->set( 'order', $order );
 143              $obj_sup->dbupdate();
 144  
 145              // EXPERIMENTAL FOR FADEOUT RESULT
 146              $result_fadeout[$this->dbIDname][] = $id;
 147              $result_fadeout[$this->dbIDname][] = $obj_sup->ID;
 148          }
 149          else
 150          {
 151              $Messages->add( T_('This element is already at the bottom.'), 'error' );
 152          }
 153          $DB->commit();
 154      }
 155  
 156  }
 157  
 158  ?>

title

Description

title

Description

title

Description

title

title

Body