Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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  /**
  18   * Legacy data mapper factory.
  19   *
  20   * @package    mod_forum
  21   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace mod_forum\local\factories;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use mod_forum\local\data_mappers\legacy\author as author_data_mapper;
  30  use mod_forum\local\data_mappers\legacy\discussion as discussion_data_mapper;
  31  use mod_forum\local\data_mappers\legacy\forum as forum_data_mapper;
  32  use mod_forum\local\data_mappers\legacy\post as post_data_mapper;
  33  use mod_forum\local\entities\forum;
  34  
  35  /**
  36   * Legacy data mapper factory.
  37   *
  38   * See:
  39   * https://designpatternsphp.readthedocs.io/en/latest/Creational/SimpleFactory/README.html
  40   *
  41   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  42   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class legacy_data_mapper {
  45      /**
  46       * Create a legacy forum data mapper.
  47       *
  48       * @return forum_data_mapper
  49       */
  50      public function get_forum_data_mapper() : forum_data_mapper {
  51          return new forum_data_mapper();
  52      }
  53  
  54      /**
  55       * Create a legacy discussion data mapper.
  56       *
  57       * @return discussion_data_mapper
  58       */
  59      public function get_discussion_data_mapper() : discussion_data_mapper {
  60          return new discussion_data_mapper();
  61      }
  62  
  63      /**
  64       * Create a legacy post data mapper.
  65       *
  66       * @return post_data_mapper
  67       */
  68      public function get_post_data_mapper() : post_data_mapper {
  69          return new post_data_mapper();
  70      }
  71  
  72      /**
  73       * Create a legacy author data mapper.
  74       *
  75       * @return author_data_mapper
  76       */
  77      public function get_author_data_mapper() : author_data_mapper {
  78          return new author_data_mapper();
  79      }
  80  
  81      /**
  82       * Get the corresponding entity based on the supplied value
  83       *
  84       * @param string $entity
  85       * @return author_data_mapper|discussion_data_mapper|forum_data_mapper|post_data_mapper
  86       */
  87      public function get_legacy_data_mapper_for_vault($entity) {
  88          switch($entity) {
  89              case 'forum':
  90                  return $this->get_forum_data_mapper();
  91              case 'discussion':
  92                  return $this->get_discussion_data_mapper();
  93              case 'post':
  94                  return $this->get_post_data_mapper();
  95              case 'author':
  96                  return $this->get_author_data_mapper();
  97          }
  98      }
  99  }