Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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   * Activity module exporter for the content API.
  19   *
  20   * @package     core
  21   * @copyright   2020 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core\content\export\exporters;
  25  
  26  use core\content\controllers\export\component_controller;
  27  
  28  /**
  29   * Activity module exporter for the content API.
  30   *
  31   * @copyright   2020 Andrew Nicols <andrew@nicols.co.uk>
  32   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  abstract class abstract_mod_exporter extends component_exporter {
  35  
  36      /** @var \cm_info The activity information for this course module */
  37      protected $cm;
  38  
  39      /**
  40       * Constructor for the general activity exporter.
  41       */
  42      public function __construct() {
  43          parent::__construct(...func_get_args());
  44  
  45          $coursecontext = $this->context->get_course_context();
  46          $modinfo = get_fast_modinfo($coursecontext->instanceid);
  47          $this->cm = $modinfo->get_cm($this->context->instanceid);
  48      }
  49  
  50      /**
  51       * Get the exportable items for the user in the specified context.
  52       *
  53       * For activities which allow users to submit their own content which is not visible to all users, for example
  54       * graded activities, the caller can request that this be either included, or excluded.
  55       *
  56       * @param   bool $includeuserdata Whether to include user data, in addition to shared content.
  57       * @return  exportable_item[]
  58       */
  59      abstract public function get_exportables(bool $includeuserdata = false): array;
  60  
  61      /**
  62       * Get the modname for the activity.
  63       *
  64       * @return  string
  65       */
  66      protected function get_modname(): string {
  67          return $this->cm->modname;
  68      }
  69  }