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.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   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 developer detail.
  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  require_once(__DIR__ . '/../../config.php');
  25  require_once($CFG->libdir . '/adminlib.php');
  26  
  27  // Required parameters.
  28  $eventname = required_param('eventname', PARAM_RAW);
  29  
  30  admin_externalpage_setup('reporteventlists');
  31  
  32  // Retrieve all events in a list.
  33  $completelist = report_eventlist_list_generator::get_all_events_list(false);
  34  
  35  // Check that $eventname is a valid event.
  36  if (!array_key_exists($eventname, $completelist)) {
  37      print_error('errorinvalidevent', 'report_eventlist');
  38  }
  39  
  40  // Break up the full event name to usable parts.
  41  $component = explode('\\', $eventname);
  42  $directory = core_component::get_component_directory($component[1]);
  43  
  44  // File and directory information.
  45  $directory = $directory . '/classes/event';
  46  // Verify that the directory is valid.
  47  if (!is_dir($directory)) {
  48      print_error('errorinvaliddirectory', 'report_eventlist');
  49  }
  50  $filename = end($component);
  51  $eventfiles = $directory . '/' . $filename . '.php';
  52  $title = $eventname::get_name_with_info();
  53  
  54  // Define event information.
  55  $eventinformation = array('title' => $title);
  56  $eventcontents = file_get_contents($eventfiles);
  57  $eventinformation['filecontents'] = $eventcontents;
  58  
  59  $ref = new \ReflectionClass($eventname);
  60  $eventinformation['explanation'] = $eventname::get_explanation($eventname);
  61  // Get event information nicely if we can.
  62  if (!$ref->isAbstract()) {
  63      $eventinformation = array_merge($eventinformation, $eventname::get_static_info());
  64      $eventinformation['legacyevent'] = $eventname::get_legacy_eventname();
  65      $eventinformation['crud'] = report_eventlist_list_generator::get_crud_string($eventinformation['crud']);
  66      $eventinformation['edulevel'] = report_eventlist_list_generator::get_edulevel_string($eventinformation['edulevel']);
  67  } else {
  68      $eventinformation['abstract'] = true;
  69      if ($eventname != '\core\event\base') {
  70          // No choice but to get information the hard way.
  71          // Strip out CRUD information.
  72          $crudpattern = "/(\['crud'\]\s=\s')(\w)/";
  73          $result = array();
  74          preg_match($crudpattern, $eventcontents, $result);
  75          if (!empty($result[2])) {
  76              $eventinformation['crud'] = report_eventlist_list_generator::get_crud_string($result[2]);
  77          }
  78  
  79          // Strip out edulevel information.
  80          $edulevelpattern = "/(\['edulevel'\]\s=\sself\:\:)(\w*)/";
  81          $result = array();
  82          preg_match($edulevelpattern, $eventcontents, $result);
  83          if (!empty($result[2])) {
  84              $educationlevel = constant('\core\event\base::' . $result[2]);
  85              $eventinformation['edulevel'] = report_eventlist_list_generator::get_edulevel_string($educationlevel);
  86          }
  87  
  88          // Retrieve object table information.
  89          $affectedtablepattern = "/(\['objecttable'\]\s=\s')(\w*)/";
  90          $result = array();
  91          preg_match($affectedtablepattern, $eventcontents, $result);
  92          if (!empty($result[2])) {
  93              $eventinformation['objecttable'] = $result[2];
  94          }
  95      }
  96  }
  97  
  98  // I can't think of a nice way to get the following information.
  99  // Searching to see if @type has been used for the 'other' field in the event.
 100  $othertypepattern = "/(@type\s([\w|\s|.]*))+/";
 101  $typeparams = array();
 102  preg_match_all($othertypepattern, $eventcontents, $typeparams);
 103  if (!empty($typeparams[2])) {
 104      $eventinformation['typeparameter'] = array();
 105      foreach ($typeparams[2] as $typeparameter) {
 106          $eventinformation['typeparameter'][] = $typeparameter;
 107      }
 108  }
 109  
 110  // Retrieving the 'other' event field information.
 111  $otherpattern = "/(\*\s{5,}-([\w|\s]*\:[\w|\s|\(|\)|.]*))/";
 112  $typeparams = array();
 113  preg_match_all($otherpattern, $eventcontents, $typeparams);
 114  if (!empty($typeparams[2])) {
 115      $eventinformation['otherparameter'] = array();
 116      foreach ($typeparams[2] as $typeparameter) {
 117          $eventinformation['otherparameter'][] = $typeparameter;
 118      }
 119  }
 120  
 121  // Get parent class information.
 122  if ($parentclass = get_parent_class($eventname)) {
 123      $eventinformation['parentclass'] = '\\' . $parentclass;
 124  }
 125  
 126  // Fetch all the observers to be matched with this event.
 127  $allobserverslist = report_eventlist_list_generator::get_observer_list();
 128  $observers = array();
 129  
 130  if (isset($allobserverslist['\\core\\event\\base'])) {
 131      $observers = $allobserverslist['\\core\\event\\base'];
 132  }
 133  if (isset($allobserverslist[$eventname])) {
 134      $observers = array_merge($observers, $allobserverslist[$eventname]);
 135  }
 136  
 137  // OUTPUT.
 138  $renderer = $PAGE->get_renderer('report_eventlist');
 139  echo $renderer->render_event_detail($observers, $eventinformation);
 140