Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

time-field.inc.php

Go to the documentation of this file.
00001 <?php
00009 class TimeField extends AbstractField
00010 {
00014     protected $mode = '12';
00015 
00024     public function __construct($name, Form &$parentForm, array $attribs = array())
00025     {
00026         parent::__construct($name, $parentForm, $attribs);
00027 
00028         if(isset($this->extras['mode']))
00029         {
00030             if($this->extras['mode'] == 12 || $this->extras['mode'] == 24) 
00031                 $this->mode = $this->extras['mode'];
00032             else
00033                 throw new Exception("Invalid time field mode: $this->extras[mode]");
00034 
00035             unset($this->extras['mode']);
00036         }
00037         else
00038             $this->mode = 12;
00039 
00040         $this->value = 'now';
00041     }
00042 
00043     
00047     public function drawInput()
00048     {
00049         $time = getdate(strtotime($this->value));
00050         
00051         # Hour
00052         $displayHour = $this->mode == 12 ? ($time['hours'] > 12 ? $time['hours'] - 12 : $time['hours']) 
00053             : $time['hours'];
00054 
00055         echo "<select name='{$this->name}_hour'>";
00056         for($i = 1; $i <= $this->mode; $i++)
00057             echo "\t<option value='$i'", $displayHour == $i ? ' selected="selected">' : '>',
00058                 $i, "</option>\n";
00059         echo "</select>:";
00060 
00061         # Minute
00062         echo "<select name='{$this->name}_minute'>";
00063         for($i = 0; $i <= 60; $i++)
00064             echo "<option value='$i'", $time['minutes'] == $i ? ' selected="selected">' : '>',
00065                 str_pad($i, 2, 0, STR_PAD_LEFT), "</option>\n";
00066 
00067         echo "</select>";
00068 
00069         # Meridiem
00070         if($this->mode == 12)
00071         {
00072             echo "\n<select name='{$this->name}_meridiem'>";
00073             echo '<option value="am"' . ($time['hours'] <= 12 ? ' selected="selected">' : '>') . 'AM</option>';
00074             echo '<option value="pm"' . ($time['hours'] > 12 ? ' selected="selected">' : '>') . 'PM</option>';
00075             echo "</select>\n";
00076         }
00077     }
00078 
00082     public function setDataFromRequest()
00083     {
00084         if(isset($_REQUEST["{$this->name}_meridiem"]))
00085             $hour = $_REQUEST["{$this->name}_meridiem"] == 'pm' ? $_REQUEST["{$this->name}_hour"] + 12 :
00086                 (int)$_REQUEST["{$this->name}_hour"];
00087         else
00088             $hour = (int)$_REQUEST["{$this->name}_hour"];
00089             
00090         $this->value = "$hour:" . str_pad($_REQUEST["{$this->name}_minute"], 2, 0);
00091     }
00092 }
00093 ?>

Generated on Fri Oct 27 12:26:40 2006 for BaseJumper by doxygen 1.3.9.1