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_Eav_Model_Attribute_Data_Date extends Mage_Eav_Model_Attribute_Data_Abstract
36: {
37: 38: 39: 40: 41: 42:
43: public function (Zend_Controller_Request_Http $request)
44: {
45: $value = $this->_getRequestValue($request);
46: return $this->_applyInputFilter($value);
47: }
48:
49: 50: 51: 52: 53: 54: 55:
56: public function validateValue($value)
57: {
58: $errors = array();
59: $attribute = $this->getAttribute();
60: $label = $attribute->getStoreLabel();
61:
62: if ($value === false) {
63:
64: $value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode());
65: }
66:
67: if ($attribute->getIsRequired() && empty($value)) {
68: $errors[] = Mage::helper('eav')->__('"%s" is a required value.', $label);
69: }
70:
71: if (!$errors && !$attribute->getIsRequired() && empty($value)) {
72: return true;
73: }
74:
75: $result = $this->_validateInputRule($value);
76: if ($result !== true) {
77: $errors = array_merge($errors, $result);
78: }
79:
80:
81: $validateRules = $attribute->getValidateRules();
82: if ((!empty($validateRules['date_range_min']) && (strtotime($value) < $validateRules['date_range_min']))
83: || (!empty($validateRules['date_range_max']) && (strtotime($value) > $validateRules['date_range_max']))
84: ) {
85: if (!empty($validateRules['date_range_min']) && !empty($validateRules['date_range_max'])) {
86: $errors[] = Mage::helper('customer')->__('Please enter a valid date between %s and %s at %s.', date('d/m/Y', $validateRules['date_range_min']), date('d/m/Y', $validateRules['date_range_max']), $label);
87: } elseif (!empty($validateRules['date_range_min'])) {
88: $errors[] = Mage::helper('customer')->__('Please enter a valid date equal to or greater than %s at %s.', date('d/m/Y', $validateRules['date_range_min']), $label);
89: } elseif (!empty($validateRules['date_range_max'])) {
90: $errors[] = Mage::helper('customer')->__('Please enter a valid date less than or equal to %s at %s.', date('d/m/Y', $validateRules['date_range_max']), $label);
91: }
92: }
93:
94: if (count($errors) == 0) {
95: return true;
96: }
97:
98: return $errors;
99: }
100:
101: 102: 103: 104: 105: 106:
107: public function compactValue($value)
108: {
109: if ($value !== false) {
110: if (empty($value)) {
111: $value = null;
112: }
113: $this->getEntity()->setDataUsingMethod($this->getAttribute()->getAttributeCode(), $value);
114: }
115: return $this;
116: }
117:
118: 119: 120: 121: 122: 123:
124: public function restoreValue($value)
125: {
126: return $this->compactValue($value);
127: }
128:
129: 130: 131: 132: 133: 134:
135: public function outputValue($format = Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_TEXT)
136: {
137: $value = $this->getEntity()->getData($this->getAttribute()->getAttributeCode());
138: if ($value) {
139: switch ($format) {
140: case Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_TEXT:
141: case Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_HTML:
142: case Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_PDF:
143: $this->_dateFilterFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
144: break;
145: }
146: $value = $this->_applyOutputFilter($value);
147: }
148:
149: $this->_dateFilterFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
150:
151: return $value;
152: }
153: }
154: