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

Source for file form_field_integer_limited.class.php

Documentation is available at form_field_integer_limited.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. //  $Id$
  4. //
  5.  
  6. /**
  7.  * Contains class Form_Field_Date
  8.  *
  9.  * @package tangra_lib
  10.  * @subpackage form
  11.  */
  12.  
  13. /**
  14.  *
  15.  */
  16. require_once(TANGRA_MAIN_DIR.'form/fields/integer/form_field_integer.class.php');
  17.  
  18.  
  19. /**
  20.  * Represents text field that accepts limited integer
  21.  *
  22.  * @package tangra_lib
  23.  * @subpackage form
  24.  */
  25.     /**
  26.      * Minumum value
  27.      *
  28.      * @var integer 
  29.      * @internal
  30.      */
  31.     private $min_val;
  32.     /**
  33.      * Maximum value
  34.      *
  35.      * @var integer 
  36.      * @internal
  37.      */
  38.     private $max_val;
  39.  
  40.  
  41.     /**
  42.      * Constructor
  43.      *
  44.      * @param string $name Name of the field
  45.      * @param integer $min_val Minimum accepted value
  46.      * @param integer $max_val maximum accepted value
  47.      * @param boolean $required Is field required. Default is false
  48.      * @param integer $maxlength Maximum length of the text. Default is 10
  49.      * @param integer $value Default value
  50.      */
  51.     function __construct($name$min_val$max_val$required false$maxlength 100$value NULL{
  52.         parent::__construct($name$required$maxlength$value);
  53.  
  54.         $this->set_min_val($min_val);
  55.         $this->set_max_val($max_val);
  56.  
  57.         $this->add_potential_error('integer_greater');
  58.         $this->add_potential_error('integer_smaller');
  59.     }
  60.  
  61.  
  62.     /**
  63.      * Sets minimum accepted value
  64.      *
  65.      * @param integer $min_val 
  66.      */
  67.     public function set_min_val($min_val{
  68.         tangra_if_not_int_throw_e($min_val);
  69.         $this->min_val = $min_val;
  70.     }
  71.  
  72.  
  73.     /**
  74.      * Sets maximum accepted value
  75.      *
  76.      * @param integer $max_val 
  77.      */
  78.     public function set_max_val($max_val{
  79.         tangra_if_not_int_throw_e($max_val);
  80.         $this->max_val = $max_val;
  81.     }
  82.  
  83.  
  84.     /**
  85.      * Returns minimum accepted value
  86.      *
  87.      * @return integer 
  88.      */
  89.     public function get_min_val({
  90.         return $this->min_val;
  91.     }
  92.  
  93.  
  94.     /**
  95.      * Returns maximum accepted value
  96.      *
  97.      * @return integer 
  98.      */
  99.     public function get_max_val({
  100.         return $this->max_val;
  101.     }
  102.  
  103.  
  104.     /**
  105.      * Performs basic check for validity
  106.      *
  107.      * @return boolean 
  108.      * @internal
  109.      */
  110.     public function basic_check({
  111.         $has_errors parent::basic_check();
  112.  
  113.         if (!$has_errors{
  114.             if ($this->get_html_value($this->get_min_val()) {
  115.                 $this->set_error('integer_smaller');
  116.                 $has_errors true;
  117.             else {
  118.                 if ($this->get_html_value($this->get_max_val()) {
  119.                     $this->set_error('integer_greater');
  120.                     $has_errors true;
  121.                 }
  122.             }
  123.         }
  124.  
  125.         return $has_errors;
  126.     }
  127.  
  128.  
  129.     /**
  130.      * Returns array with field properties
  131.      *
  132.      * @return array 
  133.      * @internal
  134.      */
  135.     public function get_properties_array({
  136.         $ret parent::get_properties_array();
  137.         $ret['min_val'$this->get_min_val();
  138.         $ret['max_val'$this->get_max_val();
  139.  
  140.         return $ret;
  141.     }
  142.  
  143. }