1 |
efrain |
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 __construct($current, $section, $cm, $course) {
|
|
|
37 |
$this->course = $course;
|
|
|
38 |
parent::__construct($current, $section, $cm, $course);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Old syntax of class constructor. Deprecated in PHP7.
|
|
|
43 |
*
|
|
|
44 |
* @deprecated since Moodle 3.1
|
|
|
45 |
*/
|
|
|
46 |
public function mod_lesson_mod_form($current, $section, $cm, $course) {
|
|
|
47 |
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
|
|
|
48 |
self::__construct($current, $section, $cm, $course);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
function definition() {
|
|
|
52 |
global $CFG, $COURSE, $DB, $OUTPUT;
|
|
|
53 |
|
|
|
54 |
$mform = $this->_form;
|
|
|
55 |
|
|
|
56 |
$lessonconfig = get_config('mod_lesson');
|
|
|
57 |
|
|
|
58 |
$mform->addElement('header', 'general', get_string('general', 'form'));
|
|
|
59 |
|
|
|
60 |
/** Legacy slideshow width element to maintain backwards compatibility */
|
|
|
61 |
$mform->addElement('hidden', 'width');
|
|
|
62 |
$mform->setType('width', PARAM_INT);
|
|
|
63 |
$mform->setDefault('width', $lessonconfig->slideshowwidth);
|
|
|
64 |
|
|
|
65 |
/** Legacy slideshow height element to maintain backwards compatibility */
|
|
|
66 |
$mform->addElement('hidden', 'height');
|
|
|
67 |
$mform->setType('height', PARAM_INT);
|
|
|
68 |
$mform->setDefault('height', $lessonconfig->slideshowheight);
|
|
|
69 |
|
|
|
70 |
/** Legacy slideshow background color element to maintain backwards compatibility */
|
|
|
71 |
$mform->addElement('hidden', 'bgcolor');
|
|
|
72 |
$mform->setType('bgcolor', PARAM_TEXT);
|
|
|
73 |
$mform->setDefault('bgcolor', $lessonconfig->slideshowbgcolor);
|
|
|
74 |
|
|
|
75 |
/** Legacy media popup width element to maintain backwards compatibility */
|
|
|
76 |
$mform->addElement('hidden', 'mediawidth');
|
|
|
77 |
$mform->setType('mediawidth', PARAM_INT);
|
|
|
78 |
$mform->setDefault('mediawidth', $lessonconfig->mediawidth);
|
|
|
79 |
|
|
|
80 |
/** Legacy media popup height element to maintain backwards compatibility */
|
|
|
81 |
$mform->addElement('hidden', 'mediaheight');
|
|
|
82 |
$mform->setType('mediaheight', PARAM_INT);
|
|
|
83 |
$mform->setDefault('mediaheight', $lessonconfig->mediaheight);
|
|
|
84 |
|
|
|
85 |
/** Legacy media popup close button element to maintain backwards compatibility */
|
|
|
86 |
$mform->addElement('hidden', 'mediaclose');
|
|
|
87 |
$mform->setType('mediaclose', PARAM_BOOL);
|
|
|
88 |
$mform->setDefault('mediaclose', $lessonconfig->mediaclose);
|
|
|
89 |
|
|
|
90 |
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
|
|
|
91 |
if (!empty($CFG->formatstringstriptags)) {
|
|
|
92 |
$mform->setType('name', PARAM_TEXT);
|
|
|
93 |
} else {
|
|
|
94 |
$mform->setType('name', PARAM_CLEANHTML);
|
|
|
95 |
}
|
|
|
96 |
$mform->addRule('name', null, 'required', null, 'client');
|
|
|
97 |
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
|
|
98 |
$this->standard_intro_elements();
|
|
|
99 |
|
|
|
100 |
// Appearance.
|
|
|
101 |
$mform->addElement('header', 'appearancehdr', get_string('appearance'));
|
|
|
102 |
|
|
|
103 |
$filemanageroptions = array();
|
|
|
104 |
$filemanageroptions['filetypes'] = '*';
|
|
|
105 |
$filemanageroptions['maxbytes'] = $this->course->maxbytes;
|
|
|
106 |
$filemanageroptions['subdirs'] = 0;
|
|
|
107 |
$filemanageroptions['maxfiles'] = 1;
|
|
|
108 |
|
|
|
109 |
$mform->addElement('filemanager', 'mediafile', get_string('mediafile', 'lesson'), null, $filemanageroptions);
|
|
|
110 |
$mform->addHelpButton('mediafile', 'mediafile', 'lesson');
|
|
|
111 |
$mform->setAdvanced('mediafile', $lessonconfig->mediafile_adv);
|
|
|
112 |
|
|
|
113 |
$mform->addElement('selectyesno', 'progressbar', get_string('progressbar', 'lesson'));
|
|
|
114 |
$mform->addHelpButton('progressbar', 'progressbar', 'lesson');
|
|
|
115 |
$mform->setDefault('progressbar', $lessonconfig->progressbar);
|
|
|
116 |
$mform->setAdvanced('progressbar', $lessonconfig->progressbar_adv);
|
|
|
117 |
|
|
|
118 |
$mform->addElement('selectyesno', 'ongoing', get_string('ongoing', 'lesson'));
|
|
|
119 |
$mform->addHelpButton('ongoing', 'ongoing', 'lesson');
|
|
|
120 |
$mform->setDefault('ongoing', $lessonconfig->ongoing);
|
|
|
121 |
$mform->setAdvanced('ongoing', $lessonconfig->ongoing_adv);
|
|
|
122 |
|
|
|
123 |
$mform->addElement('selectyesno', 'displayleft', get_string('displayleftmenu', 'lesson'));
|
|
|
124 |
$mform->addHelpButton('displayleft', 'displayleftmenu', 'lesson');
|
|
|
125 |
$mform->setDefault('displayleft', $lessonconfig->displayleftmenu);
|
|
|
126 |
$mform->setAdvanced('displayleft', $lessonconfig->displayleftmenu_adv);
|
|
|
127 |
|
|
|
128 |
$options = array();
|
|
|
129 |
for($i = 100; $i >= 0; $i--) {
|
|
|
130 |
$options[$i] = $i.'%';
|
|
|
131 |
}
|
|
|
132 |
$mform->addElement('select', 'displayleftif', get_string('displayleftif', 'lesson'), $options);
|
|
|
133 |
$mform->addHelpButton('displayleftif', 'displayleftif', 'lesson');
|
|
|
134 |
$mform->setDefault('displayleftif', $lessonconfig->displayleftif);
|
|
|
135 |
$mform->setAdvanced('displayleftif', $lessonconfig->displayleftif_adv);
|
|
|
136 |
|
|
|
137 |
$mform->addElement('selectyesno', 'slideshow', get_string('slideshow', 'lesson'));
|
|
|
138 |
$mform->addHelpButton('slideshow', 'slideshow', 'lesson');
|
|
|
139 |
$mform->setDefault('slideshow', $lessonconfig->slideshow);
|
|
|
140 |
$mform->setAdvanced('slideshow', $lessonconfig->slideshow_adv);
|
|
|
141 |
|
|
|
142 |
$numbers = array();
|
|
|
143 |
for ($i = 20; $i > 1; $i--) {
|
|
|
144 |
$numbers[$i] = $i;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
$mform->addElement('select', 'maxanswers', get_string('maximumnumberofanswersbranches', 'lesson'), $numbers);
|
|
|
148 |
$mform->setDefault('maxanswers', $lessonconfig->maxanswers);
|
|
|
149 |
$mform->setAdvanced('maxanswers', $lessonconfig->maxanswers_adv);
|
|
|
150 |
$mform->setType('maxanswers', PARAM_INT);
|
|
|
151 |
$mform->addHelpButton('maxanswers', 'maximumnumberofanswersbranches', 'lesson');
|
|
|
152 |
|
|
|
153 |
$mform->addElement('selectyesno', 'feedback', get_string('displaydefaultfeedback', 'lesson'));
|
|
|
154 |
$mform->addHelpButton('feedback', 'displaydefaultfeedback', 'lesson');
|
|
|
155 |
$mform->setDefault('feedback', $lessonconfig->defaultfeedback);
|
|
|
156 |
$mform->setAdvanced('feedback', $lessonconfig->defaultfeedback_adv);
|
|
|
157 |
|
|
|
158 |
// Get the modules.
|
|
|
159 |
if ($mods = get_course_mods($COURSE->id)) {
|
|
|
160 |
$modinstances = array();
|
|
|
161 |
foreach ($mods as $mod) {
|
|
|
162 |
// Get the module name and then store it in a new array.
|
|
|
163 |
if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) {
|
|
|
164 |
// Exclude this lesson, if it's already been saved.
|
|
|
165 |
if (!isset($this->_cm->id) || $this->_cm->id != $mod->id) {
|
|
|
166 |
$modinstances[$mod->id] = get_string('pluginname', $mod->modname) . ' - ' . format_string(
|
|
|
167 |
$module->name,
|
|
|
168 |
true,
|
|
|
169 |
[
|
|
|
170 |
'context' => $this->context,
|
|
|
171 |
],
|
|
|
172 |
);
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
asort($modinstances); // Sort by module name.
|
|
|
177 |
$modinstances=array(0=>get_string('none'))+$modinstances;
|
|
|
178 |
|
|
|
179 |
$mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances);
|
|
|
180 |
$mform->addHelpButton('activitylink', 'activitylink', 'lesson');
|
|
|
181 |
$mform->setDefault('activitylink', 0);
|
|
|
182 |
$mform->setAdvanced('activitylink', $lessonconfig->activitylink_adv);
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
// Availability.
|
|
|
186 |
$mform->addElement('header', 'availabilityhdr', get_string('availability'));
|
|
|
187 |
|
|
|
188 |
$mform->addElement('date_time_selector', 'available', get_string('available', 'lesson'), array('optional'=>true));
|
|
|
189 |
$mform->setDefault('available', 0);
|
|
|
190 |
|
|
|
191 |
$mform->addElement('date_time_selector', 'deadline', get_string('deadline', 'lesson'), array('optional'=>true));
|
|
|
192 |
$mform->setDefault('deadline', 0);
|
|
|
193 |
|
|
|
194 |
// Time limit.
|
|
|
195 |
$mform->addElement('duration', 'timelimit', get_string('timelimit', 'lesson'),
|
|
|
196 |
array('optional' => true));
|
|
|
197 |
$mform->addHelpButton('timelimit', 'timelimit', 'lesson');
|
|
|
198 |
$mform->setAdvanced('timelimit', $lessonconfig->timelimit_adv);
|
|
|
199 |
$mform->setDefault('timelimit', $lessonconfig->timelimit);
|
|
|
200 |
|
|
|
201 |
$mform->addElement('selectyesno', 'usepassword', get_string('usepassword', 'lesson'));
|
|
|
202 |
$mform->addHelpButton('usepassword', 'usepassword', 'lesson');
|
|
|
203 |
$mform->setDefault('usepassword', $lessonconfig->password);
|
|
|
204 |
$mform->setAdvanced('usepassword', $lessonconfig->password_adv);
|
|
|
205 |
|
|
|
206 |
$mform->addElement('passwordunmask', 'password', get_string('password', 'lesson'));
|
|
|
207 |
$mform->setDefault('password', '');
|
|
|
208 |
$mform->setAdvanced('password', $lessonconfig->password_adv);
|
|
|
209 |
$mform->setType('password', PARAM_RAW);
|
|
|
210 |
$mform->hideIf('password', 'usepassword', 'eq', 0);
|
|
|
211 |
$mform->hideIf('passwordunmask', 'usepassword', 'eq', 0);
|
|
|
212 |
|
|
|
213 |
// Dependent on.
|
|
|
214 |
if ($this->current && isset($this->current->dependency) && $this->current->dependency) {
|
|
|
215 |
$mform->addElement('header', 'dependencyon', get_string('prerequisitelesson', 'lesson'));
|
|
|
216 |
$mform->addElement('static', 'warningobsolete',
|
|
|
217 |
get_string('warning', 'lesson'),
|
|
|
218 |
get_string('prerequisiteisobsolete', 'lesson'));
|
|
|
219 |
$options = array(0 => get_string('none'));
|
|
|
220 |
if ($lessons = get_all_instances_in_course('lesson', $COURSE)) {
|
|
|
221 |
foreach ($lessons as $lesson) {
|
|
|
222 |
if ($lesson->id != $this->_instance) {
|
|
|
223 |
$options[$lesson->id] = format_string($lesson->name, true);
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
$mform->addElement('select', 'dependency', get_string('dependencyon', 'lesson'), $options);
|
|
|
229 |
$mform->addHelpButton('dependency', 'dependencyon', 'lesson');
|
|
|
230 |
$mform->setDefault('dependency', 0);
|
|
|
231 |
|
|
|
232 |
$mform->addElement('text', 'timespent', get_string('timespentminutes', 'lesson'));
|
|
|
233 |
$mform->setDefault('timespent', 0);
|
|
|
234 |
$mform->setType('timespent', PARAM_INT);
|
|
|
235 |
$mform->disabledIf('timespent', 'dependency', 'eq', 0);
|
|
|
236 |
|
|
|
237 |
$mform->addElement('checkbox', 'completed', get_string('completed', 'lesson'));
|
|
|
238 |
$mform->setDefault('completed', 0);
|
|
|
239 |
$mform->disabledIf('completed', 'dependency', 'eq', 0);
|
|
|
240 |
|
|
|
241 |
$mform->addElement('text', 'gradebetterthan', get_string('gradebetterthan', 'lesson'));
|
|
|
242 |
$mform->setDefault('gradebetterthan', 0);
|
|
|
243 |
$mform->setType('gradebetterthan', PARAM_INT);
|
|
|
244 |
$mform->disabledIf('gradebetterthan', 'dependency', 'eq', 0);
|
|
|
245 |
} else {
|
|
|
246 |
$mform->addElement('hidden', 'dependency', 0);
|
|
|
247 |
$mform->setType('dependency', PARAM_INT);
|
|
|
248 |
$mform->addElement('hidden', 'timespent', 0);
|
|
|
249 |
$mform->setType('timespent', PARAM_INT);
|
|
|
250 |
$mform->addElement('hidden', 'completed', 0);
|
|
|
251 |
$mform->setType('completed', PARAM_INT);
|
|
|
252 |
$mform->addElement('hidden', 'gradebetterthan', 0);
|
|
|
253 |
$mform->setType('gradebetterthan', PARAM_INT);
|
|
|
254 |
$mform->setConstants(array('dependency' => 0, 'timespent' => 0,
|
|
|
255 |
'completed' => 0, 'gradebetterthan' => 0));
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
// Allow to enable offline lessons only if the Mobile services are enabled.
|
|
|
259 |
if ($CFG->enablemobilewebservice) {
|
|
|
260 |
$mform->addElement('selectyesno', 'allowofflineattempts', get_string('allowofflineattempts', 'lesson'));
|
|
|
261 |
$mform->addHelpButton('allowofflineattempts', 'allowofflineattempts', 'lesson');
|
|
|
262 |
$mform->setDefault('allowofflineattempts', 0);
|
|
|
263 |
$mform->setAdvanced('allowofflineattempts');
|
|
|
264 |
$mform->disabledIf('allowofflineattempts', 'timelimit[number]', 'neq', 0);
|
|
|
265 |
|
|
|
266 |
$mform->addElement('static', 'allowofflineattemptswarning', '',
|
|
|
267 |
$OUTPUT->notification(get_string('allowofflineattempts_help', 'lesson'), 'warning'));
|
|
|
268 |
$mform->setAdvanced('allowofflineattemptswarning');
|
|
|
269 |
} else {
|
|
|
270 |
$mform->addElement('hidden', 'allowofflineattempts', 0);
|
|
|
271 |
$mform->setType('allowofflineattempts', PARAM_INT);
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
// Flow control.
|
|
|
275 |
$mform->addElement('header', 'flowcontrol', get_string('flowcontrol', 'lesson'));
|
|
|
276 |
|
|
|
277 |
$mform->addElement('selectyesno', 'modattempts', get_string('modattempts', 'lesson'));
|
|
|
278 |
$mform->addHelpButton('modattempts', 'modattempts', 'lesson');
|
|
|
279 |
$mform->setDefault('modattempts', $lessonconfig->modattempts);
|
|
|
280 |
$mform->setAdvanced('modattempts', $lessonconfig->modattempts_adv);
|
|
|
281 |
|
|
|
282 |
$mform->addElement('selectyesno', 'review', get_string('displayreview', 'lesson'));
|
|
|
283 |
$mform->addHelpButton('review', 'displayreview', 'lesson');
|
|
|
284 |
$mform->setDefault('review', $lessonconfig->displayreview);
|
|
|
285 |
$mform->setAdvanced('review', $lessonconfig->displayreview_adv);
|
|
|
286 |
|
|
|
287 |
$numbers = array('0' => get_string('unlimited'));
|
|
|
288 |
for ($i = 10; $i > 0; $i--) {
|
|
|
289 |
$numbers[$i] = $i;
|
|
|
290 |
}
|
|
|
291 |
$mform->addElement('select', 'maxattempts', get_string('maximumnumberofattempts', 'lesson'), $numbers);
|
|
|
292 |
$mform->addHelpButton('maxattempts', 'maximumnumberofattempts', 'lesson');
|
|
|
293 |
$mform->setDefault('maxattempts', $lessonconfig->maximumnumberofattempts);
|
|
|
294 |
$mform->setAdvanced('maxattempts', $lessonconfig->maximumnumberofattempts_adv);
|
|
|
295 |
|
|
|
296 |
$defaultnextpages = array();
|
|
|
297 |
$defaultnextpages[0] = get_string('normal', 'lesson');
|
|
|
298 |
$defaultnextpages[LESSON_UNSEENPAGE] = get_string('showanunseenpage', 'lesson');
|
|
|
299 |
$defaultnextpages[LESSON_UNANSWEREDPAGE] = get_string('showanunansweredpage', 'lesson');
|
|
|
300 |
$mform->addElement('select', 'nextpagedefault', get_string('actionaftercorrectanswer', 'lesson'), $defaultnextpages);
|
|
|
301 |
$mform->addHelpButton('nextpagedefault', 'actionaftercorrectanswer', 'lesson');
|
|
|
302 |
$mform->setDefault('nextpagedefault', $lessonconfig->defaultnextpage);
|
|
|
303 |
$mform->setAdvanced('nextpagedefault', $lessonconfig->defaultnextpage_adv);
|
|
|
304 |
|
|
|
305 |
$numbers = array();
|
|
|
306 |
for ($i = 100; $i >= 0; $i--) {
|
|
|
307 |
$numbers[$i] = $i;
|
|
|
308 |
}
|
|
|
309 |
$mform->addElement('select', 'maxpages', get_string('numberofpagestoshow', 'lesson'), $numbers);
|
|
|
310 |
$mform->addHelpButton('maxpages', 'numberofpagestoshow', 'lesson');
|
|
|
311 |
$mform->setDefault('maxpages', $lessonconfig->numberofpagestoshow);
|
|
|
312 |
$mform->setAdvanced('maxpages', $lessonconfig->numberofpagestoshow_adv);
|
|
|
313 |
|
|
|
314 |
// Grade.
|
|
|
315 |
$this->standard_grading_coursemodule_elements();
|
|
|
316 |
|
|
|
317 |
// No header here, so that the following settings are displayed in the grade section.
|
|
|
318 |
|
|
|
319 |
$mform->addElement('selectyesno', 'practice', get_string('practice', 'lesson'));
|
|
|
320 |
$mform->addHelpButton('practice', 'practice', 'lesson');
|
|
|
321 |
$mform->setDefault('practice', $lessonconfig->practice);
|
|
|
322 |
$mform->setAdvanced('practice', $lessonconfig->practice_adv);
|
|
|
323 |
|
|
|
324 |
$mform->addElement('selectyesno', 'custom', get_string('customscoring', 'lesson'));
|
|
|
325 |
$mform->addHelpButton('custom', 'customscoring', 'lesson');
|
|
|
326 |
$mform->setDefault('custom', $lessonconfig->customscoring);
|
|
|
327 |
$mform->setAdvanced('custom', $lessonconfig->customscoring_adv);
|
|
|
328 |
|
|
|
329 |
$mform->addElement('selectyesno', 'retake', get_string('retakesallowed', 'lesson'));
|
|
|
330 |
$mform->addHelpButton('retake', 'retakesallowed', 'lesson');
|
|
|
331 |
$mform->setDefault('retake', $lessonconfig->retakesallowed);
|
|
|
332 |
$mform->setAdvanced('retake', $lessonconfig->retakesallowed_adv);
|
|
|
333 |
|
|
|
334 |
$options = array();
|
|
|
335 |
$options[0] = get_string('usemean', 'lesson');
|
|
|
336 |
$options[1] = get_string('usemaximum', 'lesson');
|
|
|
337 |
$mform->addElement('select', 'usemaxgrade', get_string('handlingofretakes', 'lesson'), $options);
|
|
|
338 |
$mform->addHelpButton('usemaxgrade', 'handlingofretakes', 'lesson');
|
|
|
339 |
$mform->setDefault('usemaxgrade', $lessonconfig->handlingofretakes);
|
|
|
340 |
$mform->setAdvanced('usemaxgrade', $lessonconfig->handlingofretakes_adv);
|
|
|
341 |
$mform->hideIf('usemaxgrade', 'retake', 'eq', '0');
|
|
|
342 |
|
|
|
343 |
$numbers = array();
|
|
|
344 |
for ($i = 100; $i >= 0; $i--) {
|
|
|
345 |
$numbers[$i] = $i;
|
|
|
346 |
}
|
|
|
347 |
$mform->addElement('select', 'minquestions', get_string('minimumnumberofquestions', 'lesson'), $numbers);
|
|
|
348 |
$mform->addHelpButton('minquestions', 'minimumnumberofquestions', 'lesson');
|
|
|
349 |
$mform->setDefault('minquestions', $lessonconfig->minimumnumberofquestions);
|
|
|
350 |
$mform->setAdvanced('minquestions', $lessonconfig->minimumnumberofquestions_adv);
|
|
|
351 |
|
|
|
352 |
//-------------------------------------------------------------------------------
|
|
|
353 |
$this->standard_coursemodule_elements();
|
|
|
354 |
//-------------------------------------------------------------------------------
|
|
|
355 |
// buttons
|
|
|
356 |
$this->add_action_buttons();
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
/**
|
|
|
360 |
* Enforce defaults here
|
|
|
361 |
*
|
|
|
362 |
* @param array $defaultvalues Form defaults
|
|
|
363 |
* @return void
|
|
|
364 |
**/
|
|
|
365 |
public function data_preprocessing(&$defaultvalues) {
|
|
|
366 |
if (isset($defaultvalues['conditions'])) {
|
|
|
367 |
$conditions = unserialize_object($defaultvalues['conditions']);
|
|
|
368 |
$defaultvalues['timespent'] = $conditions->timespent ?? 0;
|
|
|
369 |
$defaultvalues['completed'] = !empty($conditions->completed);
|
|
|
370 |
$defaultvalues['gradebetterthan'] = $conditions->gradebetterthan ?? 0;
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
// Set up the completion checkbox which is not part of standard data.
|
|
|
374 |
$suffix = $this->get_suffix();
|
|
|
375 |
$completiontimespentenabledel = 'completiontimespentenabled' . $suffix;
|
|
|
376 |
$completiontimespentel = 'completiontimespent' . $suffix;
|
|
|
377 |
$defaultvalues[$completiontimespentenabledel] = !empty($defaultvalues[$completiontimespentel]) ? 1 : 0;
|
|
|
378 |
|
|
|
379 |
if ($this->current->instance) {
|
|
|
380 |
// Editing existing instance - copy existing files into draft area.
|
|
|
381 |
$draftitemid = file_get_submitted_draft_itemid('mediafile');
|
|
|
382 |
file_prepare_draft_area($draftitemid, $this->context->id, 'mod_lesson', 'mediafile', 0, array('subdirs'=>0, 'maxbytes' => $this->course->maxbytes, 'maxfiles' => 1));
|
|
|
383 |
$defaultvalues['mediafile'] = $draftitemid;
|
|
|
384 |
}
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
/**
|
|
|
388 |
* Enforce validation rules here
|
|
|
389 |
*
|
|
|
390 |
* @param object $data Post data to validate
|
|
|
391 |
* @return array
|
|
|
392 |
**/
|
|
|
393 |
function validation($data, $files) {
|
|
|
394 |
$errors = parent::validation($data, $files);
|
|
|
395 |
|
|
|
396 |
// Check open and close times are consistent.
|
|
|
397 |
if ($data['available'] != 0 && $data['deadline'] != 0 &&
|
|
|
398 |
$data['deadline'] < $data['available']) {
|
|
|
399 |
$errors['deadline'] = get_string('closebeforeopen', 'lesson');
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
if (!empty($data['usepassword']) && empty($data['password'])) {
|
|
|
403 |
$errors['password'] = get_string('emptypassword', 'lesson');
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
return $errors;
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
/**
|
|
|
410 |
* Display module-specific activity completion rules.
|
|
|
411 |
* Part of the API defined by moodleform_mod
|
|
|
412 |
* @return array Array of string IDs of added items, empty array if none
|
|
|
413 |
*/
|
|
|
414 |
public function add_completion_rules() {
|
|
|
415 |
$mform = $this->_form;
|
|
|
416 |
|
|
|
417 |
$suffix = $this->get_suffix();
|
|
|
418 |
$completionendreachedel = 'completionendreached' . $suffix;
|
|
|
419 |
$mform->addElement(
|
|
|
420 |
'checkbox', $completionendreachedel,
|
|
|
421 |
'',
|
|
|
422 |
get_string('completionendreached', 'lesson')
|
|
|
423 |
);
|
|
|
424 |
// Enable this completion rule by default.
|
|
|
425 |
$mform->setDefault($completionendreachedel, 1);
|
|
|
426 |
|
|
|
427 |
$group = [];
|
|
|
428 |
$completiontimespentenabledel = 'completiontimespentenabled' . $suffix;
|
|
|
429 |
$group[] =& $mform->createElement(
|
|
|
430 |
'checkbox',
|
|
|
431 |
$completiontimespentenabledel,
|
|
|
432 |
'',
|
|
|
433 |
get_string('completiontimespentgroup', 'lesson')
|
|
|
434 |
);
|
|
|
435 |
$completiontimespentel = 'completiontimespent' . $suffix;
|
|
|
436 |
$group[] =& $mform->createElement('duration', $completiontimespentel, '', ['optional' => false]);
|
|
|
437 |
$completiontimespentgroupel = 'completiontimespentgroup' . $suffix;
|
|
|
438 |
$mform->addGroup($group, $completiontimespentgroupel, '', ' ', false);
|
|
|
439 |
$mform->hideIf($completiontimespentel . '[number]', $completiontimespentenabledel, 'notchecked');
|
|
|
440 |
$mform->hideIf($completiontimespentel . '[timeunit]', $completiontimespentenabledel, 'notchecked');
|
|
|
441 |
|
|
|
442 |
return [$completionendreachedel, $completiontimespentgroupel];
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
/**
|
|
|
446 |
* Called during validation. Indicates whether a module-specific completion rule is selected.
|
|
|
447 |
*
|
|
|
448 |
* @param array $data Input data (not yet validated)
|
|
|
449 |
* @return bool True if one or more rules is enabled, false if none are.
|
|
|
450 |
*/
|
|
|
451 |
public function completion_rule_enabled($data) {
|
|
|
452 |
$suffix = $this->get_suffix();
|
|
|
453 |
return !empty($data['completionendreached' . $suffix]) || $data['completiontimespent' . $suffix] > 0;
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
/**
|
|
|
457 |
* Allows module to modify the data returned by form get_data().
|
|
|
458 |
* This method is also called in the bulk activity completion form.
|
|
|
459 |
*
|
|
|
460 |
* Only available on moodleform_mod.
|
|
|
461 |
*
|
|
|
462 |
* @param stdClass $data the form data to be modified.
|
|
|
463 |
*/
|
|
|
464 |
public function data_postprocessing($data) {
|
|
|
465 |
parent::data_postprocessing($data);
|
|
|
466 |
// Turn off completion setting if the checkbox is not ticked.
|
|
|
467 |
if (!empty($data->completionunlocked)) {
|
|
|
468 |
$suffix = $this->get_suffix();
|
|
|
469 |
$completion = $data->{'completion' . $suffix};
|
|
|
470 |
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
|
|
471 |
if (empty($data->{'completiontimespentenabled' . $suffix}) || !$autocompletion) {
|
|
|
472 |
$data->{'completiontimespent' . $suffix} = 0;
|
|
|
473 |
}
|
|
|
474 |
if (empty($data->{'completionendreached' . $suffix}) || !$autocompletion) {
|
|
|
475 |
$data->{'completionendreached' . $suffix} = 0;
|
|
|
476 |
}
|
|
|
477 |
}
|
|
|
478 |
}
|
|
|
479 |
}
|