Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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   * Builder 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\builders\exported_posts as exported_posts_builder;
  30  use mod_forum\local\builders\exported_discussion_summaries as exported_discussion_summaries_builder;
  31  use mod_forum\local\builders\exported_discussion as exported_discussion_builder;
  32  use mod_forum\local\factories\vault as vault_factory;
  33  use mod_forum\local\factories\legacy_data_mapper as legacy_data_mapper_factory;
  34  use mod_forum\local\factories\exporter as exporter_factory;
  35  use mod_forum\local\factories\manager as manager_factory;
  36  use renderer_base;
  37  
  38  /**
  39   * Builder factory to construct any builders for forum.
  40   *
  41   * See:
  42   * https://designpatternsphp.readthedocs.io/en/latest/Creational/SimpleFactory/README.html
  43   *
  44   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  45   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  46   */
  47  class builder {
  48      /** @var legacy_data_mapper_factory $legacydatamapperfactory Legacy data mapper factory */
  49      private $legacydatamapperfactory;
  50      /** @var exporter_factory $exporterfactory Exporter factory */
  51      private $exporterfactory;
  52      /** @var vault_factory $vaultfactory Vault factory */
  53      private $vaultfactory;
  54      /** @var manager_factory $managerfactory Manager factory */
  55      private $managerfactory;
  56      /** @var renderer_base $rendererbase Renderer base */
  57      private $rendererbase;
  58  
  59      /**
  60       * Constructor.
  61       *
  62       * @param legacy_data_mapper_factory $legacydatamapperfactory Legacy data mapper factory
  63       * @param exporter_factory $exporterfactory Exporter factory
  64       * @param vault_factory $vaultfactory Vault factory
  65       * @param manager_factory $managerfactory Manager factory
  66       * @param renderer_base $rendererbase Renderer base
  67       */
  68      public function __construct(
  69          legacy_data_mapper_factory $legacydatamapperfactory,
  70          exporter_factory $exporterfactory,
  71          vault_factory $vaultfactory,
  72          manager_factory $managerfactory,
  73          renderer_base $rendererbase
  74      ) {
  75          $this->legacydatamapperfactory = $legacydatamapperfactory;
  76          $this->exporterfactory = $exporterfactory;
  77          $this->vaultfactory = $vaultfactory;
  78          $this->managerfactory = $managerfactory;
  79          $this->rendererbase = $rendererbase;
  80      }
  81  
  82  
  83      /**
  84       * Get an instance of the exported posts builder.
  85       *
  86       * @return exported_posts_builder
  87       */
  88      public function get_exported_posts_builder() : exported_posts_builder {
  89          return new exported_posts_builder(
  90              $this->rendererbase,
  91              $this->legacydatamapperfactory,
  92              $this->exporterfactory,
  93              $this->vaultfactory,
  94              $this->managerfactory->get_rating_manager()
  95          );
  96      }
  97  
  98      /**
  99       * Get an instance of the exported discussion summaries builder.
 100       *
 101       * @return exported_discussion_summaries_builder
 102       */
 103      public function get_exported_discussion_summaries_builder() : exported_discussion_summaries_builder {
 104          return new exported_discussion_summaries_builder(
 105              $this->rendererbase,
 106              $this->legacydatamapperfactory,
 107              $this->exporterfactory,
 108              $this->vaultfactory,
 109              $this->managerfactory
 110          );
 111      }
 112  
 113      /**
 114       * Get an instance of the exported discussion builder.
 115       *
 116       * @return exported_discussion_summaries_builder
 117       */
 118      public function get_exported_discussion_builder() : exported_discussion_builder {
 119          return new exported_discussion_builder(
 120              $this->rendererbase,
 121              $this->legacydatamapperfactory,
 122              $this->exporterfactory,
 123              $this->vaultfactory,
 124              $this->managerfactory->get_rating_manager()
 125          );
 126      }
 127  }