b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/model/_subregion.class.php - 168 lines - 4943 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: _subregion.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   * Subregion Class

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

  50       * Constructor

  51       *

  52       * @param object database row

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

  57          parent::DataObject( 'T_regional__subregion', 'subrg_', 'subrg_ID' );
  58  
  59          $this->delete_restrictions = array(
  60                  array( 'table'=>'T_users', 'fk'=>'user_subrg_ID', 'msg'=>T_('%d related users') ),
  61                  array( 'table'=>'T_regional__city', 'fk'=>'city_subrg_ID', 'msg'=>T_('%d related cities') ),
  62              );
  63  
  64          $this->delete_cascades = array();
  65  
  66          if( $db_row )
  67          {
  68              $this->ID            = $db_row->subrg_ID;
  69              $this->rgn_ID        = $db_row->subrg_rgn_ID;
  70              $this->code          = $db_row->subrg_code;
  71              $this->name          = $db_row->subrg_name;
  72              $this->enabled       = $db_row->subrg_enabled;
  73              $this->preferred     = $db_row->subrg_preferred;
  74  
  75              // Load Region class

  76              load_class( 'regional/model/_region.class.php', 'Region' );
  77  
  78              $RegionCache = & get_RegionCache();
  79              if( ! empty( $this->rgn_ID ) )
  80              {
  81                  if( ($Region = & $RegionCache->get_by_ID( $db_row->subrg_rgn_ID, false )) !== false )
  82                  {    // Get country ID
  83                      $this->ctry_ID       = $Region->ctry_ID;
  84                  }
  85              }
  86          }
  87      }
  88  
  89  
  90      /**

  91       * Load data from Request form fields.

  92       *

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

  94       */
  95  	function load_from_Request()
  96      {
  97          // Country Id

  98          param( 'subrg_ctry_ID', 'integer', true );
  99          param_check_number( 'subrg_ctry_ID', T_('Please select a country'), true );
 100          $this->set_from_Request( 'ctry_ID', 'subrg_ctry_ID', true );
 101  
 102          // Region Id

 103          param( 'subrg_rgn_ID', 'integer', true );
 104          param_check_number( 'subrg_rgn_ID', T_('Please select a region'), true );
 105          $this->set_from_Request( 'rgn_ID', 'subrg_rgn_ID', true );
 106  
 107          // Name

 108          $this->set_string_from_param( 'name', true );
 109  
 110          // Code

 111          param( 'subrg_code', 'string' );
 112          param_check_regexp( 'subrg_code', '#^[A-Za-z0-9]{1,6}$#', T_('Sub-region code must be from 1 to 6 letters.') );
 113          $this->set_from_Request( 'code', 'subrg_code' );
 114  
 115          return ! param_errors_detected();
 116      }
 117  
 118  
 119      /**

 120       * Set param value

 121       *

 122       * By default, all values will be considered strings

 123       *

 124       * @param string parameter name

 125       * @param mixed parameter value

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

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

 128       */
 129  	function set( $parname, $parvalue, $make_null = false )
 130      {
 131          switch( $parname )
 132          {
 133              case 'code':
 134                  $parvalue = strtolower($parvalue);
 135              case 'name':
 136              case 'enabled':
 137              default:
 138                  return $this->set_param( $parname, 'string', $parvalue, $make_null );
 139          }
 140      }
 141  
 142  
 143      /**

 144       * Get subregion name.

 145       *

 146       * @return string subregion name

 147       */
 148  	function get_name()
 149      {
 150          return $this->name;
 151      }
 152  
 153  
 154      /**

 155       * Check existence of specified sub-region code in subrg_code unique field.

 156       *

 157       * @return int ID if region + sub-region code exist otherwise NULL/false

 158       */
 159  	function dbexists()
 160      {
 161          return parent::dbexists(
 162                  array( 'subrg_rgn_ID', 'subrg_code' ),
 163                  array( $this->rgn_ID, $this->code )
 164              );
 165      }
 166  }
 167  
 168  ?>

title

Description

title

Description

title

Description

title

title

Body