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.
   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   * Event report renderer.
  19   *
  20   * @package    report_eventlist
  21   * @copyright  2014 Adrian Greeve <adrian@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Renderer for event report.
  29   *
  30   * @package    report_eventlist
  31   * @copyright  2014 Adrian Greeve <adrian@moodle.com>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class report_eventlist_renderer extends plugin_renderer_base {
  35  
  36      /**
  37       * Renders the event list page with filter form and datatable.
  38       *
  39       * @param eventfilter_form $form Event filter form.
  40       * @param array $tabledata An array of event data to be used by the datatable.
  41       * @return string HTML to be displayed.
  42       */
  43      public function render_event_list($form, $tabledata) {
  44  
  45          $title = get_string('pluginname', 'report_eventlist');
  46  
  47          // Header.
  48          $html = $this->output->header();
  49          $html .= $this->output->heading($title);
  50  
  51          // Form.
  52          ob_start();
  53          $form->display();
  54          $html .= ob_get_contents();
  55          ob_end_clean();
  56  
  57          $this->page->requires->yui_module('moodle-report_eventlist-eventfilter', 'Y.M.report_eventlist.EventFilter.init',
  58                  array(array('tabledata' => $tabledata)));
  59          $this->page->requires->strings_for_js(array(
  60              'eventname',
  61              'component',
  62              'action',
  63              'crud',
  64              'edulevel',
  65              'affectedtable',
  66              'dname',
  67              'legacyevent',
  68              'since'
  69              ), 'report_eventlist');
  70          $html .= html_writer::start_div('report-eventlist-data-table', array('id' => 'report-eventlist-table'));
  71          $html .= html_writer::end_div();
  72  
  73          $html .= $this->output->footer();
  74          return $html;
  75      }
  76  
  77      /**
  78       * Event detail renderer.
  79       *
  80       * @param array $observerlist A list of observers that consume this event.
  81       * @param array $eventinformation A list of information about the event.
  82       * @return string HTML to be displayed.
  83       */
  84      public function render_event_detail($observerlist, $eventinformation) {
  85  
  86          $titlehtml = $this->output->header();
  87          $titlehtml .= $this->output->heading($eventinformation['title']);
  88  
  89          $html = html_writer::start_tag('dl', array('class' => 'list'));
  90  
  91          $explanation = nl2br($eventinformation['explanation']);
  92          $html .= html_writer::tag('dt', get_string('eventexplanation', 'report_eventlist'));
  93          $html .= html_writer::tag('dd', $explanation);
  94  
  95          if (isset($eventinformation['crud'])) {
  96              $html .= html_writer::tag('dt', get_string('crud', 'report_eventlist'));
  97              $html .= html_writer::tag('dd', $eventinformation['crud']);
  98          }
  99  
 100          if (isset($eventinformation['edulevel'])) {
 101              $html .= html_writer::tag('dt', get_string('edulevel', 'report_eventlist'));
 102              $html .= html_writer::tag('dd', $eventinformation['edulevel']);
 103          }
 104  
 105          if (isset($eventinformation['objecttable'])) {
 106              $html .= html_writer::tag('dt', get_string('affectedtable', 'report_eventlist'));
 107              $html .= html_writer::tag('dd', $eventinformation['objecttable']);
 108          }
 109  
 110          if (isset($eventinformation['legacyevent'])) {
 111              $html .= html_writer::tag('dt', get_string('legacyevent', 'report_eventlist'));
 112              $html .= html_writer::tag('dd', $eventinformation['legacyevent']);
 113          }
 114  
 115          if (isset($eventinformation['parentclass'])) {
 116              $url = new moodle_url('eventdetail.php', array('eventname' => $eventinformation['parentclass']));
 117              $html .= html_writer::tag('dt', get_string('parentevent', 'report_eventlist'));
 118              $html .= html_writer::tag('dd', html_writer::link($url, $eventinformation['parentclass']));
 119          }
 120  
 121          if (isset($eventinformation['abstract'])) {
 122              $html .= html_writer::tag('dt', get_string('abstractclass', 'report_eventlist'));
 123              $html .= html_writer::tag('dd', get_string('yes', 'report_eventlist'));
 124          }
 125  
 126          if (isset($eventinformation['typeparameter'])) {
 127              $html .= html_writer::tag('dt', get_string('typedeclaration', 'report_eventlist'));
 128              foreach ($eventinformation['typeparameter'] as $typeparameter) {
 129                  $html .= html_writer::tag('dd', $typeparameter);
 130              }
 131          }
 132  
 133          if (isset($eventinformation['otherparameter'])) {
 134              $html .= html_writer::tag('dt', get_string('othereventparameters', 'report_eventlist'));
 135              foreach ($eventinformation['otherparameter'] as $otherparameter) {
 136                  $html .= html_writer::tag('dd', $otherparameter);
 137              }
 138          }
 139  
 140          // List observers consuming this event if there are any.
 141          if (!empty($observerlist)) {
 142              $html .= html_writer::tag('dt', get_string('relatedobservers', 'report_eventlist'));
 143              foreach ($observerlist as $observer) {
 144                  if ($observer->plugin == 'core') {
 145                      $html .= html_writer::tag('dd', $observer->plugin);
 146                  } else {
 147                      $manager = get_string_manager();
 148                      $pluginstring = $observer->plugintype . '_' . $observer->plugin;
 149                      if ($manager->string_exists('pluginname', $pluginstring)) {
 150                          if (!empty($observer->parentplugin)) {
 151                              $string = get_string('pluginname', $pluginstring) . ' (' . $observer->parentplugin
 152                                      . ' ' . $pluginstring . ')';
 153                          } else {
 154                              $string = get_string('pluginname', $pluginstring) . ' (' . $pluginstring . ')';
 155                          }
 156                      } else {
 157                          $string = $observer->plugintype . ' ' . $observer->plugin;
 158                      }
 159                      $html .= html_writer::tag('dd', $string);
 160                  }
 161              }
 162          }
 163          $html .= html_writer::end_div();
 164          $html .= html_writer::end_tag('dl');
 165  
 166          $pagecontent = new html_table();
 167          $pagecontent->data = array(array($html));
 168          $pagehtml = $titlehtml . html_writer::table($pagecontent);
 169          $pagehtml .= $this->output->footer();
 170  
 171          return $pagehtml;
 172      }
 173  }