b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/model/_currency.class.php - 178 lines - 4889 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: _currency.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   * Currency Class
  39   */
  40  class Currency extends DataObject
  41  {
  42      var $code = '';
  43      var $shortcut = '';
  44      var $name = '';
  45      var $enabled = 1;
  46  
  47      /**
  48       * Constructor
  49       *
  50       * @param object database row
  51       */
  52  	function Currency( $db_row = NULL )
  53      {
  54          // Call parent constructor:
  55          parent::DataObject( 'T_regional__currency', 'curr_', 'curr_ID' );
  56  
  57          $this->delete_restrictions = array(
  58                  array( 'table'=>'T_regional__country', 'fk'=>'ctry_curr_ID', 'msg'=>T_('%d related countries') ),
  59              );
  60  
  61          $this->delete_cascades = array();
  62  
  63           if( $db_row )
  64          {
  65              $this->ID            = $db_row->curr_ID;
  66              $this->code          = $db_row->curr_code;
  67              $this->shortcut      = $db_row->curr_shortcut;
  68              $this->name          = $db_row->curr_name;
  69              $this->enabled       = $db_row->curr_enabled;
  70          }
  71      }
  72  
  73  
  74      /**
  75       * Load data from Request form fields.
  76       *
  77       * @return boolean true if loaded data seems valid.
  78       */
  79  	function load_from_Request()
  80      {
  81          // Name
  82          $this->set_string_from_param( 'name', true );
  83  
  84          // Shortcut
  85          $this->set_string_from_param( 'shortcut', true );
  86  
  87          // Code
  88          param( 'curr_code', 'string' );
  89          param_check_regexp( 'curr_code', '#^[A-Za-z]{3}$#', T_('Currency code must be 3 letters.') );
  90          $this->set_from_Request( 'code', 'curr_code', true  );
  91  
  92          return ! param_errors_detected();
  93      }
  94  
  95  
  96      /**
  97       * Set param value
  98       *
  99       * By default, all values will be considered strings
 100       *
 101       * @param string parameter name
 102       * @param mixed parameter value
 103       * @param boolean true to set to NULL if empty value
 104       * @return boolean true, if a value has been set; false if it has not changed
 105       */
 106  	function set( $parname, $parvalue, $make_null = false )
 107      {
 108          switch( $parname )
 109          {
 110              case 'code':
 111                  $parvalue = strtoupper($parvalue);
 112              case 'shortcut':
 113              case 'name':
 114              case 'enabled':
 115              default:
 116                  return $this->set_param( $parname, 'string', $parvalue, $make_null );
 117          }
 118      }
 119  
 120  
 121      /**
 122       * Check existence of specified currency code in curr_code unique field.
 123       *
 124       * @return int ID if currency code exists otherwise NULL/false
 125       */
 126  	function dbexists()
 127      {
 128          return parent::dbexists('curr_code', $this->code);
 129      }
 130  
 131  
 132      /**
 133       * Get currency unique name (code).
 134       *
 135       * @return string currency code
 136       */
 137  	function get_name()
 138      {
 139          return $this->code;
 140      }
 141  
 142  
 143      /**
 144       * Get link to Countries, where this Currencie is used
 145       * Use when try to delete a currencie
 146       *  
 147       * @param array restriction array 
 148       * @return string link to currency's countries
 149       */
 150  	function get_restriction_link( $restriction )
 151      {
 152          global $DB, $admin_url;
 153  
 154          if( $restriction['fk'] != 'ctry_curr_ID' )
 155          { // currency restriction exists only for countries
 156              debug_die( 'Restriction does not exists' );
 157          }
 158  
 159          // link to country object
 160          $link = '<a href="'.$admin_url.'?ctrl=countries&action=edit&ctry_ID=%d">%s</a>';
 161          // set sql to get country ID and name
 162          $objectID_query = 'SELECT ctry_ID, ctry_name'
 163                          .' FROM '.$restriction['table']
 164                          .' WHERE '.$restriction['fk'].' = '.$this->ID;
 165  
 166          $result_link = '';
 167          $query_result = $DB->get_results( $objectID_query );
 168          foreach( $query_result as $row )
 169          {
 170              $result_link .= '<br/>'.sprintf( $link, $row->ctry_ID, $row->ctry_name );
 171          }
 172  
 173          $result_link = sprintf( $restriction['msg'].$result_link, count($query_result) );
 174          return $result_link;
 175      }
 176  }
 177  
 178  ?>

title

Description

title

Description

title

Description

title

title

Body