b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/model/_region.class.php - 151 lines - 4411 bytes - Summary - Text - Print

Description: 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 is part of the evoCore framework - {@link http://evocore.net/}

   4   * See also {@link http://sourceforge.net/projects/evocms/}.

   5   *

   6   * @copyright (c)2009-2014 by Francois PLANQUE - {@link http://fplanque.net/}

   7   * Parts of this file are copyright (c)2009 by The Evo Factory - {@link http://www.evofactory.com/}.

   8   *

   9   * {@internal License choice

  10   * - If you have received this file as part of a package, please find the license.txt file in

  11   *   the same folder or the closest folder above for complete license terms.

  12   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  13   *   then you must choose one of the following licenses before using the file:

  14   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  15   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  16   * }}

  17   *

  18   * {@internal Open Source relicensing agreement:

  19   * The Evo Factory grants Francois PLANQUE the right to license

  20   * The Evo Factory's contributions to this file and the b2evolution project

  21   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  22   * }}

  23   *

  24   * @package evocore

  25   *

  26   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  27   * @author efy-maxim: Evo Factory / Maxim.

  28   * @author fplanque: Francois Planque.

  29   *

  30   * @version $Id: _region.class.php 13 2011-10-24 23:42:53Z fplanque $

  31   */
  32  
  33  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  34  
  35  load_class( '_core/model/dataobjects/_dataobject.class.php', 'DataObject' );
  36  
  37  /**

  38   * Region Class

  39   */
  40  class Region extends DataObject
  41  {
  42      var $ctry_ID = '';
  43      var $code = '';
  44      var $name = '';
  45      var $enabled = 1;
  46      var $preferred = 0;
  47  
  48      /**

  49       * Constructor

  50       *

  51       * @param object database row

  52       */
  53  	function Region( $db_row = NULL )
  54      {
  55          // Call parent constructor:

  56          parent::DataObject( 'T_regional__region', 'rgn_', 'rgn_ID' );
  57  
  58          $this->delete_restrictions = array(
  59                  array( 'table'=>'T_users', 'fk'=>'user_rgn_ID', 'msg'=>T_('%d related users') ),
  60                  array( 'table'=>'T_regional__subregion', 'fk'=>'subrg_rgn_ID', 'msg'=>T_('%d related sub-regions') ),
  61                  array( 'table'=>'T_regional__city', 'fk'=>'city_rgn_ID', 'msg'=>T_('%d related cities') ),
  62              );
  63  
  64          $this->delete_cascades = array();
  65  
  66          if( $db_row )
  67          {
  68              $this->ID            = $db_row->rgn_ID;
  69              $this->ctry_ID       = $db_row->rgn_ctry_ID;
  70              $this->code          = $db_row->rgn_code;
  71              $this->name          = $db_row->rgn_name;
  72              $this->enabled       = $db_row->rgn_enabled;
  73              $this->preferred     = $db_row->rgn_preferred;
  74          }
  75      }
  76  
  77  
  78      /**

  79       * Load data from Request form fields.

  80       *

  81       * @return boolean true if loaded data seems valid.

  82       */
  83  	function load_from_Request()
  84      {
  85          // Country Id

  86          param( 'rgn_ctry_ID', 'integer', true );
  87          param_check_number( 'rgn_ctry_ID', T_('Please select a country'), true );
  88          $this->set_from_Request( 'ctry_ID', 'rgn_ctry_ID', true );
  89  
  90          // Name

  91          $this->set_string_from_param( 'name', true );
  92  
  93          // Code

  94          param( 'rgn_code', 'string' );
  95          param_check_regexp( 'rgn_code', '#^[A-Za-z0-9]{1,6}$#', T_('Region code must be from 1 to 6 letters.') );
  96          $this->set_from_Request( 'code', 'rgn_code' );
  97  
  98          return ! param_errors_detected();
  99      }
 100  
 101  
 102      /**

 103       * Set param value

 104       *

 105       * By default, all values will be considered strings

 106       *

 107       * @param string parameter name

 108       * @param mixed parameter value

 109       * @param boolean true to set to NULL if empty value

 110       * @return boolean true, if a value has been set; false if it has not changed

 111       */
 112  	function set( $parname, $parvalue, $make_null = false )
 113      {
 114          switch( $parname )
 115          {
 116              case 'code':
 117                  $parvalue = strtolower($parvalue);
 118              case 'name':
 119              case 'enabled':
 120              default:
 121                  return $this->set_param( $parname, 'string', $parvalue, $make_null );
 122          }
 123      }
 124  
 125  
 126      /**

 127       * Get region name.

 128       *

 129       * @return string region name

 130       */
 131  	function get_name()
 132      {
 133          return $this->name;
 134      }
 135  
 136  
 137      /**

 138       * Check existence of specified region code in rgn_code unique field.

 139       *

 140       * @return int ID if country + region code exist otherwise NULL/false

 141       */
 142  	function dbexists()
 143      {
 144          return parent::dbexists(
 145                  array( 'rgn_ctry_ID', 'rgn_code' ),
 146                  array( $this->ctry_ID, $this->code )
 147              );
 148      }
 149  }
 150  
 151  ?>

title

Description

title

Description

title

Description

title

title

Body