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   * Forum data mapper.
  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\data_mappers\legacy;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use mod_forum\local\entities\forum as forum_entity;
  30  use stdClass;
  31  
  32  /**
  33   * Convert a forum entity into an stdClass.
  34   *
  35   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class forum {
  39      /**
  40       * Convert a list of forum entities into stdClasses.
  41       *
  42       * @param forum_entity[] $forums The forums to convert.
  43       * @return stdClass[]
  44       */
  45      public function to_legacy_objects(array $forums) : array {
  46          return array_map(function(forum_entity $forum) {
  47              return (object) [
  48                  'id' => $forum->get_id(),
  49                  'course' => $forum->get_course_id(),
  50                  'type' => $forum->get_type(),
  51                  'name' => $forum->get_name(),
  52                  'intro' => $forum->get_intro(),
  53                  'introformat' => $forum->get_intro_format(),
  54                  'assessed' => $forum->get_rating_aggregate(),
  55                  'assesstimestart' => $forum->get_assess_time_start(),
  56                  'assesstimefinish' => $forum->get_assess_time_finish(),
  57                  'scale' => $forum->get_scale(),
  58                  'grade_forum' => $forum->get_grade_for_forum(),
  59                  'grade_forum_notify' => $forum->should_notify_students_default_when_grade_for_forum(),
  60                  'maxbytes' => $forum->get_max_bytes(),
  61                  'maxattachments' => $forum->get_max_attachments(),
  62                  'forcesubscribe' => $forum->get_subscription_mode(),
  63                  'trackingtype' => $forum->get_tracking_type(),
  64                  'rsstype' => $forum->get_rss_type(),
  65                  'rssarticles' => $forum->get_rss_articles(),
  66                  'timemodified' => $forum->get_time_modified(),
  67                  'warnafter' => $forum->get_warn_after(),
  68                  'blockafter' => $forum->get_block_after(),
  69                  'blockperiod' => $forum->get_block_period(),
  70                  'completiondiscussions' => $forum->get_completion_discussions(),
  71                  'completionreplies' => $forum->get_completion_replies(),
  72                  'completionposts' => $forum->get_completion_posts(),
  73                  'displaywordcount' => $forum->should_display_word_count(),
  74                  'lockdiscussionafter' => $forum->get_lock_discussions_after(),
  75                  'duedate' => $forum->get_due_date(),
  76                  'cutoffdate' => $forum->get_cutoff_date()
  77              ];
  78          }, $forums);
  79      }
  80  
  81      /**
  82       * Convert a forum entity into an stdClass.
  83       *
  84       * @param forum_entity $forum The forum to convert.
  85       * @return stdClass
  86       */
  87      public function to_legacy_object(forum_entity $forum) : stdClass {
  88          return $this->to_legacy_objects([$forum])[0];
  89      }
  90  }