Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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  /**
  18   * Loglive report renderer.
  19   *
  20   * @package    report_loglive
  21   * @copyright  2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  defined('MOODLE_INTERNAL') || die;
  25  
  26  /**
  27   * Report log renderer's for printing reports.
  28   *
  29   * @since      Moodle 2.7
  30   * @package    report_loglive
  31   * @copyright  2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class report_loglive_renderer extends plugin_renderer_base {
  35  
  36      /**
  37       * This method should never be manually called, it should only be called by process.
  38       * Please call the render method instead.
  39       *
  40       * @deprecated since 2.8, to be removed in 2.9
  41       * @param report_loglive_renderable $reportloglive
  42       * @return string
  43       */
  44      public function render_report_loglive_renderable(report_loglive_renderable $reportloglive) {
  45          debugging('Do not call this method. Please call $renderer->render($reportloglive) instead.', DEBUG_DEVELOPER);
  46          return $this->render($reportloglive);
  47      }
  48  
  49      /**
  50       * Return html to render the loglive page..
  51       *
  52       * @param report_loglive_renderable $reportloglive object of report_log.
  53       *
  54       * @return string html used to render the page;
  55       */
  56      protected function render_report_loglive(report_loglive_renderable $reportloglive) {
  57          if (empty($reportloglive->selectedlogreader)) {
  58              return $this->output->notification(get_string('nologreaderenabled', 'report_loglive'), 'notifyproblem');
  59          }
  60  
  61          $table = $reportloglive->get_table();
  62          return $this->render_table($table, $reportloglive->perpage);
  63      }
  64  
  65      /**
  66       * Prints/return reader selector
  67       *
  68       * @param report_loglive_renderable $reportloglive log report.
  69       *
  70       * @return string Returns rendered widget
  71       */
  72      public function reader_selector(report_loglive_renderable $reportloglive) {
  73          $readers = $reportloglive->get_readers(true);
  74          if (count($readers) <= 1) {
  75              // One or no readers found, no need of this drop down.
  76              return '';
  77          }
  78          $select = new single_select($reportloglive->url, 'logreader', $readers, $reportloglive->selectedlogreader, null);
  79          $select->set_label(get_string('selectlogreader', 'report_loglive'));
  80          return $this->output->render($select);
  81      }
  82  
  83      /**
  84       * Prints a button to update/resume live updates.
  85       *
  86       * @param report_loglive_renderable $reportloglive log report.
  87       *
  88       * @return string Returns rendered widget
  89       */
  90      public function toggle_liveupdate_button(report_loglive_renderable $reportloglive) {
  91          // Add live log controls.
  92          if ($reportloglive->page == 0 && $reportloglive->selectedlogreader) {
  93              echo html_writer::tag('button' , get_string('pause', 'report_loglive'),
  94                  array('id' => 'livelogs-pause-button', 'class' => 'btn btn-secondary'));
  95              $icon = new pix_icon('i/loading_small', 'loading', 'moodle', array('class' => 'spinner'));
  96              return html_writer::tag('span', $this->output->render($icon), array('class' => 'spinner'));
  97          }
  98          return '';
  99      }
 100  
 101      /**
 102       * Get the html for the table.
 103       *
 104       * @param report_loglive_table_log $table table object.
 105       * @param int $perpage entries to display perpage.
 106       *
 107       * @return string table html
 108       */
 109      protected function render_table(report_loglive_table_log $table, $perpage) {
 110          $o = '';
 111          ob_start();
 112          $table->out($perpage, true);
 113          $o = ob_get_contents();
 114          ob_end_clean();
 115  
 116          return $o;
 117      }
 118  }