/usr/share/php/Icinga/Web/Form/Element/DateTimePicker.php is in php-icinga 2.1.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Form\Element;
use DateTime;
use Icinga\Web\Form\FormElement;
use Icinga\Web\Form\Validator\DateTimeValidator;
/**
* A date-and-time input control
*/
class DateTimePicker extends FormElement
{
/**
* Form view helper to use for rendering
*
* @var string
*/
public $helper = 'formDateTime';
/**
* @var bool
*/
protected $local = true;
/**
* The expected lower bound for the element’s value
*
* @var DateTime|null
*/
protected $min;
/**
* The expected upper bound for the element’s
*
* @var DateTime|null
*/
protected $max;
/**
* (non-PHPDoc)
* @see Zend_Form_Element::init() For the method documentation.
*/
public function init()
{
$this->addValidator(
new DateTimeValidator($this->local), true // true for breaking the validator chain on failure
);
if ($this->min !== null) {
$this->addValidator('GreaterThan', true, array('min' => $this->min));
}
if ($this->max !== null) {
$this->addValidator('LessThan', true, array('max' => $this->max));
}
}
public function setLocal($local)
{
$this->local = (bool) $local;
return $this;
}
public function getLocal()
{
return $this->local;
}
/**
* Set the expected lower bound for the element’s value
*
* @param DateTime $min
*
* @return $this
*/
public function setMin(DateTime $min)
{
$this->min = $min;
return $this;
}
/**
* Get the expected lower bound for the element’s value
*
* @return DateTime|null
*/
public function getMin()
{
return $this->min;
}
/**
* Set the expected upper bound for the element’s value
*
* @param DateTime $max
*
* @return $this
*/
public function setMax(DateTime $max)
{
$this->max = $max;
return $this;
}
/**
* Get the expected upper bound for the element’s value
*
* @return DateTime|null
*/
public function getMax()
{
return $this->max;
}
/**
* Is the date and time valid?
*
* @param string|DateTime $value
* @param mixed $context
*
* @return bool
*/
public function isValid($value, $context = null)
{
if (! parent::isValid($value, $context)) {
return false;
}
if (! $value instanceof DateTime) {
$format = $this->local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339;
$dateTime = DateTime::createFromFormat($format, $value);
if ($dateTime === false) {
$dateTime = DateTime::createFromFormat(substr($format, 0, strrpos($format, ':')), $value);
}
$this->setValue($dateTime);
}
return true;
}
}
|