1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Grido\Components\Filters;
13
14 15 16 17 18 19 20 21 22 23
24 class Date extends Text
25 {
26
27 protected $formatValue;
28
29
30 protected $dateFormatInput = 'd.m.Y';
31
32
33 protected $dateFormatOutput = 'Y-m-d%';
34
35 36 37 38 39
40 public function setDateFormatInput($format)
41 {
42 $this->dateFormatInput = $format;
43 return $this;
44 }
45
46 47 48 49
50 public function getDateFormatInput()
51 {
52 return $this->dateFormatInput;
53 }
54
55 56 57 58 59
60 public function setDateFormatOutput($format)
61 {
62 $this->dateFormatOutput = $format;
63 return $this;
64 }
65
66 67 68 69
70 public function getDateFormatOutput()
71 {
72 return $this->dateFormatOutput;
73 }
74
75 76 77
78 protected function getFormControl()
79 {
80 $control = parent::getFormControl();
81 $control->getControlPrototype()->class[] = 'date';
82 $control->getControlPrototype()->attrs['autocomplete'] = 'off';
83
84 return $control;
85 }
86
87 88 89 90 91 92
93 public function __getCondition($value)
94 {
95 $condition = $this->condition;
96 if ($this->where === NULL && is_string($condition)) {
97 $column = $this->getColumn();
98 return ($date = \DateTime::createFromFormat($this->dateFormatInput, $value))
99 ? Condition::setupFromArray(array($column, $condition, $date->format($this->dateFormatOutput)))
100 : Condition::setupEmpty();
101 }
102
103 return parent::__getCondition($value);
104 }
105 }
106