00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Varien_Data_Form_Element_Time extends Varien_Data_Form_Element_Abstract
00035 {
00036 public function __construct($attributes=array())
00037 {
00038 parent::__construct($attributes);
00039 $this->setType('time');
00040 }
00041
00042 public function getName()
00043 {
00044 $name = parent::getName();
00045 if (strpos($name, '[]') === false) {
00046 $name.= '[]';
00047 }
00048 return $name;
00049 }
00050
00051 public function getElementHtml()
00052 {
00053 $this->addClass('select');
00054
00055 $value_hrs = 0;
00056 $value_min = 0;
00057 $value_sec = 0;
00058
00059 if( $value = $this->getValue() ) {
00060 $values = explode(',', $value);
00061 if( is_array($values) && count($values) == 3 ) {
00062 $value_hrs = $values[0];
00063 $value_min = $values[1];
00064 $value_sec = $values[2];
00065 }
00066 }
00067
00068 $html = '<select name="'. $this->getName() . '" '.$this->serialize($this->getHtmlAttributes()).' style="width:40px">'."\n";
00069 for( $i=0;$i<24;$i++ ) {
00070 $hour = str_pad($i, 2, '0', STR_PAD_LEFT);
00071 $html.= '<option value="'.$hour.'" '. ( ($value_hrs == $i) ? 'selected="selected"' : '' ) .'>' . $hour . '</option>';
00072 }
00073 $html.= '</select>'."\n";
00074
00075 $html.= ' : <select name="'. $this->getName() . '" '.$this->serialize($this->getHtmlAttributes()).' style="width:40px">'."\n";
00076 for( $i=0;$i<60;$i++ ) {
00077 $hour = str_pad($i, 2, '0', STR_PAD_LEFT);
00078 $html.= '<option value="'.$hour.'" '. ( ($value_min == $i) ? 'selected="selected"' : '' ) .'>' . $hour . '</option>';
00079 }
00080 $html.= '</select>'."\n";
00081
00082 $html.= ' : <select name="'. $this->getName() . '" '.$this->serialize($this->getHtmlAttributes()).' style="width:40px">'."\n";
00083 for( $i=0;$i<60;$i++ ) {
00084 $hour = str_pad($i, 2, '0', STR_PAD_LEFT);
00085 $html.= '<option value="'.$hour.'" '. ( ($value_sec == $i) ? 'selected="selected"' : '' ) .'>' . $hour . '</option>';
00086 }
00087 $html.= '</select>'."\n";
00088 $html.= $this->getAfterElementHtml();
00089 return $html;
00090 }
00091 }