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\output;
  20  
  21  use html_writer;
  22  use moodle_url;
  23  use plugin_renderer_base;
  24  use core_reportbuilder\table\custom_report_table;
  25  use core_reportbuilder\table\custom_report_table_view;
  26  use core_reportbuilder\table\system_report_table;
  27  use core_reportbuilder\local\models\report;
  28  
  29  /**
  30   * Report renderer class
  31   *
  32   * @package     core_reportbuilder
  33   * @copyright   2020 Paul Holden <paulh@moodle.com>
  34   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class renderer extends plugin_renderer_base {
  37  
  38      /**
  39       * Render a system report
  40       *
  41       * @param system_report $report
  42       * @return string
  43       */
  44      protected function render_system_report(system_report $report): string {
  45          $context = $report->export_for_template($this);
  46  
  47          return $this->render_from_template('core_reportbuilder/report', $context);
  48      }
  49  
  50      /**
  51       * Render a system report table
  52       *
  53       * @param system_report_table $table
  54       * @return string
  55       */
  56      protected function render_system_report_table(system_report_table $table): string {
  57          ob_start();
  58          $table->out($table->get_default_per_page(), false);
  59          $output = ob_get_contents();
  60          ob_end_clean();
  61  
  62          return $output;
  63      }
  64  
  65      /**
  66       * Render a custom report
  67       *
  68       * @param custom_report $report
  69       * @return string
  70       */
  71      protected function render_custom_report(custom_report $report): string {
  72          $context = $report->export_for_template($this);
  73  
  74          return $this->render_from_template('core_reportbuilder/local/dynamictabs/editor', $context);
  75      }
  76  
  77      /**
  78       * Render a custom report table
  79       *
  80       * @param custom_report_table $table
  81       * @return string
  82       */
  83      protected function render_custom_report_table(custom_report_table $table): string {
  84          ob_start();
  85          $table->out($table->get_default_per_page(), false);
  86          $output = ob_get_contents();
  87          ob_end_clean();
  88  
  89          return $output;
  90      }
  91  
  92      /**
  93       * Render a custom report table (view only mode)
  94       *
  95       * @param custom_report_table_view $table
  96       * @return string
  97       */
  98      protected function render_custom_report_table_view(custom_report_table_view $table): string {
  99          ob_start();
 100          $table->out($table->get_default_per_page(), false);
 101          $output = ob_get_contents();
 102          ob_end_clean();
 103  
 104          return $output;
 105      }
 106  
 107      /**
 108       * Renders the New report button
 109       *
 110       * @return string
 111       */
 112      public function render_new_report_button(): string {
 113          return html_writer::tag('button', get_string('newreport', 'core_reportbuilder'), [
 114              'class' => 'btn btn-primary my-auto',
 115              'data-action' => 'report-create',
 116          ]);
 117      }
 118  
 119      /**
 120       * Renders full page editor header
 121       *
 122       * @param report $report
 123       * @return string
 124       */
 125      public function render_fullpage_editor_header(report $report): string {
 126          $reportname = $report->get_formatted_name();
 127          $editdetailsbutton = html_writer::tag('button', get_string('editdetails', 'core_reportbuilder'), [
 128              'class' => 'btn btn-outline-secondary mr-2',
 129              'data-action' => 'report-edit',
 130              'data-report-id' => $report->get('id')
 131          ]);
 132          $closebutton = html_writer::link(new moodle_url('/reportbuilder/index.php'), get_string('close', 'core_reportbuilder'), [
 133              'class' => 'btn btn-secondary',
 134              'title' => get_string('closeeditor', 'core_reportbuilder', $reportname),
 135              'role' => 'button'
 136          ]);
 137          $context = [
 138              'title' => $reportname,
 139              'buttons' => $editdetailsbutton . $closebutton,
 140          ];
 141  
 142          return $this->render_from_template('core_reportbuilder/editor_navbar', $context);
 143      }
 144  }