| @@ 5-53 (lines=49) @@ | ||
| 2 | ||
| 3 | namespace Sco\Admin\Form\Elements; |
|
| 4 | ||
| 5 | class DateRange extends Date |
|
| 6 | { |
|
| 7 | protected $type = 'daterange'; |
|
| 8 | ||
| 9 | protected $startName; |
|
| 10 | ||
| 11 | protected $endName; |
|
| 12 | ||
| 13 | public function __construct($startName, $endName, $title) |
|
| 14 | { |
|
| 15 | $this->startName = $startName; |
|
| 16 | $this->endName = $endName; |
|
| 17 | ||
| 18 | parent::__construct('', $title); |
|
| 19 | } |
|
| 20 | ||
| 21 | public function getName() |
|
| 22 | { |
|
| 23 | return ''; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function getStartName() |
|
| 27 | { |
|
| 28 | return $this->startName; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function getEndName() |
|
| 32 | { |
|
| 33 | return $this->endName; |
|
| 34 | } |
|
| 35 | ||
| 36 | public function getDefaultValue() |
|
| 37 | { |
|
| 38 | return []; |
|
| 39 | } |
|
| 40 | ||
| 41 | public function getValue() |
|
| 42 | { |
|
| 43 | $model = $this->getModel(); |
|
| 44 | $value = $this->getDefaultValue(); |
|
| 45 | if (is_null($model) || !$model->exists) { |
|
| 46 | return $value; |
|
| 47 | } |
|
| 48 | return [ |
|
| 49 | $model->getAttribute($this->getStartName()), |
|
| 50 | $model->getAttribute($this->getEndName()), |
|
| 51 | ]; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 5-48 (lines=44) @@ | ||
| 2 | ||
| 3 | namespace Sco\Admin\Form\Elements; |
|
| 4 | ||
| 5 | class DateTimeRange extends Date |
|
| 6 | { |
|
| 7 | protected $type = 'datetimerange'; |
|
| 8 | ||
| 9 | protected $startName; |
|
| 10 | ||
| 11 | protected $endName; |
|
| 12 | ||
| 13 | public function __construct($startName, $endName, $title) |
|
| 14 | { |
|
| 15 | $this->startName = $startName; |
|
| 16 | $this->endName = $endName; |
|
| 17 | ||
| 18 | parent::__construct('', $title); |
|
| 19 | } |
|
| 20 | ||
| 21 | public function getStartName() |
|
| 22 | { |
|
| 23 | return $this->startName; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function getEndName() |
|
| 27 | { |
|
| 28 | return $this->endName; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function getDefaultValue() |
|
| 32 | { |
|
| 33 | return []; |
|
| 34 | } |
|
| 35 | ||
| 36 | public function getValue() |
|
| 37 | { |
|
| 38 | $model = $this->getModel(); |
|
| 39 | $value = $this->getDefaultValue(); |
|
| 40 | if (is_null($model) || !$model->exists) { |
|
| 41 | return $value; |
|
| 42 | } |
|
| 43 | return [ |
|
| 44 | $model->getAttribute($this->getStartName()), |
|
| 45 | $model->getAttribute($this->getEndName()), |
|
| 46 | ]; |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||