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.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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  declare(strict_types=1);
  18  
  19  namespace core_reportbuilder\external;
  20  
  21  use core_reportbuilder\form\card_view;
  22  use renderer_base;
  23  use core\external\exporter;
  24  use core_reportbuilder\local\report\base;
  25  
  26  /**
  27   * Custom report card view exporter class
  28   *
  29   * @package     core_reportbuilder
  30   * @copyright   2021 Mikel Martín <mikel@moodle.com>
  31   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class custom_report_card_view_exporter extends exporter {
  34  
  35      /**
  36       * Return a list of objects that are related to the exporter
  37       *
  38       * @return array
  39       */
  40      protected static function define_related(): array {
  41          return [
  42              'report' => base::class,
  43          ];
  44      }
  45  
  46      /**
  47       * Return the list of additional properties for read structure and export
  48       *
  49       * @return array[]
  50       */
  51      protected static function define_other_properties(): array {
  52          return [
  53              'form' => [
  54                  'type' => PARAM_RAW,
  55                  'optional' => true,
  56              ],
  57              'helpicon' => [
  58                  'type' => PARAM_RAW,
  59                  'optional' => true,
  60              ],
  61          ];
  62      }
  63  
  64      /**
  65       * Get the additional values to inject while exporting
  66       *
  67       * @param renderer_base $output
  68       * @return array
  69       */
  70      protected function get_other_values(renderer_base $output): array {
  71          /** @var base $report */
  72          $report = $this->related['report'];
  73  
  74          $reportid = $report->get_report_persistent()->get('id');
  75  
  76          $reportsettings = $report->get_settings_values();
  77          $cardviewsettings = [
  78              'showfirsttitle' => $reportsettings['cardview_showfirsttitle'] ?? 0,
  79              'visiblecolumns' => $reportsettings['cardview_visiblecolumns'] ?? 1,
  80          ];
  81          $cardviewform = new card_view(null, null, 'post', '', [], true,
  82              array_merge(['reportid' => $reportid], $cardviewsettings));
  83          $cardviewform->set_data_for_dynamic_submission();
  84  
  85          return [
  86              'form' => $cardviewform->render(),
  87              'helpicon' => $output->help_icon('cardview', 'core_reportbuilder'),
  88          ];
  89      }
  90  }