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 402] [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  namespace report_progress\output;
  18  
  19  use single_select;
  20  use plugin_renderer_base;
  21  use html_writer;
  22  
  23  /**
  24   * Renderer for report progress.
  25   *
  26   * @package   report_progress
  27   * @copyright 2021 The Open University
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL Juv3 or later
  29   */
  30  class renderer extends plugin_renderer_base {
  31      /**
  32       * Render include activity single select box.
  33       *
  34       * @param \moodle_url $url The base url.
  35       * @param array $activitytypes The activity type options.
  36       * @param string $activityinclude The current selected option.
  37       * @return string HTML
  38       * @throws \coding_exception
  39       */
  40      public function render_include_activity_select(\moodle_url $url, array $activitytypes,
  41              string $activityinclude): string {
  42          $includeurl = fullclone($url);
  43          $includeurl->remove_params(['page', 'activityinclude']);
  44          $activityincludeselect = new single_select(
  45              $url, 'activityinclude',
  46              $activitytypes, $activityinclude, null, 'include-activity-select-report'
  47          );
  48          $activityincludeselect->set_label(get_string('include', 'report_progress'));
  49          return \html_writer::div($this->output->render($activityincludeselect),
  50                  'include-activity-selector d-inline-block mr-3' );
  51      }
  52  
  53      /**
  54       * Render activity order single select box.
  55       *
  56       * @param \moodle_url $url The base url.
  57       * @param string $activityorder The current selected option.
  58       * @return string HTML
  59       * @throws \coding_exception
  60       */
  61      public function render_activity_order_select(\moodle_url $url, string $activityorder): string {
  62          $activityorderurl = fullclone($url);
  63          $activityorderurl->remove_params(['activityorder']);
  64          $options = ['orderincourse' => get_string('orderincourse', 'report_progress'),
  65              'alphabetical' => get_string('alphabetical', 'report_progress')];
  66          $sorttable = new single_select(
  67              $activityorderurl, 'activityorder',
  68              $options, $activityorder, null, 'activity-order-select-report'
  69          );
  70          $sorttable->set_label(get_string('activityorder', 'report_progress'));
  71          return \html_writer::div($this->output->render($sorttable),
  72                  'activity-order-selector include-activity-selector d-inline-block');
  73      }
  74  
  75      /**
  76       * Render groups single select box.
  77       *
  78       * @param \moodle_url $url The base url.
  79       * @param \stdClass $course Current course.
  80       * @return string HTML
  81       */
  82      public function render_groups_select(\moodle_url $url, \stdClass $course): string {
  83          $groupurl = fullclone($url);
  84          $groupurl->remove_params(['page', 'group']);
  85          $groupoutput = groups_print_course_menu($course, $groupurl, true);
  86  
  87          if (empty($groupoutput)) {
  88              return $groupoutput;
  89          }
  90  
  91          return \html_writer::div($groupoutput, 'd-inline-block mr-3');
  92      }
  93  
  94      /**
  95       * Render download buttons.
  96       *
  97       * @param \moodle_url $url The base url.
  98       * @return string HTML
  99       * @throws \coding_exception
 100       */
 101      public function render_download_buttons(\moodle_url $url): string {
 102          $downloadurl = fullclone($url);
 103          $downloadurl->remove_params(['page']);
 104          $downloadurl->param('format', 'csv');
 105          $downloadhtml = html_writer::start_tag('ul', ['class' => 'progress-actions']);
 106          $downloadhtml .= html_writer::tag('li', html_writer::link($downloadurl, get_string('csvdownload', 'completion')));
 107          $downloadurl->param('format', 'excelcsv');
 108          $downloadhtml .= html_writer::tag('li', html_writer::link($downloadurl, get_string('excelcsvdownload', 'completion')));
 109          $downloadhtml .= html_writer::end_tag('ul');
 110  
 111          return $downloadhtml;
 112      }
 113  }