Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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 mod_bigbluebuttonbn\local\extension;
  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  abstract class mod_form_addons {
  29      /**
  30       * @var \MoodleQuickForm|null moodle form
  31       */
  32      protected $mform = null;
  33  
  34      /**
  35       * @var stdClass|null $bigbluebuttonbndata BigBlueButton data if any
  36       */
  37      protected $bigbluebuttonbndata = null;
  38  
  39      /**
  40       * @var string|null $suffix suffix for form elements
  41       */
  42      protected $suffix = null;
  43  
  44      /**
  45       * Constructor
  46       *
  47       * @param \MoodleQuickForm $mform
  48       * @param stdClass|null $bigbluebuttonbndata
  49       * @param string|null $suffix
  50       */
  51      public function __construct(\MoodleQuickForm &$mform, ?stdClass $bigbluebuttonbndata = null, string $suffix = null) {
  52          $this->mform = $mform;
  53          $this->bigbluebuttonbndata = $bigbluebuttonbndata;
  54          $this->suffix = $suffix;
  55      }
  56  
  57      /**
  58       * Add new form field definition
  59       */
  60      abstract public function add_fields(): void;
  61  
  62      /**
  63       * Validate form and returns an array of errors indexed by field name
  64       *
  65       * @param array $data
  66       * @param array $files
  67       * @return array
  68       */
  69      abstract public function validation(array $data, array $files): array;
  70  
  71      /**
  72       * Allows modules to modify the data returned by form get_data().
  73       * This method is also called in the bulk activity completion form.
  74       *
  75       * Only available on moodleform_mod.
  76       *
  77       * @param stdClass $data passed by reference
  78       */
  79      abstract public function data_postprocessing(\stdClass &$data): void;
  80  
  81      /**
  82       * Can be overridden to add custom completion rules if the module wishes
  83       * them. If overriding this, you should also override completion_rule_enabled.
  84       * <p>
  85       * Just add elements to the form as needed and return the list of IDs. The
  86       * system will call disabledIf and handle other behaviour for each returned
  87       * ID.
  88       *
  89       * @return string[] Array of string IDs of added items, empty array if none
  90       */
  91      abstract public function add_completion_rules(): array;
  92  
  93      /**
  94       * Called during validation. Override to indicate, based on the data, whether
  95       * a custom completion rule is enabled (selected).
  96       *
  97       * @param array $data Input data (not yet validated)
  98       * @return bool True if one or more rules is enabled, false if none are;
  99       *   default returns false
 100       */
 101      public function completion_rule_enabled(array $data): bool {
 102          return false;
 103      }
 104  
 105      /**
 106       * Form adjustments after setting data
 107       *
 108       * @return void
 109       */
 110      public function definition_after_data() {
 111          // Nothing for now.
 112      }
 113  }