Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.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   * Contains the import_handler_info class.
  18   *
  19   * @package tool_moodlenet
  20   * @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com>
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  namespace tool_moodlenet\local;
  25  
  26  /**
  27   * The import_handler_info class.
  28   *
  29   * An import_handler_info object represent an resource import handler for a particular module.
  30   *
  31   * @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com>
  32   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class import_handler_info {
  35  
  36      /** @var string $modulename the name of the module. */
  37      protected $modulename;
  38  
  39      /** @var string $description the description. */
  40      protected $description;
  41  
  42      /** @var import_strategy $importstrategy the strategy which will be used to import resources handled by this handler */
  43      protected $importstrategy;
  44  
  45      /**
  46       * The import_handler_info constructor.
  47       *
  48       * @param string $modulename the name of the module handling the file extension. E.g. 'label'.
  49       * @param string $description A description of how the module handles files of this extension type.
  50       * @param import_strategy $strategy the strategy which will be used to import the resource.
  51       * @throws \coding_exception
  52       */
  53      public function __construct(string $modulename, string $description, import_strategy $strategy) {
  54          if (empty($modulename)) {
  55              throw new \coding_exception("Module name cannot be empty.");
  56          }
  57          if (empty($description)) {
  58              throw new \coding_exception("Description cannot be empty.");
  59          }
  60          $this->modulename = $modulename;
  61          $this->description = $description;
  62          $this->importstrategy = $strategy;
  63      }
  64  
  65      /**
  66       * Get the name of the module.
  67       *
  68       * @return string the module name, e.g. 'label'.
  69       */
  70      public function get_module_name(): string {
  71          return $this->modulename;
  72      }
  73  
  74      /**
  75       * Get a human readable, localised description of how the file is handled by the module.
  76       *
  77       * @return string the localised description.
  78       */
  79      public function get_description(): string {
  80          return $this->description;
  81      }
  82  
  83      /**
  84       * Get the import strategy used by this handler.
  85       *
  86       * @return import_strategy the import strategy object.
  87       */
  88      public function get_strategy(): import_strategy {
  89          return $this->importstrategy;
  90      }
  91  }