Permalink
Browse files

Modified year selections on date pickers to be current time / year de…

…pendent
  • Loading branch information...
1 parent 137e908 commit a2c7d35ea49a03672ddebb45dc1add6e1f756dd1 @mikeho mikeho committed Jul 18, 2011
@@ -4,13 +4,19 @@ class QDateTimePickerBase extends QControl {
// Private Member Variables
///////////////////////////
+ // DEFAULTS
+ // These are set at the bottom of this script
+ public static $DefaultMinimumYear;
+ public static $DefaultMaximumYear;
+
// MISC
protected $dttDateTime = null;
protected $strDateTimePickerType = QDateTimePickerType::Date;
protected $strDateTimePickerFormat = QDateTimePickerFormat::MonthDayYear;
- protected $intMinimumYear = 1970;
- protected $intMaximumYear = 2015;
+ // If these stay null, then it will use the $DefaultMinimumYear and $DefaultMaximumYear static variables on QDateTimePicker
+ protected $intMinimumYear = null;
+ protected $intMaximumYear = null;
protected $intSelectedMonth = null;
protected $intSelectedDay = null;
@@ -191,12 +197,17 @@ protected function GetControlHtml() {
}
}
$strDayListbox .= '</select>';
-
+
+ // Figure Out Min and Max Years
+ $intMinimumYear = (is_null($this->intMinimumYear)) ? QDateTimePicker::$DefaultMinimumYear : $this->intMinimumYear;
+ $intMaximumYear = (is_null($this->intMaximumYear)) ? QDateTimePicker::$DefaultMaximumYear : $this->intMaximumYear;
+
// Year
$strYearListbox = sprintf('<select name="%s_lstYear" id="%s_lstYear" class="year" %s%s>', $this->strControlId, $this->strControlId, $strAttributes, $strCommand);
if (!$this->blnRequired || $dttDateTime->IsDateNull())
$strYearListbox .= '<option value="">--</option>';
- for ($intYear = $this->intMinimumYear; $intYear <= $this->intMaximumYear; $intYear++) {
+
+ for ($intYear = $intMinimumYear; $intYear <= $intMaximumYear; $intYear++) {
if (/*!$dttDateTime->IsDateNull() && */(($dttDateTime->Year == $intYear) || ($this->intSelectedYear == $intYear)))
$strSelected = ' selected="selected"';
else
@@ -477,4 +488,7 @@ public function __set($strName, $mixValue) {
}
}
}
+
+ QDateTimePickerBase::$DefaultMinimumYear = date('Y') - 30;
+ QDateTimePickerBase::$DefaultMaximumYear = date('Y') + 5;
?>
@@ -10,8 +10,9 @@ class QDateTimePicker extends QDateTimePickerBase {
protected $strDateTimePickerType = QDateTimePickerType::Date;
protected $strDateTimePickerFormat = QDateTimePickerFormat::MonthDayYear;
- protected $intMinimumYear = 1970;
- protected $intMaximumYear = 2015;
+ // If these stay null, then it will use the $DefaultMinimumYear and $DefaultMaximumYear static variables on QDateTimePicker
+ protected $intMinimumYear = null;
+ protected $intMaximumYear = null;
// Default format of the Hour field (see http://www.php.net/date for more info)
// Two digit representation of the hour in 12-hour format followed by UPPER-CASE 'AM' or 'PM'
@@ -122,7 +122,7 @@ function done() {
</select> &nbsp;
<select name="dttYear" class="dropdown" onchange="selectDate(document.myForm.dttYear.options[document.myForm.dttYear.selectedIndex].value)">
<?php
- for ($intYear = 1970; $intYear <= 2010; $intYear++) {
+ for ($intYear = 1970; $intYear <= date('Y') + 1; $intYear++) {
$intTimestampLabel = mktime(0,0,0, $intSelectedMonth, 1, $intYear);
$strLabel = date("Y", $intTimestampLabel);
$strSelected = ($intYear == $intSelectedYear) ? 'selected="selected"' : '';

0 comments on commit a2c7d35

Please sign in to comment.