From: mark-nielsen Date: Tue, 24 Jul 2007 08:12:12 +0000 (+0000) Subject: Attempting to make the form more compact by merging yes/no fields as an enable checkb... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=862bd9cd9c8e15897c683852720b9a3b9c8e2096;p=moodle.git Attempting to make the form more compact by merging yes/no fields as an enable checkbox after another field to enable/disable the feature --- diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 7b0e12f8de..40a092c0d6 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -489,6 +489,9 @@ function lesson_get_post_actions() { function lesson_process_pre_save(&$lesson) { $lesson->timemodified = time(); + if (empty($lesson->timed)) { + $lesson->timed = 0; + } if (empty($lesson->timespent) or !is_numeric($lesson->timespent) or $lesson->timespent < 0) { $lesson->timespent = 0; } diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index ebb2228847..a0f677694d 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -25,15 +25,23 @@ class mod_lesson_mod_form extends moodleform_mod { $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); - $mform->addElement('selectyesno', 'timed', get_string('timed', 'lesson')); + // Create a text box that can be enabled/disabled for lesson time limit + $timedgrp = array(); + $timedgrp[] = &$mform->createElement('text', 'maxtime'); + $timedgrp[] = &$mform->createElement('checkbox', 'timed', '', get_string('enable')); + $mform->addGroup($timedgrp, 'timedgrp', get_string('maxtime', 'lesson'), array(' '), false); + $mform->disabledIf('timedgrp', 'timed'); + + // Add numeric rule to text field + $timedgrprules = array(); + $timedgrprules['maxtime'][] = array(null, 'numeric', null, 'client'); + $mform->addGroupRule('timedgrp', $timedgrprules); + + // Rest of group setup $mform->setDefault('timed', 0); - $mform->setHelpButton('timed', array('timed', get_string('timed', 'lesson'), 'lesson')); - - $mform->addElement('text', 'maxtime', get_string('maxtime', 'lesson')); $mform->setDefault('maxtime', 20); - $mform->addRule('maxtime', null, 'required', null, 'client'); - $mform->addRule('maxtime', null, 'numeric', null, 'client'); $mform->setType('maxtime', PARAM_INT); + $mform->setHelpButton('timedgrp', array('timed', get_string('timed', 'lesson'), 'lesson')); $numbers = array(); for ($i=20; $i>1; $i--) { @@ -308,5 +316,21 @@ class mod_lesson_mod_form extends moodleform_mod { } } } + + /** + * Enforce validation rules here + * + * @param object $data Post data to validate + * @return array + **/ + function validation($data) { + $errors = array(); + + if (empty($data['maxtime']) and !empty($data['timed'])) { + $errors['timedgrp'] = get_string('err_numeric', 'form'); + } + + return $errors; + } } ?>