b2evolution PHP Cross Reference Blogging Systems

Source: /inc/generic/model/_genericordered.class.php - 130 lines - 3608 bytes - Summary - Text - Print

Description: This file implements the generic ordered 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 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: _genericordered.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/_genericelement.class.php', 'GenericElement' );
  37  
  38  /**
  39   * User property;
  40   *
  41   * Generic Ordered of users with specific permissions.
  42   *
  43   * @package evocore
  44   */
  45  class GenericOrdered extends GenericElement
  46  {
  47      // Order object
  48      var $order;
  49  
  50  
  51      /**
  52       * Constructor
  53       *
  54       * @param string Name of table in database
  55       * @param string Prefix of fields in the table
  56       * @param string Name of the ID field (including prefix)
  57       * @param object DB row
  58       */
  59  	function GenericOrdered( $tablename, $prefix = '', $dbIDname = 'ID', $db_row = NULL )
  60      {
  61          global $Debuglog;
  62  
  63          // Call parent constructor:
  64          parent::GenericElement( $tablename, $prefix, $dbIDname, $db_row );
  65  
  66          if( $db_row != NULL )
  67          {
  68              $this->order = $db_row->{$prefix.'order'};
  69          }
  70  
  71          $Debuglog->add( "Created element <strong>$this->name</strong>", 'dataobjects' );
  72      }
  73  
  74  
  75      /**
  76       * Set param value
  77       *
  78       * By default, all values will be considered strings
  79       *
  80       * {@internal Contact::set(-)}}
  81       *
  82       * @param string parameter name
  83       * @param mixed parameter value
  84       * @param boolean true to set to NULL if empty value
  85       * @return boolean true, if a value has been set; false if it has not changed
  86       */
  87  	function set( $parname, $parvalue, $make_null = false )
  88      {
  89          switch( $parname )
  90          {
  91               case 'order':
  92                  return $this->set_param( $parname, 'number', $parvalue, $make_null );
  93  
  94              case 'name':
  95              default:
  96                  return $this->set_param( $parname, 'string', $parvalue, $make_null );
  97          }
  98      }
  99  
 100  
 101      /**
 102       * Insert object into DB based on previously recorded changes
 103       */
 104  	function dbinsert()
 105      {
 106          global $DB;
 107  
 108          $DB->begin();
 109  
 110          if( $max_order = $DB->get_var( 'SELECT MAX('.$this->dbprefix.'order)
 111                                                                              FROM '.$this->dbtablename ) )
 112          {    // The new element order must be the lastest
 113              $max_order++;
 114          }
 115          else
 116          { // There are no elements in the database yet, so his order is set to 1.
 117              $max_order = 1;
 118          }
 119  
 120          // Set Object order:
 121          $this->set( 'order', $max_order );
 122  
 123          parent::dbinsert();
 124  
 125          $DB->commit();
 126      }
 127  
 128  }
 129  
 130  ?>

title

Description

title

Description

title

Description

title

title

Body