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: class Mage_Customer_Block_Widget_Dob extends Mage_Customer_Block_Widget_Abstract
28: {
29: 30: 31: 32: 33:
34: protected $_dateInputs = array();
35:
36: public function _construct()
37: {
38: parent::_construct();
39:
40:
41: $this->setTemplate('customer/widget/dob.phtml');
42: }
43:
44: public function isEnabled()
45: {
46: return (bool)$this->_getAttribute('dob')->getIsVisible();
47: }
48:
49: public function isRequired()
50: {
51: return (bool)$this->_getAttribute('dob')->getIsRequired();
52: }
53:
54: public function setDate($date)
55: {
56: $this->setTime($date ? strtotime($date) : false);
57: $this->setData('date', $date);
58: return $this;
59: }
60:
61: public function getDay()
62: {
63: return $this->getTime() ? date('d', $this->getTime()) : '';
64: }
65:
66: public function getMonth()
67: {
68: return $this->getTime() ? date('m', $this->getTime()) : '';
69: }
70:
71: public function getYear()
72: {
73: return $this->getTime() ? date('Y', $this->getTime()) : '';
74: }
75:
76: 77: 78: 79: 80:
81: public function getDateFormat()
82: {
83: return Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
84: }
85:
86: 87: 88: 89: 90: 91:
92: public function setDateInput($code, $html)
93: {
94: $this->_dateInputs[$code] = $html;
95: }
96:
97: 98: 99: 100: 101:
102: public function getSortedDateInputs()
103: {
104: $strtr = array(
105: '%b' => '%1$s',
106: '%B' => '%1$s',
107: '%m' => '%1$s',
108: '%d' => '%2$s',
109: '%e' => '%2$s',
110: '%Y' => '%3$s',
111: '%y' => '%3$s'
112: );
113:
114: $dateFormat = preg_replace('/[^\%\w]/', '\\1', $this->getDateFormat());
115:
116: return sprintf(strtr($dateFormat, $strtr),
117: $this->_dateInputs['m'], $this->_dateInputs['d'], $this->_dateInputs['y']);
118: }
119: }
120: