b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/model/_country.class.php - 149 lines - 4205 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: _country.class.php 6136 2014-03-08 07:59:48Z manuel $
  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   * Country Class
  39   */
  40  class Country extends DataObject
  41  {
  42      var $code = '';
  43      var $name = '';
  44      var $curr_ID = '';
  45      var $enabled = 1;
  46      var $preferred = 0;
  47  
  48      /**
  49       * Constructor
  50       *
  51       * @param object database row
  52       */
  53  	function Country( $db_row = NULL )
  54      {
  55          // Call parent constructor:
  56          parent::DataObject( 'T_regional__country', 'ctry_', 'ctry_ID' );
  57  
  58          $this->delete_restrictions = array(
  59                  array( 'table'=>'T_users', 'fk'=>'user_ctry_ID', 'msg'=>T_('%d related users') ),
  60                  array( 'table'=>'T_regional__region', 'fk'=>'rgn_ctry_ID', 'msg'=>T_('%d related regions') ),
  61                  array( 'table'=>'T_regional__city', 'fk'=>'city_ctry_ID', 'msg'=>T_('%d related cities') ),
  62              );
  63  
  64          $this->delete_cascades = array();
  65  
  66          if( $db_row )
  67          {
  68              $this->ID            = $db_row->ctry_ID;
  69              $this->code          = $db_row->ctry_code;
  70              $this->name          = $db_row->ctry_name;
  71              $this->curr_ID       = $db_row->ctry_curr_ID;
  72              $this->enabled       = $db_row->ctry_enabled;
  73              $this->preferred     = $db_row->ctry_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          // Name
  86          $this->set_string_from_param( 'name', true );
  87  
  88          // Code
  89          param( 'ctry_code', 'string' );
  90          param_check_regexp( 'ctry_code', '#^[A-Za-z]{2}$#', T_('Country code must be 2 letters.') );
  91          $this->set_from_Request( 'code', 'ctry_code' );
  92  
  93          // Currency Id
  94          param( 'ctry_curr_ID', 'integer' );
  95          param_check_number( 'ctry_curr_ID', T_('Please select a currency') );
  96          $this->set_from_Request( 'curr_ID', 'ctry_curr_ID', true );
  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 'curr_ID':
 120              case 'enabled':
 121              default:
 122                  return $this->set_param( $parname, 'string', $parvalue, $make_null );
 123          }
 124      }
 125  
 126  
 127      /**
 128       * Get country name.
 129       *
 130       * @return string currency code
 131       */
 132  	function get_name()
 133      {
 134          return $this->name;
 135      }
 136  
 137  
 138      /**
 139       * Check existence of specified country code in ctry_code unique field.
 140       *
 141       * @return int ID if country code exists otherwise NULL/false
 142       */
 143  	function dbexists()
 144      {
 145          return parent::dbexists('ctry_code', $this->code);
 146      }
 147  }
 148  
 149  ?>

title

Description

title

Description

title

Description

title

title

Body