/** * Constructor. * * Available options: * * * format: The time format string (%hour%:%minute%) * * hours: An array of hours for the hour select tag (optional) * * minutes: An array of minutes for the minute select tag (optional) * * can_be_empty: Whether the widget accept an empty value (true by default) * * empty_value: String to use as empty value * * @param array $options An array of options * @param array $attributes An array of default HTML attributes * * @see sfWidgetForm */ protected function configure($options = array(), $attributes = array()) { $this->addOption('format', '%hour%:%minute%'); $this->addOption('hours', parent::generateTwoCharsRange(0, 23)); $this->addOption('minutes', array('00', '15', '30', '45')); $this->addOption('can_be_empty', true); $this->addOption('empty_value', ''); }
/** * Configures the current widget. * * The attributes are passed to both the date and the time widget. * * If you want to pass HTML attributes to one of the two widget, pass an * attributes option to the date or time option (see below). * * Available options: * * * format_date: The format string in js and php for date. (see http://docs.jquery.com/UI/Datepicker/formatDate) (see http://www.php.net/date) * * date: Options for the date widget (see sfWidgetFormDate) * * hours: Options for the hours widget (see sfWidgetFormChoice) * * minutes: Options for the minutes widget (see sfWidgetFormChoice) * * period: Options for the period widget (see sfWidgetFormChoice) * * format: The format string for the datetime widget (default to %date% %hours% %minutes% %period%) * * @param array $options An array of options * @param array $attributes An array of default HTML attributes * @see sfWidgetForm */ protected function configure($options = array(), $attributes = array()) { $this->addOption('format_date', array('js' => 'ISO_8601', 'php' => 'Y-m-d H:i:s')); $this->addOption('date', array()); $this->addOption('hours', array('choices' => parent::generateTwoCharsRange(1, 12))); $this->addOption('minutes', array('choices' => parent::generateTwoCharsRange(0, 59))); $this->addOption('period', array('choices' => array('AM' => 'AM', 'noon' => 'Noon', 'PM' => 'PM', 'midnight' => 'Midnight'))); $this->addOption('format', '%date% %hours% %minutes% %period%'); }
/** * Configures the current widget. * * Available options: * * * format: The date format string (%month%/%day%/%year% by default) * * years: An array of years for the year select tag (optional) * * months: An array of months for the month select tag (optional) * * days: An array of days for the day select tag (optional) * * can_be_empty: Whether the widget accept an empty value (true by default) * * empty_values: An array of values to use for the empty value (empty string for year, month, and date by default) * * @param array $options An array of options * @param array $attributes An array of default HTML attributes * * @see sfWidgetForm */ protected function configure($options = array(), $attributes = array()) { $this->addOption('format', '%month%/%day%/%year%'); $this->addOption('days', parent::generateTwoCharsRange(1, 31)); $this->addOption('months', parent::generateTwoCharsRange(1, 12)); $years = range(date('Y') - 5, date('Y') + 5); $this->addOption('years', array_combine($years, $years)); $this->addOption('can_be_empty', true); $this->addOption('empty_values', array('year' => '', 'month' => '', 'day' => '')); }
/** * Constructor. * * Available options: * * * format: The time format string (%hour%:%minute%:%second%) * * format_without_seconds: The time format string without seconds (%hour%:%minute%) * * with_seconds: Whether to include a select for seconds (false by default) * * hours: An array of hours for the hour select tag (optional) * * minutes: An array of minutes for the minute select tag (optional) * * seconds: An array of seconds for the second select tag (optional) * * can_be_empty: Whether the widget accept an empty value (true by default) * * empty_values: An array of values to use for the empty value (empty string for hours, minutes, and seconds by default) * * @param array $options An array of options * @param array $attributes An array of default HTML attributes * * @see sfWidgetForm */ protected function configure($options = array(), $attributes = array()) { $this->addOption('format', '%hour%:%minute%:%second%'); $this->addOption('format_without_seconds', '%hour%:%minute%'); $this->addOption('with_seconds', false); $this->addOption('hours', parent::generateTwoCharsRange(0, 23)); $this->addOption('minutes', parent::generateTwoCharsRange(0, 59)); $this->addOption('seconds', parent::generateTwoCharsRange(0, 59)); $this->addOption('can_be_empty', true); $this->addOption('empty_values', array('hour' => '', 'minute' => '', 'second' => '')); }
/** * Constructor. * * Available options: * * * format: The time format string (%hour%:%minute%:%second%) * * format_without_seconds: The time format string without seconds (%hour%:%minute%) * * with_seconds: Whether to include a select for seconds (false by default) * * hours: An array of hours for the hour select tag (optional) * * minutes: An array of minutes for the minute select tag (optional) * * seconds: An array of seconds for the second select tag (optional) * * can_be_empty: Whether the widget accept an empty value (true by default) * * empty_values: An array of values to use for the empty value (empty string for hours, minutes, and seconds by default) * * @param array $options An array of options * @param array $attributes An array of default HTML attributes * * @see sfWidgetForm */ protected function configure($options = array(), $attributes = array()) { $with_meridiem = isset($options['with_meridiem']) && $options['with_meridiem']; $this->addOption('format', '%hour%:%minute%:%second%' . ($with_meridiem ? ' %meridiem%' : '')); $this->addOption('format_without_seconds', '%hour%:%minute%' . ($with_meridiem ? ' %meridiem%' : '')); $this->addOption('with_seconds', false); $this->addOption('with_meridiem', false); $this->addOption('hours', $with_meridiem ? parent::generateTwoCharsRange(1, 12) : parent::generateTwoCharsRange(0, 23)); $this->addOption('minutes', parent::generateTwoCharsRange(0, 59)); $this->addOption('seconds', parent::generateTwoCharsRange(0, 59)); $this->addOption('meridiem', array('am' => 'AM', 'pm' => 'PM')); $this->addOption('can_be_empty', true); $this->addOption('empty_values', array('hour' => '', 'minute' => '', 'second' => '', 'meridiem' => '')); }
protected function configure($options = array(), $attributes = array()) { $this->addOption('days', parent::generateTwoCharsRange(1, 31)); $this->addOption('months', parent::generateTwoCharsRange(1, 12)); $years = range(date('Y') - 5, date('Y') + 5); $this->addOption('years', array_combine($years, $years)); $this->addOption('can_be_empty', true); $this->addOption('empty_value', ''); $this->addRequiredOption('culture'); $this->addOption('use', 'months'); $this->addOption('format'); $culture = isset($options['culture']) ? $options['culture'] : 'en'; $format = isset($options['format']) ? $options['format'] : 'name'; $this->setOption('months', $this->getMonthFormat($culture, $format)); $this->setOption('days', $this->getDayFormat($culture, $format)); }
/** * @param string $name The element name * @param string $value The time displayed in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $use_period = $this->getOption('period') == true; if (!$use_period) { $this->setOption('hours', parent::generateTwoCharsRange(0, 23)); } // convert value to an array $default = array('hour' => null, 'minute' => null, 'second' => null, 'period' => null); if (is_array($value)) { $value = array_merge($default, $value); } else { $value = ctype_digit($value) ? (int) $value : strtotime($value); if (false === $value) { $value = $default; } else { // int cast required to get rid of leading zeros $value = array('hour' => (int) date('H', $value), 'minute' => (int) date('i', $value), 'second' => (int) date('s', $value), 'period' => date('A', $value)); } } $time = array(); $emptyValues = $this->getOption('empty_values'); // hours $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['hour']) + $this->getOption('hours') : $this->getOption('hours')), array_merge($this->attributes, $attributes)); $time['%hour%'] = $widget->render($name . '[hour]', $value['hour']); // minutes $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['minute']) + $this->getOption('minutes') : $this->getOption('minutes')), array_merge($this->attributes, $attributes)); $time['%minute%'] = $widget->render($name . '[minute]', $value['minute']); if ($this->getOption('with_seconds')) { // seconds $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['second']) + $this->getOption('seconds') : $this->getOption('seconds')), array_merge($this->attributes, $attributes)); $time['%second%'] = $widget->render($name . '[second]', $value['second']); } if ($use_period) { // period (AM/PM) $widget = new sfWidgetFormSelect(array('choices' => array('AM' => 'AM', 'PM' => 'PM')), array_merge($this->attributes, $attributes)); $time['%period%'] = $widget->render($name . '[period]', $value['period']); } else { $time['%period%'] = ''; } return strtr($this->getOption('with_seconds') ? $this->getOption('format') : $this->getOption('format_without_seconds'), $time); }