From 25fe66b094d19876a1ce18d3f3ac0f946ab2abd8 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Tue, 10 Mar 2009 06:44:05 +0000 Subject: [PATCH] date form fields: MDL-18502 Change the optional 'disabled' checkbox to an 'enabled' on Better for usability to avoid a double-negative. --- lib/form/dateselector.php | 55 +++++++++++++++++++++++++---------- lib/form/datetimeselector.php | 54 ++++++++++++++++++++++++---------- 2 files changed, 78 insertions(+), 31 deletions(-) diff --git a/lib/form/dateselector.php b/lib/form/dateselector.php index 3687e61240..799f991536 100644 --- a/lib/form/dateselector.php +++ b/lib/form/dateselector.php @@ -1,15 +1,38 @@ -libdir/form/group.php"; -require_once "$CFG->libdir/formslib.php"; +require_once($CFG->libdir . '/form/group.php'); +require_once($CFG->libdir . '/formslib.php'); /** * Class for a group of elements used to input a date. * * Emulates moodle print_date_selector function * - * @author Jamie Pratt - * @access public + * @package formslib */ class MoodleQuickForm_date_selector extends MoodleQuickForm_group { @@ -22,15 +45,15 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group * applydst => apply users daylight savings adjustment? * optional => if true, show a checkbox beside the date to turn it on (or off) */ - var $_options = array('startyear'=>1970, 'stopyear'=>2020, - 'timezone'=>99, 'applydst'=>true, 'optional'=>false); + protected $_options = array('startyear' => 1970, 'stopyear' => 2020, + 'timezone' => 99, 'applydst' => true, 'optional' => false); /** * These complement separators, they are appended to the resultant HTML * @access private * @var array */ - var $_wrap = array('', ''); + protected $_wrap = array('', ''); /** * Class constructor @@ -81,7 +104,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group $this->_elements[] =& MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $this->getAttributes(), true); // If optional we add a checkbox which the user can use to turn if on if($this->_options['optional']) { - $this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'off', null, get_string('disable'), $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true); } foreach ($this->_elements as $element){ if (method_exists($element, 'setHiddenLabel')){ @@ -132,10 +155,10 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group 'year' => $currentdate['year']); // If optional, default to off, unless a date was provided if($this->_options['optional']) { - $value['off'] = ($requestvalue == 0) ? true : false; + $value['enabled'] = $requestvalue != 0; } } else { - $value['off'] = (isset($value['off'])) ? true : false; + $value['enabled'] = isset($value['enabled']); } if (null !== $value){ $this->setValue($value); @@ -143,7 +166,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group break; case 'createElement': if($arg[2]['optional']) { - $caller->disabledIf($arg[0], $arg[0].'[off]', 'checked'); + $caller->disabledIf($arg[0], $arg[0].'[enabled]'); } return parent::onQuickFormEvent($event, $arg, $caller); break; @@ -193,16 +216,16 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group if (count($valuearray)){ if($this->_options['optional']) { // If checkbox is on, the value is zero, so go no further - if(!empty($valuearray['off'])) { - $value[$this->getName()]=0; + if(empty($valuearray['enabled'])) { + $value[$this->getName()] = 0; return $value; } } - $value[$this->getName()]=make_timestamp($valuearray['year'], + $value[$this->getName()] = make_timestamp($valuearray['year'], $valuearray['month'], $valuearray['day'], - 0,0,0, + 0, 0, 0, $this->_options['timezone'], $this->_options['applydst']); diff --git a/lib/form/datetimeselector.php b/lib/form/datetimeselector.php index 3e5aba7559..e5f4abe385 100644 --- a/lib/form/datetimeselector.php +++ b/lib/form/datetimeselector.php @@ -1,15 +1,38 @@ -libdir/form/group.php"; -require_once "$CFG->libdir/formslib.php"; +require_once($CFG->libdir . '/form/group.php'); +require_once($CFG->libdir . '/formslib.php'); /** * Class for a group of elements used to input a date and time. * * Emulates moodle print_date_selector function and also allows you to select a time. * - * @author Jamie Pratt - * @access public + * @package formslib */ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ /** @@ -20,9 +43,10 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ * timezone => float/string timezone * applydst => apply users daylight savings adjustment? * step => step to increment minutes by + * optional => if true, show a checkbox beside the date to turn it on (or off) */ - var $_options = array('startyear'=>1970, 'stopyear'=>2020, - 'timezone'=>99, 'applydst'=>true, 'step'=>5, 'optional'=>false); + var $_options = array('startyear' => 1970, 'stopyear' => 2020, + 'timezone' => 99, 'applydst' => true, 'step' => 5, 'optional' => false); /** * These complement separators, they are appended to the resultant HTML @@ -93,7 +117,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ } // If optional we add a checkbox which the user can use to turn if on if($this->_options['optional']) { - $this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'off', null, get_string('disable'), $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'enabled', null, get_string('enable'), $this->getAttributes(), true); } foreach ($this->_elements as $element){ if (method_exists($element, 'setHiddenLabel')){ @@ -148,10 +172,10 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ 'year' => $currentdate['year']); // If optional, default to off, unless a date was provided if($this->_options['optional']) { - $value['off'] = ($requestvalue == 0) ? true : false; + $value['enabled'] = $requestvalue != 0; } } else { - $value['off'] = (isset($value['off'])) ? true : false; + $value['enabled'] = isset($value['off']); } if (null !== $value){ $this->setValue($value); @@ -159,7 +183,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ break; case 'createElement': if($arg[2]['optional']) { - $caller->disabledIf($arg[0], $arg[0].'[off]', 'checked'); + $caller->disabledIf($arg[0], $arg[0].'[enabled]'); } return parent::onQuickFormEvent($event, $arg, $caller); break; @@ -210,13 +234,13 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ if (count($valuearray)){ if($this->_options['optional']) { // If checkbox is on, the value is zero, so go no further - if(!empty($valuearray['off'])) { - $value[$this->getName()]=0; + if(empty($valuearray['enabled'])) { + $value[$this->getName()] = 0; return $value; } } - $valuearray=$valuearray + array('year'=>1970, 'month'=>1, 'day'=>1, 'hour'=>0, 'minute'=>0); - $value[$this->getName()]=make_timestamp( + $valuearray=$valuearray + array('year' => 1970, 'month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0); + $value[$this->getName()] = make_timestamp( $valuearray['year'], $valuearray['month'], $valuearray['day'], -- 2.39.5