Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-39463 forms: use the date selectors 'optional' parameter rather t…

…han creating additional logic
  • Loading branch information...
commit e019dcccdf5d5d75ffc41e775c4932a364ad1da7 1 parent 2fd46e1
@markn86 markn86 authored
View
10 lib/form/dateselector.php
@@ -182,7 +182,15 @@ function onQuickFormEvent($event, $arg, &$caller)
// Optional is an optional param, if its set we need to add a disabledIf rule.
// If its empty or not specified then its not an optional dateselector.
if (!empty($arg[2]['optional']) && !empty($arg[0])) {
- $caller->disabledIf($arg[0], $arg[0].'[enabled]');
+ // When using the function addElement, rather than createElement, we still
+ // enter this case, making this check necessary.
+ if ($this->_usedcreateelement) {
+ $caller->disabledIf($arg[0] . '[day]', $arg[0] . '[enabled]');
+ $caller->disabledIf($arg[0] . '[month]', $arg[0] . '[enabled]');
+ $caller->disabledIf($arg[0] . '[year]', $arg[0] . '[enabled]');
+ } else {
+ $caller->disabledIf($arg[0], $arg[0] . '[enabled]');
+ }
}
return parent::onQuickFormEvent($event, $arg, $caller);
break;
View
12 lib/form/datetimeselector.php
@@ -201,7 +201,17 @@ function onQuickFormEvent($event, $arg, &$caller)
break;
case 'createElement':
if($arg[2]['optional']) {
- $caller->disabledIf($arg[0], $arg[0].'[enabled]');
+ // When using the function addElement, rather than createElement, we still
+ // enter this case, making this check necessary.
+ if ($this->_usedcreateelement) {
+ $caller->disabledIf($arg[0] . '[day]', $arg[0] . '[enabled]');
+ $caller->disabledIf($arg[0] . '[month]', $arg[0] . '[enabled]');
+ $caller->disabledIf($arg[0] . '[year]', $arg[0] . '[enabled]');
+ $caller->disabledIf($arg[0] . '[hour]', $arg[0] . '[enabled]');
+ $caller->disabledIf($arg[0] . '[minute]', $arg[0] . '[enabled]');
+ } else {
+ $caller->disabledIf($arg[0], $arg[0] . '[enabled]');
+ }
}
return parent::onQuickFormEvent($event, $arg, $caller);
break;
View
14 mod/feedback/lib.php
@@ -80,13 +80,6 @@ function feedback_add_instance($feedback) {
$feedback->timemodified = time();
$feedback->id = '';
- //check if openenable and/or closeenable is set and set correctly to save in db
- if (empty($feedback->openenable)) {
- $feedback->timeopen = 0;
- }
- if (empty($feedback->closeenable)) {
- $feedback->timeclose = 0;
- }
if (empty($feedback->site_after_submit)) {
$feedback->site_after_submit = '';
}
@@ -133,13 +126,6 @@ function feedback_update_instance($feedback) {
$feedback->timemodified = time();
$feedback->id = $feedback->instance;
- //check if openenable and/or closeenable is set and set correctly to save in db
- if (empty($feedback->openenable)) {
- $feedback->timeopen = 0;
- }
- if (empty($feedback->closeenable)) {
- $feedback->timeclose = 0;
- }
if (empty($feedback->site_after_submit)) {
$feedback->site_after_submit = '';
}
View
42 mod/feedback/mod_form.php
@@ -51,33 +51,11 @@ public function definition() {
//-------------------------------------------------------------------------------
$mform->addElement('header', 'timinghdr', get_string('availability'));
- $enableopengroup = array();
- $enableopengroup[] =& $mform->createElement('checkbox',
- 'openenable',
- get_string('feedbackopen', 'feedback'));
-
- $enableopengroup[] =& $mform->createElement('date_time_selector', 'timeopen', '');
- $mform->addGroup($enableopengroup,
- 'enableopengroup',
- get_string('feedbackopen', 'feedback'),
- ' ',
- false);
-
- $mform->disabledIf('enableopengroup', 'openenable', 'notchecked');
-
- $enableclosegroup = array();
- $enableclosegroup[] =& $mform->createElement('checkbox',
- 'closeenable',
- get_string('feedbackclose', 'feedback'));
-
- $enableclosegroup[] =& $mform->createElement('date_time_selector', 'timeclose', '');
- $mform->addGroup($enableclosegroup,
- 'enableclosegroup',
- get_string('feedbackclose', 'feedback'),
- ' ',
- false);
-
- $mform->disabledIf('enableclosegroup', 'closeenable', 'notchecked');
+ $mform->addElement('date_time_selector', 'timeopen', get_string('feedbackopen', 'feedback'),
+ array('optional' => true));
+
+ $mform->addElement('date_time_selector', 'timeclose', get_string('feedbackclose', 'feedback'),
+ array('optional' => true));
//-------------------------------------------------------------------------------
$mform->addElement('header', 'feedbackhdr', get_string('questionandsubmission', 'feedback'));
@@ -155,16 +133,6 @@ public function definition() {
}
public function data_preprocessing(&$default_values) {
- if (empty($default_values['timeopen'])) {
- $default_values['openenable'] = 0;
- } else {
- $default_values['openenable'] = 1;
- }
- if (empty($default_values['timeclose'])) {
- $default_values['closeenable'] = 0;
- } else {
- $default_values['closeenable'] = 1;
- }
$editoroptions = feedback_get_editor_options();
View
20 mod/scorm/mod_form.php
@@ -215,26 +215,6 @@ function definition() {
$mform->setDefault('lastattemptlock', $cfg_scorm->lastattemptlock);
$mform->setAdvanced('lastattemptlock', $cfg_scorm->lastattemptlock_adv);
- // Activation period
-/* $mform->addElement('static', '', '' ,'<hr />');
- $mform->addElement('static', 'activation', get_string('activation','scorm'));
- $datestartgrp = array();
- $datestartgrp[] = &$mform->createElement('date_time_selector', 'startdate');
- $datestartgrp[] = &$mform->createElement('checkbox', 'startdisabled', null, get_string('disable'));
- $mform->addGroup($datestartgrp, 'startdategrp', get_string('from'), ' ', false);
- $mform->setDefault('startdate', 0);
- $mform->setDefault('startdisabled', 1);
- $mform->disabledIf('startdategrp', 'startdisabled', 'checked');
-
- $dateendgrp = array();
- $dateendgrp[] = &$mform->createElement('date_time_selector', 'enddate');
- $dateendgrp[] = &$mform->createElement('checkbox', 'enddisabled', null, get_string('disable'));
- $mform->addGroup($dateendgrp, 'dateendgrp', get_string('to'), ' ', false);
- $mform->setDefault('enddate', 0);
- $mform->setDefault('enddisabled', 1);
- $mform->disabledIf('dateendgrp', 'enddisabled', 'checked');
-*/
-
// Autocontinue
$mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm'));
$mform->addHelpButton('auto', 'autocontinue', 'scorm');
View
29 user/filters/date.php
@@ -30,24 +30,15 @@ function user_filter_date($name, $label, $advanced, $field) {
function setupForm(&$mform) {
$objs = array();
- $objs[] =& $mform->createElement('checkbox', $this->_name.'_sck', null, get_string('isafter', 'filters'));
- $objs[] =& $mform->createElement('date_selector', $this->_name.'_sdt', null);
+ $objs[] =& $mform->createElement('date_selector', $this->_name.'_sdt', null, array('optional' => true));
$objs[] =& $mform->createElement('static', $this->_name.'_break', null, '<br/>');
- $objs[] =& $mform->createElement('checkbox', $this->_name.'_eck', null, get_string('isbefore', 'filters'));
- $objs[] =& $mform->createElement('date_selector', $this->_name.'_edt', null);
+ $objs[] =& $mform->createElement('date_selector', $this->_name.'_edt', null, array('optional' => true));
$grp =& $mform->addElement('group', $this->_name.'_grp', $this->_label, $objs, '', false);
if ($this->_advanced) {
$mform->setAdvanced($this->_name.'_grp');
}
-
- $mform->disabledIf($this->_name.'_sdt[day]', $this->_name.'_sck', 'notchecked');
- $mform->disabledIf($this->_name.'_sdt[month]', $this->_name.'_sck', 'notchecked');
- $mform->disabledIf($this->_name.'_sdt[year]', $this->_name.'_sck', 'notchecked');
- $mform->disabledIf($this->_name.'_edt[day]', $this->_name.'_eck', 'notchecked');
- $mform->disabledIf($this->_name.'_edt[month]', $this->_name.'_eck', 'notchecked');
- $mform->disabledIf($this->_name.'_edt[year]', $this->_name.'_eck', 'notchecked');
}
/**
@@ -56,26 +47,16 @@ function setupForm(&$mform) {
* @return mixed array filter data or false when filter not set
*/
function check_data($formdata) {
- $sck = $this->_name.'_sck';
$sdt = $this->_name.'_sdt';
- $eck = $this->_name.'_eck';
$edt = $this->_name.'_edt';
- if (!array_key_exists($sck, $formdata) and !array_key_exists($eck, $formdata)) {
+ if (!$formdata->$sdt and !$formdata->$edt) {
return false;
}
$data = array();
- if (array_key_exists($sck, $formdata)) {
- $data['after'] = $formdata->$sdt;
- } else {
- $data['after'] = 0;
- }
- if (array_key_exists($eck, $formdata)) {
- $data['before'] = $formdata->$edt;
- } else {
- $data['before'] = 0;
- }
+ $data['after'] = $formdata->$sdt;
+ $data['before'] = $formdata->$edt;
return $data;
}
Please sign in to comment.
Something went wrong with that request. Please try again.