1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33: 34:
35: class Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Datetime extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Date
36: {
37:
38: const END_OF_DAY_IN_SECONDS = 86399;
39:
40: public function getValue($index=null)
41: {
42: if ($index) {
43: if ($data = $this->getData('value', 'orig_'.$index)) {
44: return $data;
45: }
46: return null;
47: }
48: $value = $this->getData('value');
49: if (is_array($value)) {
50: $value['datetime'] = true;
51: }
52: if (!empty($value['to']) && !$this->getColumn()->getFilterTime()) {
53: $datetimeTo = $value['to'];
54:
55:
56: $datetimeTo->setTimezone(
57: Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE)
58: );
59: $datetimeTo->addDay(1)->subSecond(1);
60: $datetimeTo->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
61: }
62: return $value;
63: }
64:
65: 66: 67: 68: 69: 70: 71:
72: protected function _convertDate($date, $locale)
73: {
74: if ($this->getColumn()->getFilterTime()) {
75: try {
76: $dateObj = $this->getLocale()->date(null, null, $locale, false);
77:
78:
79: $dateObj->setTimezone(Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
80:
81:
82: $dateObj->set(
83: $date,
84: $this->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
85: $locale
86: );
87:
88:
89: $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
90:
91: return $dateObj;
92: }
93: catch (Exception $e) {
94: return null;
95: }
96: }
97:
98: return parent::_convertDate($date, $locale);
99: }
100:
101: 102: 103: 104: 105:
106: public function getHtml()
107: {
108: $htmlId = $this->_getHtmlId() . microtime(true);
109: $format = $this->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
110:
111: if ($this->getColumn()->getFilterTime()) {
112: $format .= ' ' . $this->getLocale()->getTimeStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
113: }
114:
115: $html = '<div class="range"><div class="range-line date">
116: <span class="label">' . Mage::helper('adminhtml')->__('From').':</span>
117: <input type="text" name="'.$this->_getHtmlName().'[from]" id="'.$htmlId.'_from" value="'.$this->getEscapedValue('from').'" class="input-text no-changes"/>
118: <img src="' . Mage::getDesign()->getSkinUrl('images/grid-cal.gif') . '" alt="" class="v-middle" id="'.$htmlId.'_from_trig" title="'.$this->htmlEscape(Mage::helper('adminhtml')->__('Date selector')).'"/>
119: </div>';
120: $html.= '<div class="range-line date">
121: <span class="label">' . Mage::helper('adminhtml')->__('To').' :</span>
122: <input type="text" name="'.$this->_getHtmlName().'[to]" id="'.$htmlId.'_to" value="'.$this->getEscapedValue('to').'" class="input-text no-changes"/>
123: <img src="' . Mage::getDesign()->getSkinUrl('images/grid-cal.gif') . '" alt="" class="v-middle" id="'.$htmlId.'_to_trig" title="'.$this->htmlEscape(Mage::helper('adminhtml')->__('Date selector')).'"/>
124: </div></div>';
125: $html.= '<input type="hidden" name="'.$this->_getHtmlName().'[locale]" value="'.$this->getLocale()->getLocaleCode().'"/>';
126: $html.= '<script type="text/javascript">
127: Calendar.setup({
128: inputField : "'.$htmlId.'_from",
129: ifFormat : "'.$format.'",
130: button : "'.$htmlId.'_from_trig",
131: showsTime: '. ( $this->getColumn()->getFilterTime() ? 'true' : 'false') .',
132: align : "Bl",
133: singleClick : true
134: });
135: Calendar.setup({
136: inputField : "'.$htmlId.'_to",
137: ifFormat : "'.$format.'",
138: button : "'.$htmlId.'_to_trig",
139: showsTime: '. ( $this->getColumn()->getFilterTime() ? 'true' : 'false') .',
140: align : "Bl",
141: singleClick : true
142: });
143: </script>';
144: return $html;
145: }
146:
147: 148: 149: 150: 151: 152:
153: public function getEscapedValue($index=null)
154: {
155: if ($this->getColumn()->getFilterTime()) {
156: $value = $this->getValue($index);
157: if ($value instanceof Zend_Date) {
158: return $value->toString($this->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
159: }
160: return $value;
161: }
162:
163: return parent::getEscapedValue($index);
164: }
165:
166: }
167: