2016-08-19 00:51:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\ORM\FieldType\DBDate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disabled version of {@link DateField}.
|
|
|
|
* Allows dates to be represented in a form, by showing in a user friendly format, eg, dd/mm/yyyy.
|
|
|
|
*/
|
|
|
|
class DateField_Disabled extends DateField
|
|
|
|
{
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
protected $disabled = true;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2018-06-01 06:05:17 +02:00
|
|
|
public function Field($properties = [])
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2018-06-01 06:05:17 +02:00
|
|
|
// Default display value
|
|
|
|
$displayValue = '<i>(' . _t(DateField::class . '.NOTSET', 'not set') . ')</i>';
|
|
|
|
|
|
|
|
$value = $this->dataValue();
|
|
|
|
|
|
|
|
if ($value) {
|
|
|
|
$value = $this->tidyInternal($value);
|
|
|
|
$df = new DBDate($this->name);
|
|
|
|
$df->setValue($value);
|
|
|
|
|
|
|
|
if ($df->IsToday()) {
|
|
|
|
// e.g. 2018-06-01 (today)
|
|
|
|
$format = '%s (%s)';
|
|
|
|
$infoComplement = _t(DateField::class . '.TODAY', 'today');
|
2016-11-29 00:31:16 +01:00
|
|
|
} else {
|
2018-06-01 06:05:17 +02:00
|
|
|
// e.g. 2018-06-01, 5 days ago
|
|
|
|
$format = '%s, %s';
|
|
|
|
$infoComplement = $df->Ago();
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2018-06-01 06:05:17 +02:00
|
|
|
|
|
|
|
// Render the display value with some complement of info
|
|
|
|
$displayValue = Convert::raw2xml(sprintf(
|
|
|
|
$format,
|
|
|
|
$this->Value(),
|
|
|
|
$infoComplement
|
|
|
|
));
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2018-06-01 06:05:17 +02:00
|
|
|
return sprintf(
|
|
|
|
"<span class=\"readonly\" id=\"%s\">%s</span>",
|
|
|
|
$this->ID(),
|
|
|
|
$displayValue
|
|
|
|
);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
public function Type()
|
|
|
|
{
|
2018-06-01 06:05:17 +02:00
|
|
|
return "date_disabled readonly " . parent::Type();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHTML5()
|
|
|
|
{
|
|
|
|
// Always disable HTML5 feature when using the readonly field.
|
|
|
|
return false;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2016-08-19 00:51:35 +02:00
|
|
|
}
|