| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfWidgetFormI18nTime extends sfWidgetFormTime |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Constructor. |
|---|
| 23 |
* |
|---|
| 24 |
* Available options: |
|---|
| 25 |
* |
|---|
| 26 |
* * culture: The culture to use for internationalized strings (required) |
|---|
| 27 |
* |
|---|
| 28 |
* @param array $options An array of options |
|---|
| 29 |
* @param array $attributes An array of default HTML attributes |
|---|
| 30 |
* |
|---|
| 31 |
* @see sfWidgetFormTime |
|---|
| 32 |
*/ |
|---|
| 33 |
protected function configure($options = array(), $attributes = array()) |
|---|
| 34 |
{ |
|---|
| 35 |
parent::configure($options, $attributes); |
|---|
| 36 |
|
|---|
| 37 |
$this->addRequiredOption('culture'); |
|---|
| 38 |
|
|---|
| 39 |
$culture = isset($options['culture']) ? $options['culture'] : 'en'; |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
$this->setOption('format', $this->getTimeFormat($culture, true)); |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
$this->setOption('format_without_seconds', $this->getTimeFormat($culture, false)); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
protected function getTimeFormat($culture, $withSeconds) |
|---|
| 49 |
{ |
|---|
| 50 |
$timeFormat = $withSeconds ? sfDateTimeFormatInfo::getInstance($culture)->getMediumTimePattern() : sfDateTimeFormatInfo::getInstance($culture)->getShortTimePattern(); |
|---|
| 51 |
|
|---|
| 52 |
if (false === ($hourPos = stripos($timeFormat, 'h')) || false === ($minutePos = stripos($timeFormat, 'm'))) |
|---|
| 53 |
{ |
|---|
| 54 |
return $this->getOption('format'); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
$trans = array( |
|---|
| 58 |
substr($timeFormat, $hourPos, strripos($timeFormat, 'h') - $hourPos + 1) => '%hour%', |
|---|
| 59 |
substr($timeFormat, $minutePos, strripos($timeFormat, 'm') - $minutePos + 1) => '%minute%', |
|---|
| 60 |
); |
|---|
| 61 |
|
|---|
| 62 |
if ($withSeconds) |
|---|
| 63 |
{ |
|---|
| 64 |
if (false === $secondPos = stripos($timeFormat, 's')) |
|---|
| 65 |
{ |
|---|
| 66 |
return $this->getOption('format'); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
$trans[substr($timeFormat, $secondPos, strripos($timeFormat, 's') - $secondPos + 1)] = '%second%'; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
return strtr($timeFormat, $trans); |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|