Modifikationen für PEAR::HTML_Quickform date Element

Wäre doch praktisch, wenn man nicht nur minYear und maxYear deklarieren könnte bei der Generierung von Select-Listen mittels des HTML_Quickform date-Elements – irgendiwe muß man doch auch bestimmte Zeiträume/Uhrzeiten definieren können, oder?

Nun ja, das dachte ich mir auch – und habe die folgenden Attribute neu eingefügt:
‚minHour‘: kleinste Stunde in der Select-Liste
‚maxHour‘: größte Stunde in der Select-Liste
‚minMinute‘: kleinste Minute in der Select-Liste
‚maxMinute‘: größte Minute in der Select-Liste
‚minSec‘: kleinste Sekunde in der Select-Liste
‚maxSec‘: größte Sekunde in der Select-Liste

date.php, die zuständige HTML_Quickform-Datei, habe ich entsprechend erweitert:


unix-box# diff -Nur date.orig.php date.php
--- date.orig.php 2005-10-06 10:05:17.551675037 +0200
+++ date.php 2005-10-06 10:28:12.903695062 +0200
@@ -59,6 +59,12 @@
* A => AM/PM
* 'minYear': Minimum year in year select
* 'maxYear': Maximum year in year select
+ * 'minHour': Minimum hour in select
+ * 'maxHour': Maximum hour in select
+ * 'minMinute': Minimum minute in select
+ * 'maxMinute': Maximum minute in select
+ * 'minSec': Minimum seconds in select
+ * 'maxSec': Maximum seconds in select
* 'addEmptyOption': Should an empty option be added to the top of
* each select box?
* 'emptyOptionValue': The value passed by the empty option.
@@ -73,6 +79,12 @@
'format' => 'dMY',
'minYear' => 2001,
'maxYear' => 2010,
+ 'minHour' => 0,
+ 'maxHour' => 23,
+ 'minMinute' => 0,
+ 'maxMinute' => 59,
+ 'minSec' => 0,
+ 'maxSec' => 59,
'addEmptyOption' => false,
'emptyOptionValue' => '',
'emptyOptionText' => ' ',
@@ -339,13 +351,25 @@
array_walk($options, create_function('&$v,$k', '$v = intval($v);'));
break;
case 'H':
- $options = $this->_createOptionList(0, 23);
+ $options = $this->_createOptionList(
+ $this->_options['minHour'],
+ $this->_options['maxHour'],
+ $this->_options['minHour'] > $this->_options['maxHour']? -1: 1
+ );
break;
case 'i':
- $options = $this->_createOptionList(0, 59, $this->_options['optionIncrement']['i']);
+ $options = $this->_createOptionList(
+ $this->_options['minMinute'],
+ $this->_options['maxMinute'],
+ $this->_options['optionIncrement']['i']
+ );
break;
case 's':
- $options = $this->_createOptionList(0, 59, $this->_options['optionIncrement']['s']);
+ $options = $this->_createOptionList(
+ $this->_options['minSec'],
+ $this->_options['maxSec'],
+ $this->_options['optionIncrement']['s']
+ );
break;
case 'a':
$options = array('am' => 'am', 'pm' => 'pm');

Mittles patch [options] [originalfile [patchfile]] läßt sich obige Erweiterung bequem im eigenen PEAR-Repository einspielen.
Oder man nimmt einfach die hochgeladene date.patched.php und kopiert Sie über das Original, hehe.

Ein zugehöriges PHP Quellcode-Beispiel, das obige Modifikationen anwendet:

$date_select_options = array(
'language' => 'de',
'format' => 'H : i : s',
'minHour' => '18',
'maxHour' => '01',
'minMinute' => '32',
'maxMinute' => '54',
'minSec' => '08',
'maxSec' => '15',
);
// $formular ist ein gültiges HTML_Quickform Objekt
$formular->addElement('date', 'datum', '', $date_select_options);
//... Darstellung

Für alle, die jetzt gerade Hä? Quickform…Was? oder Komfortable Formularerzeugung mit PHP? Hm…? denken, den sei mein Artikel über Smarty und HTML_Quickform, der übrigens auch in der nächsten BI erscheinen wird, wärmstens ans Herz gelegt.