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  /**
  18   * Vault 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\factories\entity as entity_factory;
  30  use mod_forum\local\vaults\author as author_vault;
  31  use mod_forum\local\vaults\discussion as discussion_vault;
  32  use mod_forum\local\vaults\discussion_list as discussion_list_vault;
  33  use mod_forum\local\vaults\forum as forum_vault;
  34  use mod_forum\local\vaults\post as post_vault;
  35  use mod_forum\local\vaults\post_attachment as post_attachment_vault;
  36  use mod_forum\local\vaults\post_read_receipt_collection as post_read_receipt_collection_vault;
  37  use file_storage;
  38  use moodle_database;
  39  
  40  /**
  41   * Vault factory.
  42   *
  43   * See:
  44   * https://designpatternsphp.readthedocs.io/en/latest/Creational/SimpleFactory/README.html
  45   *
  46   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  47   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  48   */
  49  class vault {
  50      /** @var entity_factory $entityfactory Entity factory */
  51      private $entityfactory;
  52      /** @var legacy_data_mapper $legacymapper Entity factory */
  53      private $legacymapper;
  54      /** @var moodle_database $db A moodle database */
  55      private $db;
  56      /** @var file_storage $filestorage A file storage instance */
  57      private $filestorage;
  58  
  59      /**
  60       * Constructor.
  61       *
  62       * @param moodle_database $db A moodle database
  63       * @param entity_factory $entityfactory Entity factory
  64       * @param file_storage $filestorage A file storage instance
  65       * @param legacy_data_mapper $legacyfactory Datamapper
  66       */
  67      public function __construct(moodle_database $db, entity_factory $entityfactory,
  68          file_storage $filestorage, legacy_data_mapper $legacyfactory) {
  69          $this->db = $db;
  70          $this->entityfactory = $entityfactory;
  71          $this->filestorage = $filestorage;
  72          $this->legacymapper = $legacyfactory;
  73      }
  74  
  75      /**
  76       * Create a forum vault.
  77       *
  78       * @return forum_vault
  79       */
  80      public function get_forum_vault() : forum_vault {
  81          return new forum_vault(
  82              $this->db,
  83              $this->entityfactory,
  84              $this->legacymapper->get_legacy_data_mapper_for_vault('forum')
  85          );
  86      }
  87  
  88      /**
  89       * Create a discussion vault.
  90       *
  91       * @return discussion_vault
  92       */
  93      public function get_discussion_vault() : discussion_vault {
  94          return new discussion_vault(
  95              $this->db,
  96              $this->entityfactory,
  97              $this->legacymapper->get_legacy_data_mapper_for_vault('discussion')
  98          );
  99      }
 100  
 101      /**
 102       * Create a discussion list vault.
 103       *
 104       * @return discussion_list_vault
 105       */
 106      public function get_discussions_in_forum_vault() : discussion_list_vault {
 107          return new discussion_list_vault(
 108              $this->db,
 109              $this->entityfactory,
 110              $this->legacymapper->get_legacy_data_mapper_for_vault('discussion')
 111          );
 112      }
 113  
 114      /**
 115       * Create a post vault.
 116       *
 117       * @return post_vault
 118       */
 119      public function get_post_vault() : post_vault {
 120          return new post_vault(
 121              $this->db,
 122              $this->entityfactory,
 123              $this->legacymapper->get_legacy_data_mapper_for_vault('post')
 124          );
 125      }
 126  
 127      /**
 128       * Create an author vault.
 129       *
 130       * @return author_vault
 131       */
 132      public function get_author_vault() : author_vault {
 133          return new author_vault(
 134              $this->db,
 135              $this->entityfactory,
 136              $this->legacymapper->get_legacy_data_mapper_for_vault('author')
 137          );
 138      }
 139  
 140      /**
 141       * Create a post read receipt collection vault.
 142       *
 143       * @return post_read_receipt_collection_vault
 144       */
 145      public function get_post_read_receipt_collection_vault() : post_read_receipt_collection_vault {
 146          return new post_read_receipt_collection_vault(
 147              $this->db,
 148              $this->entityfactory,
 149              $this->legacymapper->get_legacy_data_mapper_for_vault('post')
 150          );
 151      }
 152  
 153      /**
 154       * Create a post attachment vault.
 155       *
 156       * @return post_attachment_vault
 157       */
 158      public function get_post_attachment_vault() : post_attachment_vault {
 159          return new post_attachment_vault(
 160              $this->filestorage
 161          );
 162      }
 163  }