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  declare(strict_types=1);
  18  
  19  namespace core_reportbuilder\external;
  20  
  21  use core_user;
  22  use renderer_base;
  23  use core\external\persistent_exporter;
  24  use core_reportbuilder\datasource;
  25  use core_reportbuilder\manager;
  26  use core_reportbuilder\local\models\report;
  27  use core_user\external\user_summary_exporter;
  28  
  29  /**
  30   * Custom report details exporter class
  31   *
  32   * @package     core_reportbuilder
  33   * @copyright   2022 Paul Holden <paulh@moodle.com>
  34   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class custom_report_details_exporter extends persistent_exporter {
  37  
  38      /** @var report The persistent object we will export. */
  39      protected $persistent = null;
  40  
  41      /**
  42       * Return the name of the class we are exporting
  43       *
  44       * @return string
  45       */
  46      protected static function define_class(): string {
  47          return report::class;
  48      }
  49  
  50      /**
  51       * Return a list of additional properties used only for display
  52       *
  53       * @return array
  54       */
  55      protected static function define_other_properties(): array {
  56          return [
  57              'sourcename' => [
  58                  'type' => PARAM_RAW,
  59                  'null' => NULL_ALLOWED,
  60              ],
  61              'modifiedby' => ['type' => user_summary_exporter::read_properties_definition()],
  62          ];
  63      }
  64  
  65      /**
  66       * Get additional values to inject while exporting
  67       *
  68       * @param renderer_base $output
  69       * @return array
  70       */
  71      protected function get_other_values(renderer_base $output): array {
  72          $source = $this->persistent->get('source');
  73          $usermodified = core_user::get_user($this->persistent->get('usermodified'));
  74  
  75          return [
  76              'sourcename' => manager::report_source_exists($source, datasource::class) ? $source::get_name() : null,
  77              'modifiedby' => (new user_summary_exporter($usermodified))->export($output),
  78          ];
  79      }
  80  }