| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* sfWidgetFormI18nTime represents a time widget.
|
|
|
13 |
*
|
|
|
14 |
* @package symfony
|
|
|
15 |
* @subpackage widget
|
|
|
16 |
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
17 |
* @version SVN: $Id: sfWidgetFormI18nTime.class.php 9046 2008-05-19 08:13:51Z FabianLange $
|
|
|
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 |
// format
|
|
|
42 |
$this->setOption('format', $this->getTimeFormat($culture, true));
|
|
|
43 |
|
|
|
44 |
// format_without_seconds
|
|
|
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 |
}
|