Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * The definition of an item which can be exported.
  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  
  25  declare(strict_types=1);
  26  
  27  namespace core\content\export;
  28  
  29  use context;
  30  use core\content\export\exported_item;
  31  use core\content\export\zipwriter;
  32  
  33  /**
  34   * An object used to represent content which can be served.
  35   *
  36   * @copyright   2020 Andrew Nicols <andrew@nicols.co.uk>
  37   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  abstract class exportable_item {
  40  
  41      /** @var context The context associated with this exportable item */
  42      protected $context = null;
  43  
  44      /** @var string The component being exported */
  45      protected $component = null;
  46  
  47      /** @var string The name displayed to the user */
  48      protected $uservisiblename = null;
  49  
  50      /**
  51       * Create a new exportable_item instance.
  52       *
  53       * @param   context $context The context that this content belongs to
  54       * @param   string $component The component that this content relates to
  55       * @param   string $uservisiblename The name displayed in the export
  56       */
  57      public function __construct(context $context, string $component, string $uservisiblename) {
  58          $this->context = $context;
  59          $this->component = $component;
  60          $this->uservisiblename = $uservisiblename;
  61      }
  62  
  63      /**
  64       * Get the context that this exportable item is for.
  65       *
  66       * @return  context
  67       */
  68      public function get_context(): context {
  69          return $this->context;
  70      }
  71  
  72      /**
  73       * Get the component that this exportable item relates to.
  74       *
  75       * @return  string
  76       */
  77      public function get_component(): string {
  78          return $this->component;
  79      }
  80  
  81      /**
  82       * Get the user visible name for the exportable item.
  83       *
  84       * @return  string
  85       */
  86      public function get_user_visible_name(): string {
  87          return $this->uservisiblename;
  88      }
  89  
  90      /**
  91       * Add the content to the archive.
  92       *
  93       * @param   zipwriter $archive
  94       */
  95      abstract public function add_to_archive(zipwriter $archive): ?exported_item;
  96  }