MDL-65835 plagiarism: Initial deprecation of old functions.
[moodle.git] / mod / forum / mod_form.php
CommitLineData
535e0ab6 1<?php
8f685009
SH
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/**
01030f1b 19 * @package mod_forum
8f685009
SH
20 * @copyright Jamie Pratt <me@jamiep.org>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
bfebaf64
MD
24if (!defined('MOODLE_INTERNAL')) {
25 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
26}
27
23a7718b 28require_once ($CFG->dirroot.'/course/moodleform_mod.php');
e24b7f85 29
92b229c5
AN
30use core_grades\component_gradeitems;
31
f07b9627 32class mod_forum_mod_form extends moodleform_mod {
535e0ab6 33
2ee60b49 34 function definition() {
c18269c7 35 global $CFG, $COURSE, $DB;
535e0ab6 36
2ee60b49 37 $mform =& $this->_form;
535e0ab6 38
39//-------------------------------------------------------------------------------
40 $mform->addElement('header', 'general', get_string('general', 'form'));
41
26de8d35 42 $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64'));
8eb1d25f 43 if (!empty($CFG->formatstringstriptags)) {
fbe9f668 44 $mform->setType('name', PARAM_TEXT);
8eb1d25f 45 } else {
b8ea3041 46 $mform->setType('name', PARAM_CLEANHTML);
8eb1d25f 47 }
2ee60b49 48 $mform->addRule('name', null, 'required', null, 'client');
b230cac1 49 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
535e0ab6 50
6398ff53 51 $this->standard_intro_elements(get_string('forumintro', 'forum'));
65bcf17b 52
f1b0908b 53 $forumtypes = forum_get_forum_types();
2f1e464a 54 core_collator::asort($forumtypes, core_collator::SORT_STRING);
fbe9f668 55 $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forumtypes);
530d2d72 56 $mform->addHelpButton('type', 'forumtype', 'forum');
2ee60b49 57 $mform->setDefault('type', 'general');
535e0ab6 58
ceea2d26
SR
59 $mform->addElement('header', 'availability', get_string('availability', 'forum'));
60
61 $name = get_string('duedate', 'forum');
62 $mform->addElement('date_time_selector', 'duedate', $name, array('optional' => true));
63 $mform->addHelpButton('duedate', 'duedate', 'forum');
64
65 $name = get_string('cutoffdate', 'forum');
66 $mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional' => true));
67 $mform->addHelpButton('cutoffdate', 'cutoffdate', 'forum');
68
fbe9f668
FM
69 // Attachments and word count.
70 $mform->addElement('header', 'attachmentswordcounthdr', get_string('attachmentswordcount', 'forum'));
535e0ab6 71
367b977d 72 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, 0, $CFG->forum_maxbytes);
535e0ab6 73 $choices[1] = get_string('uploadnotallowed');
535e0ab6 74 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices);
530d2d72 75 $mform->addHelpButton('maxbytes', 'maxattachmentsize', 'forum');
2ee60b49 76 $mform->setDefault('maxbytes', $CFG->forum_maxbytes);
535e0ab6 77
7a98bbab
KW
78 $choices = array(
79 0 => 0,
80 1 => 1,
81 2 => 2,
82 3 => 3,
83 4 => 4,
84 5 => 5,
85 6 => 6,
86 7 => 7,
87 8 => 8,
88 9 => 9,
89 10 => 10,
90 20 => 20,
91 50 => 50,
92 100 => 100
93 );
30a9aff5 94 $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'forum'), $choices);
530d2d72 95 $mform->addHelpButton('maxattachments', 'maxattachments', 'forum');
30a9aff5 96 $mform->setDefault('maxattachments', $CFG->forum_maxattachments);
97
506522d5
FM
98 $mform->addElement('selectyesno', 'displaywordcount', get_string('displaywordcount', 'forum'));
99 $mform->addHelpButton('displaywordcount', 'displaywordcount', 'forum');
100 $mform->setDefault('displaywordcount', 0);
fbe9f668
FM
101
102 // Subscription and tracking.
103 $mform->addElement('header', 'subscriptionandtrackinghdr', get_string('subscriptionandtracking', 'forum'));
104
3f6e42b6 105 $options = forum_get_subscriptionmode_options();
fbe9f668
FM
106 $mform->addElement('select', 'forcesubscribe', get_string('subscriptionmode', 'forum'), $options);
107 $mform->addHelpButton('forcesubscribe', 'subscriptionmode', 'forum');
3f6e42b6
DM
108 if (isset($CFG->forum_subscription)) {
109 $defaultforumsubscription = $CFG->forum_subscription;
110 } else {
111 $defaultforumsubscription = FORUM_CHOOSESUBSCRIBE;
112 }
113 $mform->setDefault('forcesubscribe', $defaultforumsubscription);
fbe9f668
FM
114
115 $options = array();
116 $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum');
117 $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum');
20e6782f 118 if ($CFG->forum_allowforcedreadtracking) {
bd8f5d45 119 $options[FORUM_TRACKING_FORCED] = get_string('trackingon', 'forum');
20e6782f 120 }
fbe9f668
FM
121 $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options);
122 $mform->addHelpButton('trackingtype', 'trackingtype', 'forum');
20e6782f 123 $default = $CFG->forum_trackingtype;
bd8f5d45 124 if ((!$CFG->forum_allowforcedreadtracking) && ($default == FORUM_TRACKING_FORCED)) {
20e6782f
EM
125 $default = FORUM_TRACKING_OPTIONAL;
126 }
127 $mform->setDefault('trackingtype', $default);
506522d5 128
535e0ab6 129 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
a02c77dc 130//-------------------------------------------------------------------------------
807cf3d0 131 $mform->addElement('header', 'rssheader', get_string('rss'));
535e0ab6 132 $choices = array();
133 $choices[0] = get_string('none');
134 $choices[1] = get_string('discussions', 'forum');
135 $choices[2] = get_string('posts', 'forum');
136 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
530d2d72 137 $mform->addHelpButton('rsstype', 'rsstype', 'forum');
c9f2d347
RL
138 if (isset($CFG->forum_rsstype)) {
139 $mform->setDefault('rsstype', $CFG->forum_rsstype);
140 }
535e0ab6 141
142 $choices = array();
143 $choices[0] = '0';
144 $choices[1] = '1';
145 $choices[2] = '2';
146 $choices[3] = '3';
147 $choices[4] = '4';
148 $choices[5] = '5';
149 $choices[10] = '10';
150 $choices[15] = '15';
151 $choices[20] = '20';
152 $choices[25] = '25';
153 $choices[30] = '30';
154 $choices[40] = '40';
155 $choices[50] = '50';
156 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
530d2d72 157 $mform->addHelpButton('rssarticles', 'rssarticles', 'forum');
385247d9 158 $mform->hideIf('rssarticles', 'rsstype', 'eq', '0');
c9f2d347
RL
159 if (isset($CFG->forum_rssarticles)) {
160 $mform->setDefault('rssarticles', $CFG->forum_rssarticles);
161 }
535e0ab6 162 }
163
0f3bbfd4
AN
164 $mform->addElement('header', 'discussionlocking', get_string('discussionlockingheader', 'forum'));
165 $options = [
166 0 => get_string('discussionlockingdisabled', 'forum'),
167 1 * DAYSECS => get_string('numday', 'core', 1),
168 1 * WEEKSECS => get_string('numweek', 'core', 1),
169 2 * WEEKSECS => get_string('numweeks', 'core', 2),
170 30 * DAYSECS => get_string('nummonth', 'core', 1),
171 60 * DAYSECS => get_string('nummonths', 'core', 2),
172 90 * DAYSECS => get_string('nummonths', 'core', 3),
173 180 * DAYSECS => get_string('nummonths', 'core', 6),
174 1 * YEARSECS => get_string('numyear', 'core', 1),
175 ];
176 $mform->addElement('select', 'lockdiscussionafter', get_string('lockdiscussionafter', 'forum'), $options);
177 $mform->addHelpButton('lockdiscussionafter', 'lockdiscussionafter', 'forum');
178 $mform->disabledIf('lockdiscussionafter', 'type', 'eq', 'single');
179
a02c77dc 180//-------------------------------------------------------------------------------
807cf3d0 181 $mform->addElement('header', 'blockafterheader', get_string('blockafter', 'forum'));
2ee60b49 182 $options = array();
535e0ab6 183 $options[0] = get_string('blockperioddisabled','forum');
184 $options[60*60*24] = '1 '.get_string('day');
185 $options[60*60*24*2] = '2 '.get_string('days');
186 $options[60*60*24*3] = '3 '.get_string('days');
187 $options[60*60*24*4] = '4 '.get_string('days');
188 $options[60*60*24*5] = '5 '.get_string('days');
189 $options[60*60*24*6] = '6 '.get_string('days');
190 $options[60*60*24*7] = '1 '.get_string('week');
530d2d72
DM
191 $mform->addElement('select', 'blockperiod', get_string('blockperiod', 'forum'), $options);
192 $mform->addHelpButton('blockperiod', 'blockperiod', 'forum');
535e0ab6 193
2ee60b49 194 $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum'));
195 $mform->setType('blockafter', PARAM_INT);
196 $mform->setDefault('blockafter', '0');
197 $mform->addRule('blockafter', null, 'numeric', null, 'client');
530d2d72 198 $mform->addHelpButton('blockafter', 'blockafter', 'forum');
385247d9 199 $mform->hideIf('blockafter', 'blockperiod', 'eq', 0);
9c03bbaa 200
9c03bbaa 201 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
2ee60b49 202 $mform->setType('warnafter', PARAM_INT);
203 $mform->setDefault('warnafter', '0');
204 $mform->addRule('warnafter', null, 'numeric', null, 'client');
530d2d72 205 $mform->addHelpButton('warnafter', 'warnafter', 'forum');
385247d9 206 $mform->hideIf('warnafter', 'blockperiod', 'eq', 0);
9c03bbaa 207
103e7cba 208 $coursecontext = context_course::instance($COURSE->id);
d0d65b49 209 // To be removed (deprecated) with MDL-67526.
67fbfe8b 210 plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_forum');
103e7cba 211
a02c77dc 212//-------------------------------------------------------------------------------
16306628 213
92b229c5
AN
214 // Add the whole forum grading options.
215 $this->add_forum_grade_settings($mform, 'forum');
16306628 216
42f103be 217 $this->standard_coursemodule_elements();
a23f0aaf 218//-------------------------------------------------------------------------------
2ee60b49 219// buttons
a23f0aaf 220 $this->add_action_buttons();
92b229c5 221 }
535e0ab6 222
92b229c5
AN
223 /**
224 * Add the whole forum grade settings to the mform.
225 *
226 * @param \mform $mform
227 * @param string $itemname
228 */
229 private function add_forum_grade_settings($mform, string $itemname) {
230 global $COURSE;
231
232 $component = "mod_{$this->_modname}";
233 $defaultgradingvalue = 0;
234
235 $itemnumber = component_gradeitems::get_itemnumber_from_itemname($component, $itemname);
236 $gradefieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'grade');
237 $gradecatfieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'gradecat');
238 $gradepassfieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'gradepass');
77580567
SR
239 $sendstudentnotificationsfieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber,
240 'sendstudentnotifications');
92b229c5
AN
241
242 // The advancedgradingmethod is different in that it is suffixed with an area name... which is not the
243 // itemnumber.
244 $methodfieldname = "advancedgradingmethod_{$itemname}";
245
246 $headername = "{$gradefieldname}_header";
247 $mform->addElement('header', $headername, get_string("grade_{$itemname}_header", $component));
248
249 $isupdate = !empty($this->_cm);
250 $gradeoptions = [
251 'isupdate' => $isupdate,
252 'currentgrade' => false,
253 'hasgrades' => false,
254 'canrescale' => false,
255 'useratings' => false,
256 ];
257
258 if ($isupdate) {
259 $gradeitem = grade_item::fetch([
260 'itemtype' => 'mod',
261 'itemmodule' => $this->_cm->modname,
262 'iteminstance' => $this->_cm->instance,
263 'itemnumber' => $itemnumber,
264 'courseid' => $COURSE->id,
265 ]);
266 if ($gradeitem) {
267 $gradeoptions['currentgrade'] = $gradeitem->grademax;
268 $gradeoptions['currentgradetype'] = $gradeitem->gradetype;
269 $gradeoptions['currentscaleid'] = $gradeitem->scaleid;
270 $gradeoptions['hasgrades'] = $gradeitem->has_grades();
271 }
272 }
273 $mform->addElement(
274 'modgrade',
275 $gradefieldname,
276 get_string("{$gradefieldname}_title", $component),
277 $gradeoptions
278 );
279 $mform->addHelpButton($gradefieldname, 'modgrade', 'grades');
280 $mform->setDefault($gradefieldname, $defaultgradingvalue);
281
282 if (!empty($this->current->_advancedgradingdata['methods']) && !empty($this->current->_advancedgradingdata['areas'])) {
283 $areadata = $this->current->_advancedgradingdata['areas'][$itemname];
284 $mform->addElement(
285 'select',
286 $methodfieldname,
287 get_string('gradingmethod', 'core_grading'),
288 $this->current->_advancedgradingdata['methods']
289 );
290 $mform->addHelpButton($methodfieldname, 'gradingmethod', 'core_grading');
291 $mform->hideIf($methodfieldname, "{$gradefieldname}[modgrade_type]", 'eq', 'none');
292 }
293
294 // Grade category.
295 $mform->addElement(
296 'select',
297 $gradecatfieldname,
298 get_string('gradecategoryonmodform', 'grades'),
299 grade_get_categories_menu($COURSE->id, $this->_outcomesused)
300 );
301 $mform->addHelpButton($gradecatfieldname, 'gradecategoryonmodform', 'grades');
302 $mform->hideIf($gradecatfieldname, "{$gradefieldname}[modgrade_type]", 'eq', 'none');
303
304 // Grade to pass.
305 $mform->addElement('text', $gradepassfieldname, get_string('gradepass', 'grades'));
306 $mform->addHelpButton($gradepassfieldname, 'gradepass', 'grades');
307 $mform->setDefault($gradepassfieldname, '');
308 $mform->setType($gradepassfieldname, PARAM_RAW);
309 $mform->hideIf($gradepassfieldname, "{$gradefieldname}[modgrade_type]", 'eq', 'none');
77580567
SR
310
311 $mform->addElement(
312 'selectyesno',
313 $sendstudentnotificationsfieldname,
314 get_string('sendstudentnotificationsdefault', 'forum')
315 );
316 $mform->addHelpButton($sendstudentnotificationsfieldname, 'sendstudentnotificationsdefault', 'forum');
317 $mform->hideIf($sendstudentnotificationsfieldname, "{$gradefieldname}[modgrade_type]", 'eq', 'none');
2ee60b49 318 }
535e0ab6 319
4ba2221a 320 function definition_after_data() {
4050572d 321 parent::definition_after_data();
322 $mform =& $this->_form;
323 $type =& $mform->getElement('type');
324 $typevalue = $mform->getElementValue('type');
325
d24206d6 326 //we don't want to have these appear as possible selections in the form but
327 //we want the form to display them if they are set.
4ba2221a 328 if ($typevalue[0]=='news') {
d24206d6 329 $type->addOption(get_string('namenews', 'forum'), 'news');
530d2d72 330 $mform->addHelpButton('type', 'namenews', 'forum');
d24206d6 331 $type->freeze();
332 $type->setPersistantFreeze(true);
333 }
4ba2221a 334 if ($typevalue[0]=='social') {
d24206d6 335 $type->addOption(get_string('namesocial', 'forum'), 'social');
535e0ab6 336 $type->freeze();
337 $type->setPersistantFreeze(true);
338 }
2ee60b49 339 }
535e0ab6 340
ceea2d26
SR
341 public function validation($data, $files) {
342 $errors = parent::validation($data, $files);
343
344 if ($data['duedate'] && $data['cutoffdate']) {
345 if ($data['duedate'] > $data['cutoffdate']) {
346 $errors['cutoffdate'] = get_string('cutoffdatevalidation', 'forum');
347 }
348 }
349
92b229c5
AN
350 $this->validation_forum_grade($data, $files, $errors);
351
ceea2d26
SR
352 return $errors;
353 }
354
92b229c5
AN
355 /**
356 * Handle definition after data for grade settings.
357 *
358 * @param array $data
359 * @param array $files
360 * @param array $errors
361 */
362 private function validation_forum_grade(array $data, array $files, array $errors) {
363 global $COURSE;
364
365 $mform =& $this->_form;
366
367 $component = "mod_forum";
368 $itemname = 'forum';
369 $itemnumber = component_gradeitems::get_itemnumber_from_itemname($component, $itemname);
370 $gradefieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'grade');
371 $gradepassfieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'grade');
372
373 $gradeitem = grade_item::fetch([
374 'itemtype' => 'mod',
375 'itemmodule' => $data['modulename'],
376 'iteminstance' => $data['instance'],
377 'itemnumber' => $itemnumber,
378 'courseid' => $COURSE->id,
379 ]);
380
381 if ($mform->elementExists('cmidnumber') && $this->_cm) {
382 if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $gradeitem, $this->_cm)) {
383 $errors['cmidnumber'] = get_string('idnumbertaken');
384 }
385 }
386
387 // Check that the grade pass is a valid number.
388 $gradepassvalid = false;
389 if (isset($data[$gradepassfieldname])) {
390 if (unformat_float($data[$gradepassfieldname], true) === false) {
391 $errors[$gradepassfieldname] = get_string('err_numeric', 'form');
392 } else {
393 $gradepassvalid = true;
394 }
395 }
396
397 // Grade to pass: ensure that the grade to pass is valid for points and scales.
398 // If we are working with a scale, convert into a positive number for validation.
399 if ($gradepassvalid && isset($data[$gradepassfieldname]) && (!empty($data[$gradefieldname]))) {
400 $grade = $data[$gradefieldname];
401 if (unformat_float($data[$gradepassfieldname]) > $grade) {
402 $errors[$gradepassfieldname] = get_string('gradepassgreaterthangrade', 'grades', $grade);
403 }
404 }
405 }
406
4ba2221a 407 function data_preprocessing(&$default_values) {
55d95d90
AD
408 parent::data_preprocessing($default_values);
409
4e781c7b 410 // Set up the completion checkboxes which aren't part of standard data.
411 // We also make the default value (if you turn on the checkbox) for those
412 // numbers to be 1, this will not apply unless checkbox is ticked.
413 $default_values['completiondiscussionsenabled']=
414 !empty($default_values['completiondiscussions']) ? 1 : 0;
4ba2221a 415 if (empty($default_values['completiondiscussions'])) {
4e781c7b 416 $default_values['completiondiscussions']=1;
417 }
418 $default_values['completionrepliesenabled']=
419 !empty($default_values['completionreplies']) ? 1 : 0;
4ba2221a 420 if (empty($default_values['completionreplies'])) {
4e781c7b 421 $default_values['completionreplies']=1;
422 }
e44d71a6
JP
423 // Tick by default if Add mode or if completion posts settings is set to 1 or more.
424 if (empty($this->_instance) || !empty($default_values['completionposts'])) {
425 $default_values['completionpostsenabled'] = 1;
426 } else {
427 $default_values['completionpostsenabled'] = 0;
428 }
4ba2221a 429 if (empty($default_values['completionposts'])) {
4e781c7b 430 $default_values['completionposts']=1;
431 }
2ee60b49 432 }
e24b7f85 433
197b6d9e
JP
434 /**
435 * Add custom completion rules.
436 *
437 * @return array Array of string IDs of added items, empty array if none
438 */
439 public function add_completion_rules() {
4e781c7b 440 $mform =& $this->_form;
441
442 $group=array();
443 $group[] =& $mform->createElement('checkbox', 'completionpostsenabled', '', get_string('completionposts','forum'));
444 $group[] =& $mform->createElement('text', 'completionposts', '', array('size'=>3));
445 $mform->setType('completionposts',PARAM_INT);
446 $mform->addGroup($group, 'completionpostsgroup', get_string('completionpostsgroup','forum'), array(' '), false);
4e781c7b 447 $mform->disabledIf('completionposts','completionpostsenabled','notchecked');
448
449 $group=array();
450 $group[] =& $mform->createElement('checkbox', 'completiondiscussionsenabled', '', get_string('completiondiscussions','forum'));
451 $group[] =& $mform->createElement('text', 'completiondiscussions', '', array('size'=>3));
452 $mform->setType('completiondiscussions',PARAM_INT);
453 $mform->addGroup($group, 'completiondiscussionsgroup', get_string('completiondiscussionsgroup','forum'), array(' '), false);
4e781c7b 454 $mform->disabledIf('completiondiscussions','completiondiscussionsenabled','notchecked');
455
456 $group=array();
457 $group[] =& $mform->createElement('checkbox', 'completionrepliesenabled', '', get_string('completionreplies','forum'));
458 $group[] =& $mform->createElement('text', 'completionreplies', '', array('size'=>3));
459 $mform->setType('completionreplies',PARAM_INT);
460 $mform->addGroup($group, 'completionrepliesgroup', get_string('completionrepliesgroup','forum'), array(' '), false);
4e781c7b 461 $mform->disabledIf('completionreplies','completionrepliesenabled','notchecked');
462
463 return array('completiondiscussionsgroup','completionrepliesgroup','completionpostsgroup');
464 }
465
466 function completion_rule_enabled($data) {
467 return (!empty($data['completiondiscussionsenabled']) && $data['completiondiscussions']!=0) ||
468 (!empty($data['completionrepliesenabled']) && $data['completionreplies']!=0) ||
469 (!empty($data['completionpostsenabled']) && $data['completionposts']!=0);
470 }
471
92b229c5
AN
472 /**
473 * Return submitted data if properly submitted or returns NULL if validation fails or
474 * if there is no submitted data.
475 *
476 * Do not override this method, override data_postprocessing() instead.
477 *
478 * @return object submitted data; NULL if not valid or not submitted or cancelled
479 */
480 public function get_data() {
481 $data = parent::get_data();
482 if ($data) {
483 $itemname = 'forum';
484 $component = 'mod_forum';
485 $gradepassfieldname = component_gradeitems::get_field_name_for_itemname($component, $itemname, 'gradepass');
486
487 // Convert the grade pass value - we may be using a language which uses commas,
488 // rather than decimal points, in numbers. These need to be converted so that
489 // they can be added to the DB.
490 if (isset($data->{$gradepassfieldname})) {
491 $data->{$gradepassfieldname} = unformat_float($data->{$gradepassfieldname});
492 }
493 }
494
495 return $data;
496 }
497
06cdda46
MG
498 /**
499 * Allows module to modify the data returned by form get_data().
500 * This method is also called in the bulk activity completion form.
501 *
502 * Only available on moodleform_mod.
503 *
273d3106 504 * @param stdClass $data the form data to be modified.
06cdda46 505 */
273d3106 506 public function data_postprocessing($data) {
06cdda46 507 parent::data_postprocessing($data);
4e781c7b 508 // Turn off completion settings if the checkboxes aren't ticked
a9f5fc15 509 if (!empty($data->completionunlocked)) {
510 $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
511 if (empty($data->completiondiscussionsenabled) || !$autocompletion) {
512 $data->completiondiscussions = 0;
513 }
514 if (empty($data->completionrepliesenabled) || !$autocompletion) {
515 $data->completionreplies = 0;
516 }
517 if (empty($data->completionpostsenabled) || !$autocompletion) {
518 $data->completionposts = 0;
519 }
4e781c7b 520 }
4e781c7b 521 }
535e0ab6 522}