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 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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   * Log report renderer.
  19   *
  20   * @package    report_log
  21   * @copyright  2014 Rajesh Taneja <rajesh.taneja@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   * @package    report_log
  30   * @copyright  2014 Rajesh Taneja <rajesh.taneja@gmail.com>
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class report_log_renderer extends plugin_renderer_base {
  34  
  35      /**
  36       * This method should never be manually called, it should only be called by process.
  37       *
  38       * @deprecated since 2.8, to be removed in 2.9
  39       * @param report_log_renderable $reportlog
  40       * @return string
  41       */
  42      public function render_report_log_renderable(report_log_renderable $reportlog) {
  43          debugging('Do not call this method. Please call $renderer->render($reportlog) instead.', DEBUG_DEVELOPER);
  44          return $this->render($reportlog);
  45      }
  46  
  47      /**
  48       * Render log report page.
  49       *
  50       * @param report_log_renderable $reportlog object of report_log.
  51       */
  52      protected function render_report_log(report_log_renderable $reportlog) {
  53          if (empty($reportlog->selectedlogreader)) {
  54              echo $this->output->notification(get_string('nologreaderenabled', 'report_log'), 'notifyproblem');
  55              return;
  56          }
  57          if ($reportlog->showselectorform) {
  58              $this->report_selector_form($reportlog);
  59          }
  60  
  61          if ($reportlog->showreport) {
  62              $reportlog->tablelog->out($reportlog->perpage, true);
  63          }
  64      }
  65  
  66      /**
  67       * Prints/return reader selector
  68       *
  69       * @param report_log_renderable $reportlog log report.
  70       */
  71      public function reader_selector(report_log_renderable $reportlog) {
  72          $readers = $reportlog->get_readers(true);
  73          if (empty($readers)) {
  74              $readers = array(get_string('nologreaderenabled', 'report_log'));
  75          }
  76          $url = fullclone ($reportlog->url);
  77          $url->remove_params(array('logreader'));
  78          $select = new single_select($url, 'logreader', $readers, $reportlog->selectedlogreader, null);
  79          $select->set_label(get_string('selectlogreader', 'report_log'));
  80          echo $this->output->render($select);
  81      }
  82  
  83      /**
  84       * This function is used to generate and display selector form
  85       *
  86       * @param report_log_renderable $reportlog log report.
  87       */
  88      public function report_selector_form(report_log_renderable $reportlog) {
  89          echo html_writer::start_tag('form', array('class' => 'logselecform', 'action' => $reportlog->url, 'method' => 'get'));
  90          echo html_writer::start_div();
  91          echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'chooselog', 'value' => '1'));
  92          echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showusers', 'value' => $reportlog->showusers));
  93          echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showcourses',
  94              'value' => $reportlog->showcourses));
  95  
  96          $selectedcourseid = empty($reportlog->course) ? 0 : $reportlog->course->id;
  97  
  98          // Add course selector.
  99          $sitecontext = context_system::instance();
 100          $courses = $reportlog->get_course_list();
 101          if (!empty($courses) && $reportlog->showcourses) {
 102              echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide'));
 103              echo html_writer::select($courses, "id", $selectedcourseid, null, ['class' => 'mr-2 mb-2']);
 104          } else {
 105              $courses = array();
 106              $courses[$selectedcourseid] = get_course_display_name_for_list($reportlog->course) . (($selectedcourseid == SITEID) ?
 107                  ' (' . get_string('site') . ') ' : '');
 108              echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide'));
 109              echo html_writer::select($courses, "id", $selectedcourseid, false, ['class' => 'mr-2 mb-2']);
 110              // Check if user is admin and this came because of limitation on number of courses to show in dropdown.
 111              if (has_capability('report/log:view', $sitecontext)) {
 112                  $a = new stdClass();
 113                  $a->url = new moodle_url('/report/log/index.php', array('chooselog' => 0,
 114                      'group' => $reportlog->get_selected_group(), 'user' => $reportlog->userid,
 115                      'id' => $selectedcourseid, 'date' => $reportlog->date, 'modid' => $reportlog->modid,
 116                      'showcourses' => 1, 'showusers' => $reportlog->showusers));
 117                  $a->url = $a->url->out(false);
 118                  print_string('logtoomanycourses', 'moodle', $a);
 119              }
 120          }
 121  
 122          // Add group selector.
 123          $groups = $reportlog->get_group_list();
 124          if (!empty($groups)) {
 125              echo html_writer::label(get_string('selectagroup'), 'menugroup', false, array('class' => 'accesshide'));
 126              echo html_writer::select($groups, "group", $reportlog->groupid, get_string("allgroups"),
 127                  ['class' => 'mr-2 mb-2']);
 128          }
 129  
 130          // Add user selector.
 131          $users = $reportlog->get_user_list();
 132  
 133          if ($reportlog->showusers) {
 134              echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide'));
 135              echo html_writer::select($users, "user", $reportlog->userid, get_string("allparticipants"),
 136                  ['class' => 'mr-2 mb-2']);
 137          } else {
 138              $users = array();
 139              if (!empty($reportlog->userid)) {
 140                  $users[$reportlog->userid] = $reportlog->get_selected_user_fullname();
 141              } else {
 142                  $users[0] = get_string('allparticipants');
 143              }
 144              echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide'));
 145              echo html_writer::select($users, "user", $reportlog->userid, false, ['class' => 'mr-2 mb-2']);
 146              $a = new stdClass();
 147              $a->url = new moodle_url('/report/log/index.php', array('chooselog' => 0,
 148                  'group' => $reportlog->get_selected_group(), 'user' => $reportlog->userid,
 149                  'id' => $selectedcourseid, 'date' => $reportlog->date, 'modid' => $reportlog->modid,
 150                  'showusers' => 1, 'showcourses' => $reportlog->showcourses));
 151              $a->url = $a->url->out(false);
 152              echo html_writer::start_span('mx-1');
 153              print_string('logtoomanyusers', 'moodle', $a);
 154              echo html_writer::end_span();
 155          }
 156  
 157          // Add date selector.
 158          $dates = $reportlog->get_date_options();
 159          echo html_writer::label(get_string('date'), 'menudate', false, array('class' => 'accesshide'));
 160          echo html_writer::select($dates, "date", $reportlog->date, get_string("alldays"),
 161              ['class' => 'mr-2 mb-2']);
 162  
 163          // Add activity selector.
 164          $activities = $reportlog->get_activities_list();
 165          echo html_writer::label(get_string('activities'), 'menumodid', false, array('class' => 'accesshide'));
 166          echo html_writer::select($activities, "modid", $reportlog->modid, get_string("allactivities"),
 167              ['class' => 'mr-2 mb-2']);
 168  
 169          // Add actions selector.
 170          echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide'));
 171          echo html_writer::select($reportlog->get_actions(), 'modaction', $reportlog->action,
 172              get_string("allactions"), ['class' => 'mr-2 mb-2']);
 173  
 174          // Add origin.
 175          $origin = $reportlog->get_origin_options();
 176          echo html_writer::label(get_string('origin', 'report_log'), 'menuorigin', false, array('class' => 'accesshide'));
 177          echo html_writer::select($origin, 'origin', $reportlog->origin, false, ['class' => 'mr-2 mb-2']);
 178  
 179          // Add edulevel.
 180          $edulevel = $reportlog->get_edulevel_options();
 181          echo html_writer::label(get_string('edulevel'), 'menuedulevel', false, array('class' => 'accesshide'));
 182          echo html_writer::select($edulevel, 'edulevel', $reportlog->edulevel, false,
 183              ['class' => 'mr-2 mb-2']) .$this->help_icon('edulevel');
 184  
 185          // Add reader option.
 186          // If there is some reader available then only show submit button.
 187          $readers = $reportlog->get_readers(true);
 188          if (!empty($readers)) {
 189              if (count($readers) == 1) {
 190                  $attributes = array('type' => 'hidden', 'name' => 'logreader', 'value' => key($readers));
 191                  echo html_writer::empty_tag('input', $attributes);
 192              } else {
 193                  echo html_writer::label(get_string('selectlogreader', 'report_log'), 'menureader', false,
 194                          array('class' => 'accesshide'));
 195                  echo html_writer::select($readers, 'logreader', $reportlog->selectedlogreader, false,
 196                      ['class' => 'mr-2 mb-2']);
 197              }
 198              echo html_writer::start_div('mt-1');
 199              echo html_writer::empty_tag('input', array('type' => 'submit',
 200                  'value' => get_string('gettheselogs'), 'class' => 'btn btn-primary'));
 201              echo html_writer::end_div();
 202          }
 203          echo html_writer::end_div();
 204          echo html_writer::end_tag('form');
 205      }
 206  }
 207