29 protected $minDate = NULL;
30 protected $maxDate = NULL;
44 function __construct (
string $label,
string $description,
string $ldapName,
bool $required,
string $format, $defaultValue =
'today', $min = NULL, $max = NULL,
string $acl =
'')
46 parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
47 $this->format = $format;
50 $this->minDate =
new DateTime($min,
new DateTimeZone(
'UTC'));
57 $this->maxDate =
new DateTime($max,
new DateTimeZone(
'UTC'));
64 function inputValue ($value)
68 ($this->isTemplate() && preg_match(
'/%/', $value))
72 return $this->ldapToDate($value);
78 if ($this->value ===
'') {
82 return $this->getDateValue()->format(
'Y-m-d');
89 protected function ldapToDate ($ldapValue)
91 $date = DateTime::createFromFormat(
'!'.$this->format, $ldapValue,
new DateTimeZone(
'UTC'));
92 if ($date !== FALSE) {
99 protected function dateToLdap (DateTime $dateValue)
101 return $dateValue->format($this->format);
104 function getDateValue ()
106 $value = $this->value;
107 if (!($value instanceof DateTime)) {
109 $value =
new DateTime($value,
new DateTimeZone(
'UTC'));
122 function computeLdapValue ()
124 if ($this->value ===
'') {
126 } elseif (!($this->value instanceof DateTime)) {
128 $this->setValue($this->getDateValue());
133 return $this->dateToLdap($this->value);
138 $error = parent::check();
139 if (!empty($error)) {
142 if (empty($this->value)) {
146 $dateValue = $this->getDateValue();
147 if (($this->minDate !== NULL) && ($dateValue < $this->minDate)) {
153 if (($this->maxDate !== NULL) && ($dateValue > $this->maxDate)) {
160 if ($this->isTemplate() && preg_match(
'/%/', $this->value)) {
175 function renderFormInput ():
string 178 'value' => $this->getValue(),
179 'pattern' =>
'[0-9]{4}-[0-9]{2}-[0-9]{2}',
181 if ($this->minDate !== NULL) {
182 $attributes[
'min'] = $this->minDate->format(
'Y-m-d');
184 if ($this->maxDate !== NULL) {
185 $attributes[
'max'] = $this->maxDate->format(
'Y-m-d');
187 $display = $this->renderInputField(
'date', $this->getHtmlId(), $attributes);
191 function renderTemplateInput ():
string 193 $id = $this->getHtmlId();
195 'value' => $this->getValue()
197 if ($this->isSubAttribute) {
198 $attributes[
'class'] =
'subattribute';
200 $display = $this->renderInputField(
'text', $id, $attributes);
210 function __construct (
string $label,
string $description,
string $ldapName,
bool $required, $defaultValue =
'today', $min = NULL, $max = NULL,
string $acl =
'')
212 parent::__construct($label, $description, $ldapName, $required,
'', $defaultValue, $min, $max, $acl);
215 protected function ldapToDate ($ldapValue)
224 protected function dateToLdap (DateTime $dateValue)
237 function __construct ($label, $description, $ldapName, $required, $convert = TRUE, $acl =
'')
239 $this->convert = $convert;
243 $ldapName.
'_hours', TRUE,
248 $ldapName.
'_minutes', TRUE,
253 $ldapName.
'_seconds', TRUE,
257 parent::__construct($description, $ldapName, $attributes,
'/^(\d\d)(\d\d)(\d\d)$/',
'%02d%02d%02d', $acl, $label);
258 $this->setLinearRendering(TRUE);
261 function readValues (
string $value): array
263 $values = parent::readValues($value);
264 if ($this->convert) {
265 $datetime =
new DateTime(
'T'.implode(
':', $values), timezone::utc());
267 $datetime->setTimeZone(timezone::getDefaultTimeZone());
268 if (count($values) < 3) {
269 $values = explode(
':', $datetime->format(
'H:i'));
271 $values = explode(
':', $datetime->format(
'H:i:s'));
277 function writeValues (array $values)
279 if ($this->convert) {
280 $datetime =
new DateTime(
'T'.implode(
':', $values), timezone::getDefaultTimeZone());
281 $datetime->setTimeZone(timezone::utc());
282 if (count($values) < 3) {
283 $values = explode(
':', $datetime->format(
'H:i'));
285 $values = explode(
':', $datetime->format(
'H:i:s'));
288 return parent::writeValues($values);
291 function displayValue ($value):
string 293 $values = parent::readValues($value);
294 $datetime =
new DateTime(
'T'.implode(
':', $values), timezone::utc());
295 if ($this->convert) {
296 $datetime->setTimeZone(timezone::getDefaultTimeZone());
298 if (count($values) < 3) {
299 return $datetime->format(
'H:i');
301 return $datetime->format(
'H:i:s');
311 function __construct ($label, $description, $ldapName, $required, $convert = TRUE, $acl =
'')
313 $this->convert = $convert;
317 $ldapName.
'_hours', TRUE,
322 $ldapName.
'_minutes', TRUE,
327 $this->setLinearRendering(TRUE);
336 function __construct ($label, $description, $ldapName, $required, $acl =
'')
341 $ldapName.
'_date', $required,
347 $ldapName.
'_time', $required,
351 parent::__construct($description, $ldapName, $attributes,
'/^(\d{8})(\d{6})$/',
'%s%s', $acl, $label);
360 protected $displayFormat;
362 function __construct (
string $label,
string $description,
string $ldapName,
bool $required, $defaultValue =
'', $format =
'Y-m-d, H:i:s', $min = NULL, $max = NULL,
string $acl =
'')
364 parent::__construct($label, $description, $ldapName, $required, $defaultValue, $min, $max, $acl);
365 $this->displayFormat = $format;
370 return $this->computeLdapValue();
373 function renderFormInput ():
string 375 if (empty($this->value)) {
378 $date = $this->getDateValue();
379 $date->setTimezone(timezone::getDefaultTimeZone());
380 return htmlescape($date->format($this->displayFormat));
390 public static $secondsPerDay = 86400;
392 function __construct (
string $label,
string $description,
string $ldapName,
bool $required, $defaultValue =
'today', $min = NULL, $max = NULL,
string $acl =
'')
394 parent::__construct($label, $description, $ldapName, $required,
'', $defaultValue, $min, $max, $acl);
397 protected function ldapToDate ($ldapValue)
399 $date = DateTime::createFromFormat(
'U', (
string)($ldapValue * static::$secondsPerDay), timezone::utc());
400 if ($date !== FALSE) {
403 trigger_error(
'LDAP value for '.$this->getLdapName().
' was not in the right date format.');
404 return new DateTime($ldapValue, timezone::utc());
408 protected function dateToLdap (DateTime $dateValue)
410 return floor($dateValue->format(
'U') / static::$secondsPerDay);
413 function getEpochDays ()
415 if (empty($this->value)) {
419 return $this->dateToLdap($this->getDateValue());
421 if (is_object($this->plugin) && $this->plugin->is_template) {
Date attribute storing standard LDAP GeneralizedTime format.
Attribute storing time as Hi format.
htmlescape(string $str)
Escape string for HTML output.
Read-only GeneralizedTimeDateAttribute. Used by audit plugin.
__construct(string $label, string $description, string $ldapName, bool $required, string $format, $defaultValue='today', $min=NULL, $max=NULL, string $acl='')
The constructor of DateAttribute.
static toString(DateTime $date, $setToUTC=TRUE)
Convert from DateTime object to LDAP GeneralizedTime formatted string.
This class allow to handle easily a composite attribute.
__construct(string $description, string $ldapName, array $attributes, $readFormat, $writeFormat, string $acl='', string $label=NULL)
The constructor of CompositeAttribute.
static invalidValue(string $error)
Format error message for invalid value.
Error returned by check method of SimplePlugin.
Attribute storing time as His format.
renderAcl(string $display)
Add ACL information around display.
static fromString($string, $useException=TRUE)
Convert from LDAP GeneralizedTime formatted string to DateTime object.
This class allow to handle easily an Integer LDAP attribute.
Attribute storing both Date and Time.
This class allow to handle easily an Date LDAP attribute.
This class allow to handle easily any kind of LDAP attribute.
Date stored as days since Unix epoch. Used by posix plugin.