Source of file DateRangeField.php
Size: 1,370 Bytes - Last Modified: 2021-12-24T06:43:43+00:00
/var/www/docs.ssmods.com/process/src/code/DateRangeField.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | <?php namespace DeptInternalAffairsNZ\SilverStripe; use SilverStripe\Forms\CompositeField; use SilverStripe\Forms\DateField; class DateRangeField extends CompositeField { /* @var $from DateField */ protected $from; /* @var $to DateField */ protected $to; public function __construct($name, $title = null, $value = null) { $this->name = $name; $this->setTitle($title); $this->from = new DateField($this->name . '[From]', $title, null); $this->to = new DateField($this->name . '[To]', $title, null); parent::__construct(array( $this->from, $this->to )); $this->setConfig('showcalendar', true); $this->setConfig('dateformat', 'yyyy-MM-dd'); $this->setValue($value); } public function setConfig($key, $value) { $this->from->set_stat($key, $value); $this->to->set_stat($key, $value); } public function hasData() { return true; } public function getValue() { return $this->value; } /** * Set the field name */ public function setName($name) { $this->name = $name; $this->from->setName($name . '[From]'); $this->to->setName($name . '[To]'); return $this; } public function setTitle($title) { parent::setTitle($title); if ($this->from instanceof DateField) { $this->from->setTitle('From ' . $title); } if ($this->to instanceof DateField) { $this->to->setTitle('To ' . $title); } } } |