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

Source for file form_field_date.class.php

Documentation is available at form_field_date.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.  */
  17. require_once(TANGRA_MAIN_DIR.'form/fields/text/form_field_text.class.php');
  18. /**
  19.  *
  20.  */
  21. require_once(TANGRA_MAIN_DIR.'nls/date.inc.php');
  22.  
  23.  
  24. /**
  25.  * Represents text field that accepts date
  26.  *
  27.  * @package tangra_lib
  28.  * @subpackage form
  29.  */
  30. class Form_Field_Date extends Form_Field_Text {
  31.     /**
  32.      * Date format
  33.      *
  34.      * @var string 
  35.      * @internal
  36.      */
  37.     private $date_format;
  38.  
  39.  
  40.     /**
  41.      * Constructor
  42.      *
  43.      * @param string $name Name of the field
  44.      * @param boolean $required Is field required. Default is false
  45.      * @param integer $maxlength Maximum length of the text. Default is 10
  46.      * @param string $value - Default value. Must be valid date in YYYY-MM-DD format or 0000-00-00
  47.      * @param string $date_format - Format that will be used
  48.      */
  49.     function __construct($name$required false$maxlength 10$value NULL$date_format TANGRA_DATE_FORMAT_YYYYSMMSDD{
  50.         if ($value{
  51.             if (!is_valid_date($value$date_format)) {
  52.                 throw new Tangra_Exception('Invalid date = '.$value);
  53.             }
  54.         }
  55.  
  56.         parent::__construct($name$required$maxlength ,$value);
  57.         $this->date_format = $date_format;
  58.         $this->add_potential_error('invalid_date');
  59.     }
  60.  
  61.  
  62.     /**
  63.      * Returns format for the date
  64.      *
  65.      * @return string 
  66.      */
  67.     public function get_date_format({
  68.         return $this->date_format;
  69.     }
  70.  
  71.  
  72.     /**
  73.      * Performs basic check for validity
  74.      *
  75.      * @return boolean 
  76.      * @internal
  77.      */
  78.     public function basic_check({
  79.         $has_errors parent::basic_check();
  80.  
  81.         if (!$has_errors{
  82.             if ($this->get_html_value(!= NULL and $this->get_html_value(!= ''{
  83.                 if (!is_valid_date($this->get_html_value()$this->date_format)) {
  84.                     $this->set_error('invalid_date');
  85.                     $has_errors true;
  86.                 }
  87.             }
  88.         }
  89.  
  90.         return $has_errors;
  91.     }
  92.  
  93.  
  94.     /**
  95.      * Returns array with field properties
  96.      *
  97.      * @return array 
  98.      * @internal
  99.      */
  100.     public function get_properties_array({
  101.         $ret parent::get_properties_array();
  102.  
  103.         $ret['date_format'$this->get_date_format();
  104.  
  105.         return $ret;
  106.     }
  107. }