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  
  17  namespace tool_mfa\local\form;
  18  
  19  use tool_mfa\plugininfo\factor;
  20  
  21  /**
  22   * MFA login form
  23   *
  24   * @package     tool_mfa
  25   * @author      Mikhail Golenkov <golenkovm@gmail.com>
  26   * @copyright   Catalyst IT
  27   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  class global_form_manager {
  30      /** @var array factors to call hooks upon. */
  31      private $activefactors;
  32  
  33      /**
  34       * Create an instance of this class.
  35       */
  36      public function __construct() {
  37          $this->activefactors = factor::get_active_user_factor_types();
  38      }
  39  
  40      /**
  41       * Hook point for global auth form action hooks.
  42       *
  43       * @param \MoodleQuickForm $mform Form to inject global elements into.
  44       * @return void
  45       */
  46      public function definition(\MoodleQuickForm &$mform): void {
  47          foreach ($this->activefactors as $factor) {
  48              $factor->global_definition($mform);
  49          }
  50      }
  51  
  52      /**
  53       * Hook point for global auth form action hooks.
  54       *
  55       * @param \MoodleQuickForm $mform Form to inject global elements into.
  56       * @return void
  57       */
  58      public function definition_after_data(\MoodleQuickForm &$mform): void {
  59          foreach ($this->activefactors as $factor) {
  60              $factor->global_definition_after_data($mform);
  61          }
  62      }
  63  
  64      /**
  65       * Hook point for global auth form action hooks.
  66       *
  67       * @param array $data Data from the form.
  68       * @param array $files Files form the form.
  69       * @return array of errors from validation.
  70       */
  71      public function validation(array $data, array $files): array {
  72          $errors = [];
  73          foreach ($this->activefactors as $factor) {
  74              $errors = array_merge($errors, $factor->global_validation($data, $files));
  75          }
  76          return $errors;
  77      }
  78  
  79      /**
  80       * Hook point for global auth form submission hooks.
  81       *
  82       * @param \stdClass $data Data from the form.
  83       * @return void
  84       */
  85      public function submit(\stdClass $data): void {
  86          foreach ($this->activefactors as $factor) {
  87              $factor->global_submit($data);
  88          }
  89      }
  90  }