Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/lesson/mod_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00030 require_once($CFG->dirroot.'/course/moodleform_mod.php');
00031 require_once($CFG->dirroot.'/mod/lesson/locallib.php');
00032 
00033 class mod_lesson_mod_form extends moodleform_mod {
00034 
00035     protected $course = null;
00036 
00037     public function mod_lesson_mod_form($current, $section, $cm, $course) {
00038         $this->course = $course;
00039         parent::moodleform_mod($current, $section, $cm, $course);
00040     }
00041 
00042     function definition() {
00043         global $CFG, $COURSE, $DB;
00044 
00045         $mform    = $this->_form;
00046 
00047 //-------------------------------------------------------------------------------
00048         $mform->addElement('header', 'general', get_string('general', 'form'));
00049 
00051         $mform->addElement('hidden', 'width');
00052         $mform->setType('width', PARAM_INT);
00053         $mform->setDefault('width', $CFG->lesson_slideshowwidth);
00054 
00056         $mform->addElement('hidden', 'height');
00057         $mform->setType('height', PARAM_INT);
00058         $mform->setDefault('height', $CFG->lesson_slideshowheight);
00059 
00061         $mform->addElement('hidden', 'bgcolor');
00062         $mform->setType('bgcolor', PARAM_TEXT);
00063         $mform->setDefault('bgcolor', $CFG->lesson_slideshowbgcolor);
00064 
00066         $mform->addElement('hidden', 'mediawidth');
00067         $mform->setType('mediawidth', PARAM_INT);
00068         $mform->setDefault('mediawidth', $CFG->lesson_mediawidth);
00069 
00071         $mform->addElement('hidden', 'mediaheight');
00072         $mform->setType('mediaheight', PARAM_INT);
00073         $mform->setDefault('mediaheight', $CFG->lesson_mediaheight);
00074 
00076         $mform->addElement('hidden', 'mediaclose');
00077         $mform->setType('mediaclose', PARAM_BOOL);
00078         $mform->setDefault('mediaclose', $CFG->lesson_mediaclose);
00079 
00081         $mform->addElement('hidden', 'maxhighscores');
00082         $mform->setType('maxhighscores', PARAM_INT);
00083         $mform->setDefault('maxhighscores', $CFG->lesson_maxhighscores);
00084 
00085         $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
00086         if (!empty($CFG->formatstringstriptags)) {
00087             $mform->setType('name', PARAM_TEXT);
00088         } else {
00089             $mform->setType('name', PARAM_CLEANHTML);
00090         }
00091         $mform->addRule('name', null, 'required', null, 'client');
00092 
00093         // Create a text box that can be enabled/disabled for lesson time limit
00094         $timedgrp = array();
00095         $timedgrp[] = &$mform->createElement('text', 'maxtime');
00096         $timedgrp[] = &$mform->createElement('checkbox', 'timed', '', get_string('enable'));
00097         $mform->addGroup($timedgrp, 'timedgrp', get_string('maxtime', 'lesson'), array(' '), false);
00098         $mform->disabledIf('timedgrp', 'timed');
00099 
00100         // Add numeric rule to text field
00101         $timedgrprules = array();
00102         $timedgrprules['maxtime'][] = array(null, 'numeric', null, 'client');
00103         $mform->addGroupRule('timedgrp', $timedgrprules);
00104 
00105         // Rest of group setup
00106         $mform->setDefault('timed', 0);
00107         $mform->setDefault('maxtime', 20);
00108         $mform->setType('maxtime', PARAM_INT);
00109 
00110         $numbers = array();
00111         for ($i=20; $i>1; $i--) {
00112             $numbers[$i] = $i;
00113         }
00114 
00115         $mform->addElement('date_time_selector', 'available', get_string('available', 'lesson'), array('optional'=>true));
00116         $mform->setDefault('available', 0);
00117 
00118         $mform->addElement('date_time_selector', 'deadline', get_string('deadline', 'lesson'), array('optional'=>true));
00119         $mform->setDefault('deadline', 0);
00120 
00121         $mform->addElement('select', 'maxanswers', get_string('maximumnumberofanswersbranches', 'lesson'), $numbers);
00122         $mform->setDefault('maxanswers', $CFG->lesson_maxanswers);
00123         $mform->setType('maxanswers', PARAM_INT);
00124         $mform->addHelpButton('maxanswers', 'maximumnumberofanswersbranches', 'lesson');
00125 
00126         $mform->addElement('selectyesno', 'usepassword', get_string('usepassword', 'lesson'));
00127         $mform->addHelpButton('usepassword', 'usepassword', 'lesson');
00128         $mform->setDefault('usepassword', 0);
00129         $mform->setAdvanced('usepassword');
00130 
00131         $mform->addElement('passwordunmask', 'password', get_string('password', 'lesson'));
00132         $mform->setDefault('password', '');
00133         $mform->setType('password', PARAM_RAW);
00134         $mform->setAdvanced('password');
00135         $mform->disabledIf('password', 'usepassword', 'eq', 0);
00136 
00137         $this->standard_grading_coursemodule_elements();
00138 
00139 //-------------------------------------------------------------------------------
00140         $mform->addElement('header', 'gradeoptions', get_string('gradeoptions', 'lesson'));
00141 
00142         $mform->addElement('selectyesno', 'practice', get_string('practice', 'lesson'));
00143         $mform->addHelpButton('practice', 'practice', 'lesson');
00144         $mform->setDefault('practice', 0);
00145 
00146         $mform->addElement('selectyesno', 'custom', get_string('customscoring', 'lesson'));
00147         $mform->addHelpButton('custom', 'customscoring', 'lesson');
00148         $mform->setDefault('custom', 1);
00149 
00150         $mform->addElement('selectyesno', 'retake', get_string('retakesallowed', 'lesson'));
00151         $mform->addHelpButton('retake', 'retakesallowed', 'lesson');
00152         $mform->setDefault('retake', 0);
00153 
00154         $options = array();
00155         $options[0] = get_string('usemean', 'lesson');
00156         $options[1] = get_string('usemaximum', 'lesson');
00157         $mform->addElement('select', 'usemaxgrade', get_string('handlingofretakes', 'lesson'), $options);
00158         $mform->addHelpButton('usemaxgrade', 'handlingofretakes', 'lesson');
00159         $mform->setDefault('usemaxgrade', 0);
00160         $mform->disabledIf('usemaxgrade', 'retake', 'eq', '0');
00161 
00162         $mform->addElement('selectyesno', 'ongoing', get_string('ongoing', 'lesson'));
00163         $mform->addHelpButton('ongoing', 'ongoing', 'lesson');
00164         $mform->setDefault('ongoing', 0);
00165 
00166 //-------------------------------------------------------------------------------
00167         $mform->addElement('header', 'flowcontrol', get_string('flowcontrol', 'lesson'));
00168 
00169         $mform->addElement('selectyesno', 'modattempts', get_string('modattempts', 'lesson'));
00170         $mform->addHelpButton('modattempts', 'modattempts', 'lesson');
00171         $mform->setDefault('modattempts', 0);
00172 
00173         $mform->addElement('selectyesno', 'review', get_string('displayreview', 'lesson'));
00174         $mform->addHelpButton('review', 'displayreview', 'lesson');
00175         $mform->setDefault('review', 0);
00176 
00177         $numbers = array();
00178         for ($i=10; $i>0; $i--) {
00179             $numbers[$i] = $i;
00180         }
00181         $mform->addElement('select', 'maxattempts', get_string('maximumnumberofattempts', 'lesson'), $numbers);
00182         $mform->addHelpButton('maxattempts', 'maximumnumberofattempts', 'lesson');
00183         $mform->setDefault('maxattempts', 1);
00184 
00185         $defaultnextpages = array();
00186         $defaultnextpages[0] = get_string('normal', 'lesson');
00187         $defaultnextpages[LESSON_UNSEENPAGE] = get_string('showanunseenpage', 'lesson');
00188         $defaultnextpages[LESSON_UNANSWEREDPAGE] = get_string('showanunansweredpage', 'lesson');
00189         $mform->addElement('select', 'nextpagedefault', get_string('actionaftercorrectanswer', 'lesson'), $defaultnextpages);
00190         $mform->addHelpButton('nextpagedefault', 'actionaftercorrectanswer', 'lesson');
00191         $mform->setDefault('nextpagedefault', $CFG->lesson_defaultnextpage);
00192         $mform->setAdvanced('nextpagedefault');
00193 
00194         $mform->addElement('selectyesno', 'feedback', get_string('displaydefaultfeedback', 'lesson'));
00195         $mform->addHelpButton('feedback', 'displaydefaultfeedback', 'lesson');
00196         $mform->setDefault('feedback', 0);
00197 
00198         $mform->addElement('selectyesno', 'progressbar', get_string('progressbar', 'lesson'));
00199         $mform->addHelpButton('progressbar', 'progressbar', 'lesson');
00200         $mform->setDefault('progressbar', 0);
00201 
00202         $mform->addElement('selectyesno', 'displayleft', get_string('displayleftmenu', 'lesson'));
00203         $mform->addHelpButton('displayleft', 'displayleftmenu', 'lesson');
00204         $mform->setDefault('displayleft', 0);
00205 
00206         $options = array();
00207         for($i = 100; $i >= 0; $i--) {
00208             $options[$i] = $i.'%';
00209         }
00210         $mform->addElement('select', 'displayleftif', get_string('displayleftif', 'lesson'), $options);
00211         $mform->addHelpButton('displayleftif', 'displayleftif', 'lesson');
00212         $mform->setDefault('displayleftif', 0);
00213         $mform->setAdvanced('displayleftif');
00214 
00215         $numbers = array();
00216         for ($i = 100; $i >= 0; $i--) {
00217             $numbers[$i] = $i;
00218         }
00219         $mform->addElement('select', 'minquestions', get_string('minimumnumberofquestions', 'lesson'), $numbers);
00220         $mform->addHelpButton('minquestions', 'minimumnumberofquestions', 'lesson');
00221         $mform->setDefault('minquestions', 0);
00222         $mform->setAdvanced('minquestions');
00223 
00224         $numbers = array();
00225         for ($i = 100; $i >= 0; $i--) {
00226             $numbers[$i] = $i;
00227         }
00228         $mform->addElement('select', 'maxpages', get_string('numberofpagestoshow', 'lesson'), $numbers);
00229         $mform->addHelpButton('maxpages', 'numberofpagestoshow', 'lesson');
00230         $mform->setAdvanced('maxpages');
00231         $mform->setDefault('maxpages', 0);
00232 
00233         $mform->addElement('selectyesno', 'slideshow', get_string('slideshow', 'lesson'));
00234         $mform->addHelpButton('slideshow', 'slideshow', 'lesson');
00235         $mform->setDefault('slideshow', 0);
00236         $mform->setAdvanced('slideshow');
00237 
00238         // get the modules
00239         if ($mods = get_course_mods($COURSE->id)) {
00240             $modinstances = array();
00241             foreach ($mods as $mod) {
00242 
00243                 // get the module name and then store it in a new array
00244                 if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) {
00245                     if (isset($this->_cm->id) and $this->_cm->id != $mod->id){
00246                         $modinstances[$mod->id] = $mod->modname.' - '.$module->name;
00247                     }
00248                 }
00249             }
00250             asort($modinstances); // sort by module name
00251             $modinstances=array(0=>get_string('none'))+$modinstances;
00252 
00253             $mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances);
00254             $mform->addHelpButton('activitylink', 'activitylink', 'lesson');
00255             $mform->setDefault('activitylink', 0);
00256             $mform->setAdvanced('activitylink');
00257         }
00258 
00259 //-------------------------------------------------------------------------------
00260         $mform->addElement('header', 'mediafileheader', get_string('mediafile', 'lesson'));
00261 
00262         $filepickeroptions = array();
00263         $filepickeroptions['filetypes'] = '*';
00264         $filepickeroptions['maxbytes'] = $this->course->maxbytes;
00265         $mform->addElement('filepicker', 'mediafilepicker', get_string('mediafile', 'lesson'), null, $filepickeroptions);
00266         $mform->addHelpButton('mediafilepicker', 'mediafile', 'lesson');
00267 
00268 //-------------------------------------------------------------------------------
00269         $mform->addElement('header', 'dependencyon', get_string('dependencyon', 'lesson'));
00270 
00271         $options = array(0=>get_string('none'));
00272         if ($lessons = get_all_instances_in_course('lesson', $COURSE)) {
00273             foreach($lessons as $lesson) {
00274                 if ($lesson->id != $this->_instance){
00275                     $options[$lesson->id] = format_string($lesson->name, true);
00276                 }
00277 
00278             }
00279         }
00280         $mform->addElement('select', 'dependency', get_string('dependencyon', 'lesson'), $options);
00281         $mform->addHelpButton('dependency', 'dependencyon', 'lesson');
00282         $mform->setDefault('dependency', 0);
00283 
00284         $mform->addElement('text', 'timespent', get_string('timespentminutes', 'lesson'));
00285         $mform->setDefault('timespent', 0);
00286         $mform->setType('timespent', PARAM_INT);
00287 
00288         $mform->addElement('checkbox', 'completed', get_string('completed', 'lesson'));
00289         $mform->setDefault('completed', 0);
00290 
00291         $mform->addElement('text', 'gradebetterthan', get_string('gradebetterthan', 'lesson'));
00292         $mform->setDefault('gradebetterthan', 0);
00293         $mform->setType('gradebetterthan', PARAM_INT);
00294 
00295 //-------------------------------------------------------------------------------
00296         $this->standard_coursemodule_elements();
00297 //-------------------------------------------------------------------------------
00298 // buttons
00299         $this->add_action_buttons();
00300     }
00301 
00308     function data_preprocessing(&$default_values) {
00309         global $DB;
00310         global $module;
00311         if (isset($default_values['conditions'])) {
00312             $conditions = unserialize($default_values['conditions']);
00313             $default_values['timespent'] = $conditions->timespent;
00314             $default_values['completed'] = $conditions->completed;
00315             $default_values['gradebetterthan'] = $conditions->gradebetterthan;
00316         }
00317         // after this passwords are clear text, MDL-11090
00318         if (isset($default_values['password']) and ($module->version<2008112600)) {
00319             unset($default_values['password']);
00320         }
00321 
00322         if ($this->current->instance) {
00323             // editing existing instance - copy existing files into draft area
00324             $draftitemid = file_get_submitted_draft_itemid('mediafilepicker');
00325             file_prepare_draft_area($draftitemid, $this->context->id, 'mod_lesson', 'mediafile', 0, array('subdirs'=>0, 'maxbytes' => $this->course->maxbytes, 'maxfiles' => 1));
00326             $default_values['mediafilepicker'] = $draftitemid;
00327         }
00328     }
00329 
00336     function validation($data, $files) {
00337         $errors = parent::validation($data, $files);
00338 
00339         if (empty($data['maxtime']) and !empty($data['timed'])) {
00340             $errors['timedgrp'] = get_string('err_numeric', 'form');
00341         }
00342         if (!empty($data['usepassword']) && empty($data['password'])) {
00343             $errors['password'] = get_string('emptypassword', 'lesson');
00344         }
00345 
00346         return $errors;
00347     }
00348 }
00349 
 All Data Structures Namespaces Files Functions Variables Enumerations