tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Source for file form_field_number_nls.class.php

Documentation is available at form_field_number_nls.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. //  $Id$
  4. //
  5.  
  6.  
  7.  
  8. /**
  9.  * Contains class Form_Field_Number_NLS
  10.  *
  11.  * @package tangra_lib
  12.  * @subpackage form
  13.  */
  14.  
  15. /**
  16.  *
  17.  */
  18. require_once(TANGRA_MAIN_DIR.'form/fields/text/form_field_text.class.php');
  19. /**
  20.  *
  21.  */
  22. require_once(TANGRA_MAIN_DIR.'nls/number_functions.inc.php');
  23.  
  24.  
  25. /**
  26.  * Represents text field that accepts number formated according some NLS specifics
  27.  *
  28.  * @package tangra_lib
  29.  * @subpackage form
  30.  */
  31.     /**
  32.      * Separator for thousands
  33.      *
  34.      * @var string 
  35.      * @internal
  36.      */
  37.     private $thousands_separator;
  38.     /**
  39.      * Decimal separator
  40.      *
  41.      * @var string 
  42.      * @internal
  43.      */
  44.     private $floating_separator;
  45.  
  46.  
  47.     /**
  48.      * Constructor
  49.      *
  50.      * @param string $name Name of the field
  51.      * @param boolean $required Is field required. Default is false
  52.      * @param integer $maxlength Maximum length of the text. Default is 100
  53.      * @param string $value Default value.
  54.      * @param string $thousands_separator Separator for thousands
  55.      * @param string $floating_separator Decimal separator
  56.      */
  57.     function __construct($name$required false$maxlength 100$value NULL$thousands_separator ' '$floating_separator '.'{
  58.         parent::__construct($name$required$maxlength$value);
  59.  
  60.         $this->set_separators($thousands_separator$floating_separator);
  61.  
  62.         $this->add_potential_error('not_a_number');
  63.     }
  64.  
  65.  
  66.     /**
  67.      * Sets separators
  68.      *
  69.      * @param string $thousands_separator Thousands separator
  70.      * @param string $floating_separator Decimal separator
  71.      */
  72.     public function set_separators($thousands_separator$floating_separator{
  73.         if ($thousands_separator == $floating_separator{
  74.             throw new Tangra_Exception('Thousands separator and Floating separator can not be the same = '$thousands_separator);
  75.         }
  76.  
  77.         if ($thousands_separator != ',' && $thousands_separator != ' ' && $thousands_separator != '.' && $thousands_separator != ''{
  78.             throw new Tangra_Exception('Invalid thousands separator = "'.$thousands_separator.'". Must be "," (comma) or " "(space) or empty.');
  79.         }
  80.  
  81.         $this->thousands_separator = $thousands_separator;
  82.  
  83.         if ($floating_separator != '.' && $floating_separator != ","{
  84.             throw new Tangra_Exception('Invalid floating separator = "'.$floating_separator.'". Must be "."(dot) or ","(comma)');
  85.         }
  86.  
  87.         $this->floating_separator = $floating_separator;
  88.  
  89.     }
  90.  
  91.     /**
  92.      * Returns thousands separator
  93.      *
  94.      * @return string 
  95.      */
  96.     public function get_thousands_separator({
  97.         return $this->thousands_separator;
  98.     }
  99.  
  100.  
  101.     /**
  102.      * Returns decimal separator
  103.      *
  104.      * @return unknown 
  105.      */
  106.     public function get_floating_separator({
  107.         return $this->floating_separator;
  108.     }
  109.  
  110.  
  111.     /**
  112.      * Alias of get_floating_separator
  113.      *
  114.      * @return unknown 
  115.      */
  116.     public function get_decimal_separator({
  117.         return $this->get_floating_separator();
  118.     }
  119.  
  120.  
  121.     /**
  122.      * Performs basic check for validity
  123.      *
  124.      * @return boolean 
  125.      * @internal
  126.      */
  127.     public function basic_check({
  128.         $has_errors parent::basic_check();
  129.  
  130.         if (!$has_errors{
  131.             if ($this->get_html_value(!= NULL and $this->get_html_value(!= ''{
  132. //printbr($this->convert_number($this->get_html_value()));
  133.                 if (!(convert_number_from_nls_format($this->get_html_value()$this->get_floating_separator()$this->get_thousands_separator()) !== false)) {
  134.                     $this->set_error('not_a_number');
  135.                     $has_errors true;
  136.                 }
  137.             }
  138.         }
  139.  
  140.         return $has_errors;
  141.     }
  142.  
  143.  
  144.     /**
  145.      * Transfers data from html_value to value
  146.      * @internal
  147.      */
  148.     protected function translate_value_html2app({
  149.     }
  150. }