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

Source for file form_field_integer_positive.class.php

Documentation is available at form_field_integer_positive.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. //  $Id$
  4. //
  5.  
  6.  
  7. /**
  8.  * Contains class Form_Field_Integer_Positive
  9.  *
  10.  * @package tangra_lib
  11.  * @subpackage form
  12.  */
  13.  
  14. /**
  15.  *
  16.  */
  17. require_once(TANGRA_MAIN_DIR.'form/fields/integer/form_field_integer.class.php');
  18.  
  19.  
  20.  
  21. /**
  22.  * Represents text field that accepts positive integer value
  23.  *
  24.  * @package tangra_lib
  25.  * @subpackage form
  26.  */
  27.     /**
  28.      * Will accept zero
  29.      *
  30.      * @var boolean 
  31.      * @internal
  32.      */
  33.     private $accept_zero;
  34.  
  35.     /**
  36.      * Constructor
  37.      *
  38.      * @param string $name Name of the field
  39.      * @param boolean $accept_zero Will object zero as valid value?
  40.      * @param boolean $required Is field required. Default is false
  41.      * @param integer $maxlength Maximum length of the text. Default is 100
  42.      * @param integer $value Default value.
  43.      */
  44.     function __construct($name$accept_zero false$required false$maxlength 100$value NULL{
  45.         parent::__construct($name$required$maxlength$value);
  46.  
  47.         $this->accept_zero = $accept_zero;
  48.         $this->add_potential_error('integer_not_positive');
  49.     }
  50.  
  51.  
  52.     /**
  53.      * Returns true if accepts zero as valid value
  54.      *
  55.      * @return unknown 
  56.      */
  57.     public function get_accept_zero({
  58.         return $this->accept_zero;
  59.     }
  60.  
  61.  
  62.     /**
  63.      * Performs basic check for validity
  64.      *
  65.      * @return boolean 
  66.      * @internal
  67.      */
  68.     public function basic_check({
  69.         $has_errors parent::basic_check();
  70.  
  71.         if (!$has_errors{
  72.             if ($this->get_html_value(!= NULL and $this->get_html_value(!= ''{
  73.                 if ($this->get_accept_zero()) {
  74.                     if ($this->get_html_value({
  75.                         $this->set_error('integer_not_positive');
  76.                         $has_errors true;
  77.                     }
  78.                 else {
  79.                     if ($this->get_html_value(<= {
  80.                         $this->set_error('integer_not_positive');
  81.                         $has_errors true;
  82.                     }
  83.                 }
  84.             }
  85.         }
  86.  
  87.         return $has_errors;
  88.     }
  89.  
  90.  
  91.     /**
  92.      * Returns array with field properties
  93.      *
  94.      * @return array 
  95.      * @internal
  96.      */
  97.     public function get_properties_array({
  98.         $ret parent::get_properties_array();
  99.  
  100.         return $ret;
  101.     }
  102. }