source: trunk/patForms/Element/Date/Element/Day.php @ 256

Revision 256, 1.9 KB checked in by schst, 8 years ago (diff)

Adjusted the subpackage to Element to match all other files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/**
3 * patForms Date subelement Day
4 *
5 * Handles day input and validation for the date element
6 *
7 * $Id$
8 *
9 * @access      public
10 * @package     patForms
11 * @subpackage  Element
12 * @author      Sebastian 'The Argh' Mordziol <argh@php-tools.net>
13 */
14
15/**
16 * patForms Date subelement Day
17 *
18 * Handles day input and validation for the date element
19 *
20 * $Id$
21 *
22 * @access      public
23 * @package     patForms
24 * @subpackage  Element
25 * @author      Sebastian 'The Argh' Mordziol <argh@php-tools.net>
26 */
27class patForms_Element_Date_Element_Day extends patForms_Element_Date_Element
28{
29   /**
30    * Stores all needed token configurations, i.e. the length and output
31    * format of the corresponding values.
32    *
33    * @access   private
34    * @var      array
35    */
36    var $tokens = array(
37        'd' => array(
38            'length'    =>  2,
39            'format'    =>  '%02d',
40            'getter'    =>  'getDay',
41            'setter'    =>  'setDay',
42        ),
43        'j' => array(
44            'length'    =>  2,
45            'format'    =>  '%01d',
46            'getter'    =>  'getDay',
47            'setter'    =>  'setDay',
48        )
49    );
50   
51   /**
52    * Stores a compatibility table of date tokens that will be converted if used
53    * to the alternate token specified.
54    *
55    * @access   private
56    * @var      array
57    */
58    var $compatTable = array(
59        'j' =>  'd',
60    );
61   
62   /**
63    * Retrieves values for the selector when using the preset mode.
64    *
65    * @access   private
66    * @return   array   $values Values list in patForms format
67    */
68    function getValues()
69    {
70        $values = array();
71       
72        for( $i=1; $i <= 31; $i++ ) {
73            $label = sprintf( $this->tokens[$this->token]['format'], $i );
74            $value = $i;
75           
76            array_push( 
77                $values, 
78                array(
79                    'label' => $label,
80                    'value' => $value
81                )
82            );
83        }
84       
85        return $values;
86    }
87   
88   /**
89    * Validates the element.
90    *
91    * @access   public
92    * @return   bool    $valid  True if valid, false otherwise
93    */
94    function validate()
95    {
96        $value = $this->getValue();
97        if( is_null( $value ) ) {
98            return false;
99        }
100       
101        if( $value < 1 || $value > 32 ) {
102            return false;
103        }
104       
105        return true;
106    }
107}
108
109?>
Note: See TracBrowser for help on using the repository browser.