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.

Differences Between: [Versions 401 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 renderer_base;
  22  use core_reportbuilder\datasource;
  23  
  24  /**
  25   * Custom report column cards exporter class
  26   *
  27   * @package     core_reportbuilder
  28   * @copyright   2022 Paul Holden <paulh@moodle.com>
  29   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class custom_report_column_cards_exporter extends custom_report_menu_cards_exporter {
  32  
  33      /**
  34       * Return a list of objects that are related to the exporter
  35       *
  36       * @return array
  37       */
  38      protected static function define_related(): array {
  39          return [
  40              'report' => datasource::class,
  41          ];
  42      }
  43  
  44      /**
  45       * Get the additional values to inject while exporting
  46       *
  47       * @param renderer_base $output
  48       * @return array
  49       */
  50      protected function get_other_values(renderer_base $output): array {
  51          /** @var datasource $report */
  52          $report = $this->related['report'];
  53  
  54          $menucards = [];
  55  
  56          foreach ($report->get_columns() as $column) {
  57  
  58              // New menu card per entity.
  59              $entityname = $column->get_entity_name();
  60              if (!array_key_exists($entityname, $menucards)) {
  61                  $menucards[$entityname] = [
  62                      'name' => (string) $report->get_entity_title($entityname),
  63                      'key' => $entityname,
  64                      'items' => [],
  65                  ];
  66              }
  67  
  68              // Append menu card item per column.
  69              $menucards[$entityname]['items'][] = [
  70                  'name' => $column->get_title(),
  71                  'identifier' => $column->get_unique_identifier(),
  72                  'title' => get_string('addcolumn', 'core_reportbuilder', $column->get_title()),
  73                  'action' => 'report-add-column',
  74              ];
  75          }
  76  
  77          return [
  78              'menucards' => array_values($menucards),
  79          ];
  80      }
  81  }