1: | <?php |
2: | |
3: | namespace Zippy\Html\Form; |
4: | |
5: | use Zippy\WebApplication; |
6: | use Zippy\Event; |
7: | use Zippy\Interfaces\ChangeListener; |
8: | use Zippy\Interfaces\EventReceiver; |
9: | use Zippy\Interfaces\Requestable; |
10: | |
11: | |
12: | |
13: | |
14: | class Date extends TextInput implements Requestable, ChangeListener |
15: | { |
16: | private $event; |
17: | private $min=0; |
18: | private $max=0; |
19: | |
20: | public function __construct($id, $value = null, $bgupdate = false) { |
21: | parent::__construct($id); |
22: | $this->setDate($value); |
23: | $this->bgupdate = $bgupdate; |
24: | } |
25: | |
26: | protected function onAdded() { |
27: | if ($this->bgupdate) { |
28: | $page = $this->getPageOwner(); |
29: | $this->onChange($page, 'OnBackgroundUpdate', true); |
30: | } |
31: | } |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | public function setMinMax($min, $max) { |
40: | if($min > $max) { |
41: | return; |
42: | } |
43: | $this->min = $min; |
44: | $this->max = $max; |
45: | } |
46: | |
47: | public function RenderImpl() { |
48: | TextInput::RenderImpl(); |
49: | |
50: | |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | $this->setAttribute('type', 'date') ; |
85: | if($this->min >0) { |
86: | $this->setAttribute('min', date('Y-m-d', $this->min)) ; |
87: | } |
88: | if($this->max >0) { |
89: | $this->setAttribute('max', date('Y-m-d', $this->max)) ; |
90: | } |
91: | |
92: | } |
93: | |
94: | |
95: | |
96: | |
97: | |
98: | public function getDate($endday = false) { |
99: | $date = strtotime($this->getText()); |
100: | if ($endday == true) { |
101: | $d = date('Y-m-d', $date); |
102: | $date = strtotime($d . ' 23:59:59'); |
103: | } |
104: | return $date; |
105: | } |
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: | |
113: | public function setDate($t = 0) { |
114: | if ($t > 0) { |
115: | $this->setText(date('Y-m-d', $t)); |
116: | } else { |
117: | $this->setText(""); |
118: | } |
119: | } |
120: | |
121: | |
122: | |
123: | |
124: | public function onChange(EventReceiver $receiver, $handler, $ajax = true) { |
125: | |
126: | $this->event = new Event($receiver, $handler); |
127: | $this->event->isajax = $ajax; |
128: | } |
129: | |
130: | |
131: | |
132: | |
133: | public function OnEvent() { |
134: | if ($this->event != null) { |
135: | $this->event->onEvent($this); |
136: | } |
137: | } |
138: | |
139: | |
140: | |
141: | |
142: | public function RequestHandle() { |
143: | $this->OnEvent(); |
144: | } |
145: | |
146: | } |
147: | |