[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * Form to define a new instance of lesson or edit an instance. 20 * It is used from /course/modedit.php. 21 * 22 * @package mod_lesson 23 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late 25 **/ 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 require_once($CFG->dirroot.'/course/moodleform_mod.php'); 30 require_once($CFG->dirroot.'/mod/lesson/locallib.php'); 31 32 class mod_lesson_mod_form extends moodleform_mod { 33 34 protected $course = null; 35 36 public function mod_lesson_mod_form($current, $section, $cm, $course) { 37 $this->course = $course; 38 parent::moodleform_mod($current, $section, $cm, $course); 39 } 40 41 function definition() { 42 global $CFG, $COURSE, $DB; 43 44 $mform = $this->_form; 45 46 $config = get_config('lesson'); 47 48 $mform->addElement('header', 'general', get_string('general', 'form')); 49 50 /** Legacy slideshow width element to maintain backwards compatibility */ 51 $mform->addElement('hidden', 'width'); 52 $mform->setType('width', PARAM_INT); 53 $mform->setDefault('width', $CFG->lesson_slideshowwidth); 54 55 /** Legacy slideshow height element to maintain backwards compatibility */ 56 $mform->addElement('hidden', 'height'); 57 $mform->setType('height', PARAM_INT); 58 $mform->setDefault('height', $CFG->lesson_slideshowheight); 59 60 /** Legacy slideshow background color element to maintain backwards compatibility */ 61 $mform->addElement('hidden', 'bgcolor'); 62 $mform->setType('bgcolor', PARAM_TEXT); 63 $mform->setDefault('bgcolor', $CFG->lesson_slideshowbgcolor); 64 65 /** Legacy media popup width element to maintain backwards compatibility */ 66 $mform->addElement('hidden', 'mediawidth'); 67 $mform->setType('mediawidth', PARAM_INT); 68 $mform->setDefault('mediawidth', $CFG->lesson_mediawidth); 69 70 /** Legacy media popup height element to maintain backwards compatibility */ 71 $mform->addElement('hidden', 'mediaheight'); 72 $mform->setType('mediaheight', PARAM_INT); 73 $mform->setDefault('mediaheight', $CFG->lesson_mediaheight); 74 75 /** Legacy media popup close button element to maintain backwards compatibility */ 76 $mform->addElement('hidden', 'mediaclose'); 77 $mform->setType('mediaclose', PARAM_BOOL); 78 $mform->setDefault('mediaclose', $CFG->lesson_mediaclose); 79 80 /** Legacy maximum highscores element to maintain backwards compatibility */ 81 $mform->addElement('hidden', 'maxhighscores'); 82 $mform->setType('maxhighscores', PARAM_INT); 83 $mform->setDefault('maxhighscores', $CFG->lesson_maxhighscores); 84 85 $mform->addElement('text', 'name', get_string('name'), array('size'=>'64')); 86 if (!empty($CFG->formatstringstriptags)) { 87 $mform->setType('name', PARAM_TEXT); 88 } else { 89 $mform->setType('name', PARAM_CLEANHTML); 90 } 91 $mform->addRule('name', null, 'required', null, 'client'); 92 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 93 $this->add_intro_editor($config->requiremodintro); 94 95 // Appearance. 96 $mform->addElement('header', 'appearancehdr', get_string('appearance')); 97 98 $filemanageroptions = array(); 99 $filemanageroptions['filetypes'] = '*'; 100 $filemanageroptions['maxbytes'] = $this->course->maxbytes; 101 $filemanageroptions['subdirs'] = 0; 102 $filemanageroptions['maxfiles'] = 1; 103 104 $mform->addElement('filemanager', 'mediafile', get_string('mediafile', 'lesson'), null, $filemanageroptions); 105 $mform->addHelpButton('mediafile', 'mediafile', 'lesson'); 106 107 $mform->addElement('selectyesno', 'progressbar', get_string('progressbar', 'lesson')); 108 $mform->addHelpButton('progressbar', 'progressbar', 'lesson'); 109 $mform->setDefault('progressbar', 0); 110 111 $mform->addElement('selectyesno', 'ongoing', get_string('ongoing', 'lesson')); 112 $mform->addHelpButton('ongoing', 'ongoing', 'lesson'); 113 $mform->setDefault('ongoing', 0); 114 115 $mform->addElement('selectyesno', 'displayleft', get_string('displayleftmenu', 'lesson')); 116 $mform->addHelpButton('displayleft', 'displayleftmenu', 'lesson'); 117 $mform->setDefault('displayleft', 0); 118 119 $options = array(); 120 for($i = 100; $i >= 0; $i--) { 121 $options[$i] = $i.'%'; 122 } 123 $mform->addElement('select', 'displayleftif', get_string('displayleftif', 'lesson'), $options); 124 $mform->addHelpButton('displayleftif', 'displayleftif', 'lesson'); 125 $mform->setDefault('displayleftif', 0); 126 127 $mform->addElement('selectyesno', 'slideshow', get_string('slideshow', 'lesson')); 128 $mform->addHelpButton('slideshow', 'slideshow', 'lesson'); 129 $mform->setDefault('slideshow', 0); 130 131 $numbers = array(); 132 for ($i = 20; $i > 1; $i--) { 133 $numbers[$i] = $i; 134 } 135 136 $mform->addElement('select', 'maxanswers', get_string('maximumnumberofanswersbranches', 'lesson'), $numbers); 137 $mform->setDefault('maxanswers', $CFG->lesson_maxanswers); 138 $mform->setType('maxanswers', PARAM_INT); 139 $mform->addHelpButton('maxanswers', 'maximumnumberofanswersbranches', 'lesson'); 140 141 $mform->addElement('selectyesno', 'feedback', get_string('displaydefaultfeedback', 'lesson')); 142 $mform->addHelpButton('feedback', 'displaydefaultfeedback', 'lesson'); 143 $mform->setDefault('feedback', 0); 144 145 // Get the modules. 146 if ($mods = get_course_mods($COURSE->id)) { 147 $modinstances = array(); 148 foreach ($mods as $mod) { 149 150 // get the module name and then store it in a new array 151 if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) { 152 if (isset($this->_cm->id) and $this->_cm->id != $mod->id){ 153 $modinstances[$mod->id] = $mod->modname.' - '.$module->name; 154 } 155 } 156 } 157 asort($modinstances); // sort by module name 158 $modinstances=array(0=>get_string('none'))+$modinstances; 159 160 $mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances); 161 $mform->addHelpButton('activitylink', 'activitylink', 'lesson'); 162 $mform->setDefault('activitylink', 0); 163 } 164 165 // Availability. 166 $mform->addElement('header', 'availabilityhdr', get_string('availability')); 167 168 $mform->addElement('date_time_selector', 'available', get_string('available', 'lesson'), array('optional'=>true)); 169 $mform->setDefault('available', 0); 170 171 $mform->addElement('date_time_selector', 'deadline', get_string('deadline', 'lesson'), array('optional'=>true)); 172 $mform->setDefault('deadline', 0); 173 174 // Create a text box that can be enabled/disabled for lesson time limit 175 $timedgrp = array(); 176 $timedgrp[] = &$mform->createElement('text', 'maxtime'); 177 $timedgrp[] = &$mform->createElement('checkbox', 'timed', '', get_string('enable')); 178 $mform->addGroup($timedgrp, 'timedgrp', get_string('maxtime', 'lesson'), array(' '), false); 179 $mform->disabledIf('timedgrp', 'timed'); 180 181 // Add numeric rule to text field 182 $timedgrprules = array(); 183 $timedgrprules['maxtime'][] = array(null, 'numeric', null, 'client'); 184 $mform->addGroupRule('timedgrp', $timedgrprules); 185 186 // Rest of group setup 187 $mform->setDefault('timed', 0); 188 $mform->setDefault('maxtime', 20); 189 $mform->setType('maxtime', PARAM_INT); 190 191 $mform->addElement('selectyesno', 'usepassword', get_string('usepassword', 'lesson')); 192 $mform->addHelpButton('usepassword', 'usepassword', 'lesson'); 193 $mform->setDefault('usepassword', 0); 194 195 $mform->addElement('passwordunmask', 'password', get_string('password', 'lesson')); 196 $mform->setDefault('password', ''); 197 $mform->setType('password', PARAM_RAW); 198 $mform->disabledIf('password', 'usepassword', 'eq', 0); 199 $mform->disabledIf('passwordunmask', 'usepassword', 'eq', 0); 200 201 // Dependent on. 202 $mform->addElement('header', 'dependencyon', get_string('prerequisitelesson', 'lesson')); 203 204 $options = array(0=>get_string('none')); 205 if ($lessons = get_all_instances_in_course('lesson', $COURSE)) { 206 foreach($lessons as $lesson) { 207 if ($lesson->id != $this->_instance){ 208 $options[$lesson->id] = format_string($lesson->name, true); 209 } 210 211 } 212 } 213 $mform->addElement('select', 'dependency', get_string('dependencyon', 'lesson'), $options); 214 $mform->addHelpButton('dependency', 'dependencyon', 'lesson'); 215 $mform->setDefault('dependency', 0); 216 217 $mform->addElement('text', 'timespent', get_string('timespentminutes', 'lesson')); 218 $mform->setDefault('timespent', 0); 219 $mform->setType('timespent', PARAM_INT); 220 $mform->disabledIf('timespent', 'dependency', 'eq', 0); 221 222 $mform->addElement('checkbox', 'completed', get_string('completed', 'lesson')); 223 $mform->setDefault('completed', 0); 224 $mform->disabledIf('completed', 'dependency', 'eq', 0); 225 226 $mform->addElement('text', 'gradebetterthan', get_string('gradebetterthan', 'lesson')); 227 $mform->setDefault('gradebetterthan', 0); 228 $mform->setType('gradebetterthan', PARAM_INT); 229 $mform->disabledIf('gradebetterthan', 'dependency', 'eq', 0); 230 231 // Flow control. 232 $mform->addElement('header', 'flowcontrol', get_string('flowcontrol', 'lesson')); 233 234 $mform->addElement('selectyesno', 'modattempts', get_string('modattempts', 'lesson')); 235 $mform->addHelpButton('modattempts', 'modattempts', 'lesson'); 236 $mform->setDefault('modattempts', 0); 237 238 $mform->addElement('selectyesno', 'review', get_string('displayreview', 'lesson')); 239 $mform->addHelpButton('review', 'displayreview', 'lesson'); 240 $mform->setDefault('review', 0); 241 242 $numbers = array(); 243 for ($i = 10; $i > 0; $i--) { 244 $numbers[$i] = $i; 245 } 246 $mform->addElement('select', 'maxattempts', get_string('maximumnumberofattempts', 'lesson'), $numbers); 247 $mform->addHelpButton('maxattempts', 'maximumnumberofattempts', 'lesson'); 248 $mform->setDefault('maxattempts', 1); 249 250 $defaultnextpages = array(); 251 $defaultnextpages[0] = get_string('normal', 'lesson'); 252 $defaultnextpages[LESSON_UNSEENPAGE] = get_string('showanunseenpage', 'lesson'); 253 $defaultnextpages[LESSON_UNANSWEREDPAGE] = get_string('showanunansweredpage', 'lesson'); 254 $mform->addElement('select', 'nextpagedefault', get_string('actionaftercorrectanswer', 'lesson'), $defaultnextpages); 255 $mform->addHelpButton('nextpagedefault', 'actionaftercorrectanswer', 'lesson'); 256 $mform->setDefault('nextpagedefault', $CFG->lesson_defaultnextpage); 257 258 $numbers = array(); 259 for ($i = 100; $i >= 0; $i--) { 260 $numbers[$i] = $i; 261 } 262 $mform->addElement('select', 'maxpages', get_string('numberofpagestoshow', 'lesson'), $numbers); 263 $mform->addHelpButton('maxpages', 'numberofpagestoshow', 'lesson'); 264 $mform->setDefault('maxpages', 0); 265 266 // Grade. 267 $this->standard_grading_coursemodule_elements(); 268 269 // No header here, so that the following settings are displayed in the grade section. 270 271 $mform->addElement('selectyesno', 'practice', get_string('practice', 'lesson')); 272 $mform->addHelpButton('practice', 'practice', 'lesson'); 273 $mform->setDefault('practice', 0); 274 275 $mform->addElement('selectyesno', 'custom', get_string('customscoring', 'lesson')); 276 $mform->addHelpButton('custom', 'customscoring', 'lesson'); 277 $mform->setDefault('custom', 1); 278 279 $mform->addElement('selectyesno', 'retake', get_string('retakesallowed', 'lesson')); 280 $mform->addHelpButton('retake', 'retakesallowed', 'lesson'); 281 $mform->setDefault('retake', 0); 282 283 $options = array(); 284 $options[0] = get_string('usemean', 'lesson'); 285 $options[1] = get_string('usemaximum', 'lesson'); 286 $mform->addElement('select', 'usemaxgrade', get_string('handlingofretakes', 'lesson'), $options); 287 $mform->addHelpButton('usemaxgrade', 'handlingofretakes', 'lesson'); 288 $mform->setDefault('usemaxgrade', 0); 289 $mform->disabledIf('usemaxgrade', 'retake', 'eq', '0'); 290 291 $numbers = array(); 292 for ($i = 100; $i >= 0; $i--) { 293 $numbers[$i] = $i; 294 } 295 $mform->addElement('select', 'minquestions', get_string('minimumnumberofquestions', 'lesson'), $numbers); 296 $mform->addHelpButton('minquestions', 'minimumnumberofquestions', 'lesson'); 297 $mform->setDefault('minquestions', 0); 298 299 //------------------------------------------------------------------------------- 300 $this->standard_coursemodule_elements(); 301 //------------------------------------------------------------------------------- 302 // buttons 303 $this->add_action_buttons(); 304 } 305 306 /** 307 * Enforce defaults here 308 * 309 * @param array $default_values Form defaults 310 * @return void 311 **/ 312 function data_preprocessing(&$default_values) { 313 if (isset($default_values['conditions'])) { 314 $conditions = unserialize($default_values['conditions']); 315 $default_values['timespent'] = $conditions->timespent; 316 $default_values['completed'] = $conditions->completed; 317 $default_values['gradebetterthan'] = $conditions->gradebetterthan; 318 } 319 320 if ($this->current->instance) { 321 // Editing existing instance - copy existing files into draft area. 322 $draftitemid = file_get_submitted_draft_itemid('mediafile'); 323 file_prepare_draft_area($draftitemid, $this->context->id, 'mod_lesson', 'mediafile', 0, array('subdirs'=>0, 'maxbytes' => $this->course->maxbytes, 'maxfiles' => 1)); 324 $default_values['mediafile'] = $draftitemid; 325 } 326 } 327 328 /** 329 * Enforce validation rules here 330 * 331 * @param object $data Post data to validate 332 * @return array 333 **/ 334 function validation($data, $files) { 335 $errors = parent::validation($data, $files); 336 337 if (empty($data['maxtime']) and !empty($data['timed'])) { 338 $errors['timedgrp'] = get_string('err_numeric', 'form'); 339 } 340 if (!empty($data['usepassword']) && empty($data['password'])) { 341 $errors['password'] = get_string('emptypassword', 'lesson'); 342 } 343 344 return $errors; 345 } 346 } 347
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |