]> git.mjollnir.org Git - moodle.git/commitdiff
Attempting to make the form more compact by merging yes/no fields as an enable checkb...
authormark-nielsen <mark-nielsen>
Tue, 24 Jul 2007 08:12:12 +0000 (08:12 +0000)
committermark-nielsen <mark-nielsen>
Tue, 24 Jul 2007 08:12:12 +0000 (08:12 +0000)
mod/lesson/lib.php
mod/lesson/mod_form.php

index 7b0e12f8def600f4db8ccc43b9ebdb2e42c68f62..40a092c0d6f799ea5ad08ecebdfccb66962b390a 100644 (file)
@@ -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;
     }
index ebb222884735bd91042139c28cd2401dbd10716c..a0f677694d7c426865021ce91d0159be8f15bd04 100644 (file)
@@ -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;
+    }
 }
 ?>