1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class DateRangeField Custom DateRangeField which can be used |
5
|
|
|
* |
6
|
|
|
* @package dms |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
class DateRangeField extends FieldGroup |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
public $minDate, $maxDate; |
|
|
|
|
13
|
|
|
protected $template = "DateRangeField"; |
14
|
|
|
|
15
|
|
|
public function __construct($name, $minTitle = '', $maxTitle = '', $min = null, $max = null, $minPlaceHolder = null, $maxPlaceHolder = null) |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
$minDate = new DateField($name.'[min]', $minTitle, $min); |
19
|
|
|
$maxDate = new DateField($name.'[max]', $maxTitle, $max); |
20
|
|
|
|
21
|
|
|
$minDate->setConfig("showcalendar", true); |
22
|
|
|
$minDate->setConfig("dateformat", 'yyyy-MM-dd'); |
23
|
|
|
if ($minPlaceHolder) { |
24
|
|
|
$minDate->setAttribute('placeholder', $minPlaceHolder); |
25
|
|
|
} else { |
26
|
|
|
$minDate->setAttribute('placeholder', "yyyy-mm-dd"); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$maxDate->setconfig("showcalendar", true); |
30
|
|
|
$maxDate->setConfig("dateformat", 'yyyy-MM-dd'); |
31
|
|
|
if ($maxPlaceHolder) { |
32
|
|
|
$maxDate->setAttribute('placeholder', $maxPlaceHolder); |
33
|
|
|
} else { |
34
|
|
|
$maxDate->setAttribute('placeholder', "yyyy-mm-dd"); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$this->minDate = $minDate; |
38
|
|
|
$this->maxDate = $maxDate; |
39
|
|
|
$this->setName($name); |
40
|
|
|
Requirements::css(DMS_DIR . '/css/DateRangeField.css'); |
41
|
|
|
parent::__construct($name, new FieldList($this->minDate, $this->maxDate)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function FieldMin() |
45
|
|
|
{ |
46
|
|
|
return $this->minDate; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function FieldMax() |
50
|
|
|
{ |
51
|
|
|
return $this->maxDate; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function setName($name) |
55
|
|
|
{ |
56
|
|
|
$this->minDate->setName($name.'[min]'); |
57
|
|
|
$this->maxDate->setName($name.'[max]'); |
58
|
|
|
parent::setName($name); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function isComposite() |
62
|
|
|
{ |
63
|
|
|
return true; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function setValue($value) |
67
|
|
|
{ |
68
|
|
|
if (isset($value['min'])) { |
69
|
|
|
$this->minDate->setValue($value['min']); |
70
|
|
|
} |
71
|
|
|
if (isset($value['max'])) { |
72
|
|
|
$this->maxDate->setValue($value['max']); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function Field($properties = array()) |
77
|
|
|
{ |
78
|
|
|
Requirements::css(DMS_DIR . '/css/DateRangeField.css'); |
79
|
|
|
return parent::Field($properties); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.