Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 401 and 403] [Versions 402 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              if ($column->get_is_deprecated()) {
  58                  continue;
  59              }
  60  
  61              // New menu card per entity.
  62              $entityname = $column->get_entity_name();
  63              if (!array_key_exists($entityname, $menucards)) {
  64                  $menucards[$entityname] = [
  65                      'name' => (string) $report->get_entity_title($entityname),
  66                      'key' => $entityname,
  67                      'items' => [],
  68                  ];
  69              }
  70  
  71              // Append menu card item per column.
  72              $menucards[$entityname]['items'][] = [
  73                  'name' => $column->get_title(),
  74                  'identifier' => $column->get_unique_identifier(),
  75                  'title' => get_string('addcolumn', 'core_reportbuilder', $column->get_title()),
  76                  'action' => 'report-add-column',
  77              ];
  78          }
  79  
  80          return [
  81              'menucards' => array_values($menucards),
  82          ];
  83      }
  84  }