2013-07-16 15:39:47 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
/**
|
2014-09-03 14:40:58 +02:00
|
|
|
* Render date-and-time input controls
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
2013-08-06 19:05:16 +02:00
|
|
|
class Zend_View_Helper_FormDateTime extends Zend_View_Helper_FormElement
|
2013-07-16 15:39:47 +02:00
|
|
|
{
|
|
|
|
/**
|
2014-09-03 14:40:58 +02:00
|
|
|
* Format date and time
|
|
|
|
*
|
|
|
|
* @param DateTime $dateTime
|
|
|
|
* @param bool $local
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function formatDate(DateTime $dateTime, $local)
|
|
|
|
{
|
|
|
|
$format = (bool) $local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339;
|
|
|
|
return $dateTime->format($format);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the date-and-time input control
|
2013-07-16 15:39:47 +02:00
|
|
|
*
|
2013-08-07 10:53:44 +02:00
|
|
|
* @param string $name The element name
|
2014-09-03 14:40:58 +02:00
|
|
|
* @param DateTime $value The default timestamp
|
2013-08-07 10:53:44 +02:00
|
|
|
* @param array $attribs Attributes for the element tag
|
2013-07-16 15:39:47 +02:00
|
|
|
*
|
2013-08-06 19:05:16 +02:00
|
|
|
* @return string The element XHTML
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
|
|
|
public function formDateTime($name, $value = null, $attribs = null)
|
|
|
|
{
|
2013-08-06 19:05:16 +02:00
|
|
|
$info = $this->_getInfo($name, $value, $attribs);
|
2014-09-03 14:40:58 +02:00
|
|
|
extract($info); // name, id, value, attribs, options, listsep, disable
|
|
|
|
/** @var string $id */
|
|
|
|
/** @var bool $disable */
|
2013-08-06 19:05:16 +02:00
|
|
|
$disabled = '';
|
2014-09-03 14:40:58 +02:00
|
|
|
if ($disable) {
|
2013-08-06 19:05:16 +02:00
|
|
|
$disabled = ' disabled="disabled"';
|
|
|
|
}
|
2014-09-03 14:40:58 +02:00
|
|
|
if ($value instanceof DateTime) {
|
|
|
|
// If value was valid, it's a DateTime object
|
|
|
|
$value = $this->formatDate($value, $attribs['local']);
|
2013-08-06 19:05:16 +02:00
|
|
|
}
|
2014-09-03 14:40:58 +02:00
|
|
|
$min = '';
|
|
|
|
if (! empty($attribs['min'])) {
|
|
|
|
$min = sprintf(' min="%s"', $this->formatDate($attribs['min'], $attribs['local']));
|
2013-10-20 15:30:49 +02:00
|
|
|
}
|
2014-09-03 14:40:58 +02:00
|
|
|
unset($attribs['min']); // Unset min to not render it again in $this->_htmlAttribs($attribs)
|
|
|
|
$max = '';
|
|
|
|
if (! empty($attribs['max'])) {
|
|
|
|
$max = sprintf(' max="%s"', $this->formatDate($attribs['max'], $attribs['local']));
|
2013-10-21 11:32:24 +02:00
|
|
|
}
|
2014-09-03 14:40:58 +02:00
|
|
|
unset($attribs['max']); // Unset max to not render it again in $this->_htmlAttribs($attribs)
|
|
|
|
$type = $attribs['local'] === true ? 'datetime-local' : 'datetime';
|
|
|
|
unset($attribs['local']); // Unset local to not render it again in $this->_htmlAttribs($attribs)
|
|
|
|
$html5 = sprintf(
|
|
|
|
'<input type="%s" name="%s" id="%s" value="%s"%s%s%s%s%s',
|
|
|
|
$type,
|
|
|
|
$this->view->escape($name),
|
|
|
|
$this->view->escape($id),
|
|
|
|
$this->view->escape($value),
|
|
|
|
$min,
|
|
|
|
$max,
|
|
|
|
$disabled,
|
|
|
|
$this->_htmlAttribs($attribs),
|
|
|
|
$this->getClosingBracket()
|
|
|
|
);
|
|
|
|
return $html5;
|
2013-07-16 15:39:47 +02:00
|
|
|
}
|
|
|
|
}
|