1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 namespace bbbext_simple\bigbluebuttonbn; 17 18 use stdClass; 19 20 /** 21 * A class for the main mod form extension 22 * 23 * @package mod_bigbluebuttonbn 24 * @copyright 2023 onwards, Blindside Networks Inc 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 * @author Laurent David (laurent@call-learning.fr) 27 */ 28 class mod_form_addons extends \mod_bigbluebuttonbn\local\extension\mod_form_addons { 29 /** 30 * Allows modules to modify the data returned by form get_data(). 31 * This method is also called in the bulk activity completion form. 32 * 33 * Only available on moodleform_mod. 34 * 35 * @param stdClass $data passed by reference 36 */ 37 public function data_postprocessing(\stdClass &$data): void { 38 // Nothing for now. 39 } 40 41 /** 42 * Allow module to modify the data at the pre-processing stage. 43 * 44 * This method is also called in the bulk activity completion form. 45 * 46 * @param array|null $defaultvalues 47 */ 48 public function data_preprocessing(?array &$defaultvalues): void { 49 // This is where we can add the data from the flexurl table to the data provided. 50 if (!empty($defaultvalues['id'])) { 51 global $DB; 52 $flexurlrecord = $DB->get_record('bbbext_simple', [ 53 'bigbluebuttonbnid' => $defaultvalues['id'], 54 ]); 55 if ($flexurlrecord) { 56 $defaultvalues['newfield'] = $flexurlrecord->newfield; 57 } 58 } 59 } 60 61 /** 62 * Can be overridden to add custom completion rules if the module wishes 63 * them. If overriding this, you should also override completion_rule_enabled. 64 * <p> 65 * Just add elements to the form as needed and return the list of IDs. The 66 * system will call disabledIf and handle other behaviour for each returned 67 * ID. 68 * 69 * @return array Array of string IDs of added items, empty array if none 70 */ 71 public function add_completion_rules(): array { 72 return []; 73 } 74 75 /** 76 * Called during validation. Override to indicate, based on the data, whether 77 * a custom completion rule is enabled (selected). 78 * 79 * @param array $data Input data (not yet validated) 80 * @return bool True if one or more rules is enabled, false if none are; 81 * default returns false 82 */ 83 public function completion_rule_enabled(array $data): bool { 84 return false; 85 } 86 87 /** 88 * Form adjustments after setting data 89 * 90 * @return void 91 */ 92 public function definition_after_data() { 93 // Nothing for now. 94 } 95 96 /** 97 * Add new form field definition 98 */ 99 public function add_fields(): void { 100 $this->mform->addElement('header', 'simple', get_string('pluginname', 'bbbext_simple')); 101 $this->mform->addElement('text', 'newfield', get_string('newfield', 'bbbext_simple')); 102 $this->mform->setType('newfield', PARAM_TEXT); 103 } 104 105 /** 106 * Validate form and returns an array of errors indexed by field name 107 * 108 * @param array $data 109 * @param array $files 110 * @return array 111 */ 112 public function validation(array $data, array $files): array { 113 $errors = []; 114 if (empty($data['newfield'])) { 115 $errors['newfield'] = get_string('newfielderror', 'bbbext_simple'); 116 } 117 return $errors; 118 } 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body