Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]
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 * @package mod_forum 20 * @copyright Jamie Pratt <me@jamiep.org> 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 if (!defined('MOODLE_INTERNAL')) { 25 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 26 } 27 28 require_once ($CFG->dirroot.'/course/moodleform_mod.php'); 29 30 use core_grades\component_gradeitems; 31 32 class mod_forum_mod_form extends moodleform_mod { 33 34 function definition() { 35 global $CFG, $COURSE, $DB; 36 37 $mform =& $this->_form; 38 39 //------------------------------------------------------------------------------- 40 $mform->addElement('header', 'general', get_string('general', 'form')); 41 42 $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64')); 43 if (!empty($CFG->formatstringstriptags)) { 44 $mform->setType('name', PARAM_TEXT); 45 } else { 46 $mform->setType('name', PARAM_CLEANHTML); 47 } 48 $mform->addRule('name', null, 'required', null, 'client'); 49 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 50 51 $this->standard_intro_elements(get_string('forumintro', 'forum')); 52 53 $forumtypes = forum_get_forum_types(); 54 core_collator::asort($forumtypes, core_collator::SORT_STRING); 55 $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forumtypes); 56 $mform->addHelpButton('type', 'forumtype', 'forum'); 57 $mform->setDefault('type', 'general'); 58 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 69 // Attachments and word count. 70 $mform->addElement('header', 'attachmentswordcounthdr', get_string('attachmentswordcount', 'forum')); 71 72 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, 0, $CFG->forum_maxbytes); 73 $choices[1] = get_string('uploadnotallowed'); 74 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices); 75 $mform->addHelpButton('maxbytes', 'maxattachmentsize', 'forum'); 76 $mform->setDefault('maxbytes', $CFG->forum_maxbytes); 77 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 ); 94 $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'forum'), $choices); 95 $mform->addHelpButton('maxattachments', 'maxattachments', 'forum'); 96 $mform->setDefault('maxattachments', $CFG->forum_maxattachments); 97 98 $mform->addElement('selectyesno', 'displaywordcount', get_string('displaywordcount', 'forum')); 99 $mform->addHelpButton('displaywordcount', 'displaywordcount', 'forum'); 100 $mform->setDefault('displaywordcount', 0); 101 102 // Subscription and tracking. 103 $mform->addElement('header', 'subscriptionandtrackinghdr', get_string('subscriptionandtracking', 'forum')); 104 105 $options = forum_get_subscriptionmode_options(); 106 $mform->addElement('select', 'forcesubscribe', get_string('subscriptionmode', 'forum'), $options); 107 $mform->addHelpButton('forcesubscribe', 'subscriptionmode', 'forum'); 108 if (isset($CFG->forum_subscription)) { 109 $defaultforumsubscription = $CFG->forum_subscription; 110 } else { 111 $defaultforumsubscription = FORUM_CHOOSESUBSCRIBE; 112 } 113 $mform->setDefault('forcesubscribe', $defaultforumsubscription); 114 115 $options = array(); 116 $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum'); 117 $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum'); 118 if ($CFG->forum_allowforcedreadtracking) { 119 $options[FORUM_TRACKING_FORCED] = get_string('trackingon', 'forum'); 120 } 121 $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options); 122 $mform->addHelpButton('trackingtype', 'trackingtype', 'forum'); 123 $default = $CFG->forum_trackingtype; 124 if ((!$CFG->forum_allowforcedreadtracking) && ($default == FORUM_TRACKING_FORCED)) { 125 $default = FORUM_TRACKING_OPTIONAL; 126 } 127 $mform->setDefault('trackingtype', $default); 128 129 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) { 130 //------------------------------------------------------------------------------- 131 $mform->addElement('header', 'rssheader', get_string('rss')); 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', 'forum'), $choices); 137 $mform->addHelpButton('rsstype', 'rsstype', 'forum'); 138 if (isset($CFG->forum_rsstype)) { 139 $mform->setDefault('rsstype', $CFG->forum_rsstype); 140 } 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); 157 $mform->addHelpButton('rssarticles', 'rssarticles', 'forum'); 158 $mform->hideIf('rssarticles', 'rsstype', 'eq', '0'); 159 if (isset($CFG->forum_rssarticles)) { 160 $mform->setDefault('rssarticles', $CFG->forum_rssarticles); 161 } 162 } 163 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 180 //------------------------------------------------------------------------------- 181 $mform->addElement('header', 'blockafterheader', get_string('blockafter', 'forum')); 182 $options = array(); 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'); 191 $mform->addElement('select', 'blockperiod', get_string('blockperiod', 'forum'), $options); 192 $mform->addHelpButton('blockperiod', 'blockperiod', 'forum'); 193 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'); 198 $mform->addHelpButton('blockafter', 'blockafter', 'forum'); 199 $mform->hideIf('blockafter', 'blockperiod', 'eq', 0); 200 201 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum')); 202 $mform->setType('warnafter', PARAM_INT); 203 $mform->setDefault('warnafter', '0'); 204 $mform->addRule('warnafter', null, 'numeric', null, 'client'); 205 $mform->addHelpButton('warnafter', 'warnafter', 'forum'); 206 $mform->hideIf('warnafter', 'blockperiod', 'eq', 0); 207 208 //------------------------------------------------------------------------------- 209 210 // Add the whole forum grading options. 211 $this->add_forum_grade_settings($mform, 'forum'); 212 213 $this->standard_coursemodule_elements(); 214 //------------------------------------------------------------------------------- 215 // buttons 216 $this->add_action_buttons(); 217 } 218 219 /** 220 * Add the whole forum grade settings to the mform. 221 * 222 * @param \mform $mform 223 * @param string $itemname 224 */ 225 private function add_forum_grade_settings($mform, string $itemname) { 226 global $COURSE; 227 228 $component = "mod_{$this->_modname}"; 229 $defaultgradingvalue = 0; 230 231 $itemnumber = component_gradeitems::get_itemnumber_from_itemname($component, $itemname); 232 $gradefieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'grade'); 233 $gradecatfieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'gradecat'); 234 $gradepassfieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'gradepass'); 235 $sendstudentnotificationsfieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 236 'sendstudentnotifications'); 237 238 // The advancedgradingmethod is different in that it is suffixed with an area name... which is not the 239 // itemnumber. 240 $methodfieldname = "advancedgradingmethod_{$itemname}"; 241 242 $headername = "{$gradefieldname}_header"; 243 $mform->addElement('header', $headername, get_string("grade_{$itemname}_header", $component)); 244 245 $isupdate = !empty($this->_cm); 246 $gradeoptions = [ 247 'isupdate' => $isupdate, 248 'currentgrade' => false, 249 'hasgrades' => false, 250 'canrescale' => false, 251 'useratings' => false, 252 ]; 253 254 if ($isupdate) { 255 $gradeitem = grade_item::fetch([ 256 'itemtype' => 'mod', 257 'itemmodule' => $this->_cm->modname, 258 'iteminstance' => $this->_cm->instance, 259 'itemnumber' => $itemnumber, 260 'courseid' => $COURSE->id, 261 ]); 262 if ($gradeitem) { 263 $gradeoptions['currentgrade'] = $gradeitem->grademax; 264 $gradeoptions['currentgradetype'] = $gradeitem->gradetype; 265 $gradeoptions['currentscaleid'] = $gradeitem->scaleid; 266 $gradeoptions['hasgrades'] = $gradeitem->has_grades(); 267 } 268 } 269 $mform->addElement( 270 'modgrade', 271 $gradefieldname, 272 get_string("{$gradefieldname}_title", $component), 273 $gradeoptions 274 ); 275 $mform->addHelpButton($gradefieldname, 'modgrade', 'grades'); 276 $mform->setDefault($gradefieldname, $defaultgradingvalue); 277 278 if (!empty($this->current->_advancedgradingdata['methods']) && !empty($this->current->_advancedgradingdata['areas'])) { 279 $areadata = $this->current->_advancedgradingdata['areas'][$itemname]; 280 $mform->addElement( 281 'select', 282 $methodfieldname, 283 get_string('gradingmethod', 'core_grading'), 284 $this->current->_advancedgradingdata['methods'] 285 ); 286 $mform->addHelpButton($methodfieldname, 'gradingmethod', 'core_grading'); 287 $mform->hideIf($methodfieldname, "{$gradefieldname}[modgrade_type]", 'eq', 'none'); 288 } 289 290 // Grade category. 291 $mform->addElement( 292 'select', 293 $gradecatfieldname, 294 get_string('gradecategoryonmodform', 'grades'), 295 grade_get_categories_menu($COURSE->id, $this->_outcomesused) 296 ); 297 $mform->addHelpButton($gradecatfieldname, 'gradecategoryonmodform', 'grades'); 298 $mform->hideIf($gradecatfieldname, "{$gradefieldname}[modgrade_type]", 'eq', 'none'); 299 300 // Grade to pass. 301 $mform->addElement('text', $gradepassfieldname, get_string('gradepass', 'grades')); 302 $mform->addHelpButton($gradepassfieldname, 'gradepass', 'grades'); 303 $mform->setDefault($gradepassfieldname, ''); 304 $mform->setType($gradepassfieldname, PARAM_RAW); 305 $mform->hideIf($gradepassfieldname, "{$gradefieldname}[modgrade_type]", 'eq', 'none'); 306 307 $mform->addElement( 308 'selectyesno', 309 $sendstudentnotificationsfieldname, 310 get_string('sendstudentnotificationsdefault', 'forum') 311 ); 312 $mform->addHelpButton($sendstudentnotificationsfieldname, 'sendstudentnotificationsdefault', 'forum'); 313 $mform->hideIf($sendstudentnotificationsfieldname, "{$gradefieldname}[modgrade_type]", 'eq', 'none'); 314 } 315 316 function definition_after_data() { 317 parent::definition_after_data(); 318 $mform =& $this->_form; 319 $type =& $mform->getElement('type'); 320 $typevalue = $mform->getElementValue('type'); 321 322 //we don't want to have these appear as possible selections in the form but 323 //we want the form to display them if they are set. 324 if ($typevalue[0]=='news') { 325 $type->addOption(get_string('namenews', 'forum'), 'news'); 326 $mform->addHelpButton('type', 'namenews', 'forum'); 327 $type->freeze(); 328 $type->setPersistantFreeze(true); 329 } 330 if ($typevalue[0]=='social') { 331 $type->addOption(get_string('namesocial', 'forum'), 'social'); 332 $type->freeze(); 333 $type->setPersistantFreeze(true); 334 } 335 } 336 337 public function validation($data, $files) { 338 $errors = parent::validation($data, $files); 339 340 if ($data['type'] === 'single' && $data['groupmode'] == SEPARATEGROUPS) { 341 $errors['type'] = get_string('cannotusesingletopicandseperategroups', 'forum'); 342 $errors['groupmode'] = get_string('cannotuseseperategroupsandsingletopic', 'forum'); 343 } 344 345 if ($data['duedate'] && $data['cutoffdate']) { 346 if ($data['duedate'] > $data['cutoffdate']) { 347 $errors['cutoffdate'] = get_string('cutoffdatevalidation', 'forum'); 348 } 349 } 350 351 $this->validation_forum_grade($data, $files, $errors); 352 353 return $errors; 354 } 355 356 /** 357 * Handle definition after data for grade settings. 358 * 359 * @param array $data 360 * @param array $files 361 * @param array $errors 362 */ 363 private function validation_forum_grade(array $data, array $files, array $errors) { 364 global $COURSE; 365 366 $mform =& $this->_form; 367 368 $component = "mod_forum"; 369 $itemname = 'forum'; 370 $itemnumber = component_gradeitems::get_itemnumber_from_itemname($component, $itemname); 371 $gradefieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'grade'); 372 $gradepassfieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'grade'); 373 374 $gradeitem = grade_item::fetch([ 375 'itemtype' => 'mod', 376 'itemmodule' => $data['modulename'], 377 'iteminstance' => $data['instance'], 378 'itemnumber' => $itemnumber, 379 'courseid' => $COURSE->id, 380 ]); 381 382 if ($mform->elementExists('cmidnumber') && $this->_cm) { 383 if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $gradeitem, $this->_cm)) { 384 $errors['cmidnumber'] = get_string('idnumbertaken'); 385 } 386 } 387 388 // Check that the grade pass is a valid number. 389 $gradepassvalid = false; 390 if (isset($data[$gradepassfieldname])) { 391 if (unformat_float($data[$gradepassfieldname], true) === false) { 392 $errors[$gradepassfieldname] = get_string('err_numeric', 'form'); 393 } else { 394 $gradepassvalid = true; 395 } 396 } 397 398 // Grade to pass: ensure that the grade to pass is valid for points and scales. 399 // If we are working with a scale, convert into a positive number for validation. 400 if ($gradepassvalid && isset($data[$gradepassfieldname]) && (!empty($data[$gradefieldname]))) { 401 $grade = $data[$gradefieldname]; 402 if (unformat_float($data[$gradepassfieldname]) > $grade) { 403 $errors[$gradepassfieldname] = get_string('gradepassgreaterthangrade', 'grades', $grade); 404 } 405 } 406 } 407 408 public function data_preprocessing(&$defaultvalues) { 409 parent::data_preprocessing($defaultvalues); 410 411 $suffix = $this->get_suffix(); 412 $completiondiscussionsenabledel = 'completiondiscussionsenabled' . $suffix; 413 $completiondiscussionsel = 'completiondiscussions' . $suffix; 414 $completionrepliesenabledel = 'completionrepliesenabled' . $suffix; 415 $completionrepliesel = 'completionreplies' . $suffix; 416 $completionpostsel = 'completionposts' . $suffix; 417 $completionpostsenabledel = 'completionpostsenabled' . $suffix; 418 419 // Set up the completion checkboxes which aren't part of standard data. 420 // We also make the default value (if you turn on the checkbox) for those 421 // numbers to be 1, this will not apply unless checkbox is ticked. 422 $defaultvalues[$completiondiscussionsenabledel] = !empty($defaultvalues[$completiondiscussionsel]) ? 1 : 0; 423 if (empty($defaultvalues[$completiondiscussionsel])) { 424 $defaultvalues[$completiondiscussionsel] = 1; 425 } 426 $defaultvalues[$completionrepliesenabledel] = !empty($defaultvalues[$completionrepliesel]) ? 1 : 0; 427 if (empty($defaultvalues[$completionrepliesel])) { 428 $defaultvalues[$completionrepliesel] = 1; 429 } 430 // Tick by default if Add mode or if completion posts settings is set to 1 or more. 431 if (empty($this->_instance) || !empty($defaultvalues[$completionpostsel])) { 432 $defaultvalues[$completionpostsenabledel] = 1; 433 } else { 434 $defaultvalues[$completionpostsenabledel] = 0; 435 } 436 if (empty($defaultvalues[$completionpostsel])) { 437 $defaultvalues[$completionpostsel] = 1; 438 } 439 } 440 441 /** 442 * Add custom completion rules. 443 * 444 * @return array Array of string IDs of added items, empty array if none 445 */ 446 public function add_completion_rules() { 447 $mform = $this->_form; 448 449 $suffix = $this->get_suffix(); 450 451 $group = []; 452 $completionpostsenabledel = 'completionpostsenabled' . $suffix; 453 $group[] =& $mform->createElement('checkbox', $completionpostsenabledel, '', get_string('completionposts', 'forum')); 454 $completionpostsel = 'completionposts' . $suffix; 455 $group[] =& $mform->createElement('text', $completionpostsel, '', ['size' => 3]); 456 $mform->setType($completionpostsel, PARAM_INT); 457 $completionpostsgroupel = 'completionpostsgroup' . $suffix; 458 $mform->addGroup($group, $completionpostsgroupel, '', ' ', false); 459 $mform->hideIf($completionpostsel, $completionpostsenabledel, 'notchecked'); 460 461 $group = []; 462 $completiondiscussionsenabledel = 'completiondiscussionsenabled' . $suffix; 463 $group[] =& $mform->createElement( 464 'checkbox', 465 $completiondiscussionsenabledel, 466 '', 467 get_string('completiondiscussions', 'forum') 468 ); 469 $completiondiscussionsel = 'completiondiscussions' . $suffix; 470 $group[] =& $mform->createElement('text', $completiondiscussionsel, '', ['size' => 3]); 471 $mform->setType($completiondiscussionsel, PARAM_INT); 472 $completiondiscussionsgroupel = 'completiondiscussionsgroup' . $suffix; 473 $mform->addGroup($group, $completiondiscussionsgroupel, '', ' ', false); 474 $mform->hideIf($completiondiscussionsel, $completiondiscussionsenabledel, 'notchecked'); 475 476 $group = []; 477 $completionrepliesenabledel = 'completionrepliesenabled' . $suffix; 478 $group[] =& $mform->createElement('checkbox', $completionrepliesenabledel, '', get_string('completionreplies', 'forum')); 479 $completionrepliesel = 'completionreplies' . $suffix; 480 $group[] =& $mform->createElement('text', $completionrepliesel, '', ['size' => 3]); 481 $mform->setType($completionrepliesel, PARAM_INT); 482 $completionrepliesgroupel = 'completionrepliesgroup' . $suffix; 483 $mform->addGroup($group, $completionrepliesgroupel, '', ' ', false); 484 $mform->hideIf($completionrepliesel, $completionrepliesenabledel, 'notchecked'); 485 486 return [$completiondiscussionsgroupel, $completionrepliesgroupel, $completionpostsgroupel]; 487 } 488 489 public function completion_rule_enabled($data) { 490 $suffix = $this->get_suffix(); 491 return (!empty($data['completiondiscussionsenabled' . $suffix]) && $data['completiondiscussions' . $suffix] != 0) || 492 (!empty($data['completionrepliesenabled' . $suffix]) && $data['completionreplies' . $suffix] != 0) || 493 (!empty($data['completionpostsenabled' . $suffix]) && $data['completionposts' . $suffix] != 0); 494 } 495 496 /** 497 * Return submitted data if properly submitted or returns NULL if validation fails or 498 * if there is no submitted data. 499 * 500 * Do not override this method, override data_postprocessing() instead. 501 * 502 * @return object submitted data; NULL if not valid or not submitted or cancelled 503 */ 504 public function get_data() { 505 $data = parent::get_data(); 506 if ($data) { 507 $itemname = 'forum'; 508 $component = 'mod_forum'; 509 $gradepassfieldname = component_gradeitems::get_field_name_for_itemname($component, $itemname, 'gradepass'); 510 511 // Convert the grade pass value - we may be using a language which uses commas, 512 // rather than decimal points, in numbers. These need to be converted so that 513 // they can be added to the DB. 514 if (isset($data->{$gradepassfieldname})) { 515 $data->{$gradepassfieldname} = unformat_float($data->{$gradepassfieldname}); 516 } 517 } 518 519 return $data; 520 } 521 522 /** 523 * Allows module to modify the data returned by form get_data(). 524 * This method is also called in the bulk activity completion form. 525 * 526 * Only available on moodleform_mod. 527 * 528 * @param stdClass $data the form data to be modified. 529 */ 530 public function data_postprocessing($data) { 531 parent::data_postprocessing($data); 532 // Turn off completion settings if the checkboxes aren't ticked. 533 if (!empty($data->completionunlocked)) { 534 $suffix = $this->get_suffix(); 535 $completion = $data->{'completion' . $suffix}; 536 $autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC; 537 if (empty($data->{'completiondiscussionsenabled' . $suffix}) || !$autocompletion) { 538 $data->{'completiondiscussions' . $suffix} = 0; 539 } 540 if (empty($data->{'completionrepliesenabled' . $suffix}) || !$autocompletion) { 541 $data->{'completionreplies' . $suffix} = 0; 542 } 543 if (empty($data->{'completionpostsenabled' . $suffix}) || !$autocompletion) { 544 $data->{'completionposts' . $suffix} = 0; 545 } 546 } 547 } 548 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body