'g:i A', 'minutesInterval' => 15, 'minuteOptions' => array(), 'required' => false, 'emptyOptions' => false, 'smartOptions' => true, ); protected function _getInfo($name, $value = null, $attribs = null, $options = null, $listsep = null) { $info = parent::_getInfo($name, $value, $attribs, $options, $listsep); foreach ($this->_params as $paramName => $paramValue) { if (isset($info['attribs'][$paramName])) { $info[$paramName] = $info['attribs'][$paramName]; unset($info['attribs'][$paramName]); } else { $info[$paramName] = $paramValue; } } foreach (array_keys($info) as $key) { if (isset($info['attribs'][$key])) { unset($info['attribs'][$key]); } } return $info; } protected function _getValuePart($part, $value) { if (false == ($time = strtotime($value))) { return null; } return date($part, $time); } public function formTime($name, $value = null, $attribs = null) { $info = $this->_getInfo($name, $value, $attribs); extract($info); $content = ''; $formatChars = str_split($format); foreach ($formatChars as $char) { switch ($char) { case 'H': $hours = 0; while ($hours < 24) { $options[sprintf('%02d', $hours)] = sprintf('%02d', $hours); $hours++; } break; case 's': $seconds = 0; while ($seconds < 60) { $options[sprintf('%02d', $minutes)] = sprintf('%02d', $seconds); $seconds++; } break; case 'g': $options = array_keys(array_fill(1, 12, '')); $options = array_combine($options, $options); break; case 'i': if (empty($minuteOptions)) { $options = array(); $minutes = 0; while ($minutes < 60) { $options[sprintf('%02d', $minutes)] = sprintf('%02d', $minutes); $minutes+= $minutesInterval; } } else { $options = $minuteOptions; } $_value = $this->_getValuePart($char, $value); if ($_value && !array_key_exists($_value, $options) && $smartOptions) { $options[$_value] = $_value; ksort($options); } break; case 'a': case 'A': if ($char == 'a') { $options = array('am' => 'am', 'pm' => 'pm'); } else { $options = array('AM' => 'AM', 'PM' => 'PM'); } break; default: $content .= $char; continue 2; } $_value = $this->_getValuePart($char, $value); $_attribs = array('class' => 'time_' . $char); if (!$required || $emptyOptions) { $options = array('' => '') + (array) $options; } $content .= $this->view->formSelect("{$name}[{$char}]", $_value, $_attribs, $options); } return $content; } }