Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 402 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  /**
  18   * The gradebook grade history report
  19   *
  20   * @package    gradereport_history
  21   * @copyright  2013 NetSpot Pty Ltd (https://www.netspot.com.au)
  22   * @author     Adam Olley <adam.olley@netspot.com.au>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once(__DIR__ . '/../../../config.php');
  27  require_once($CFG->libdir.'/gradelib.php');
  28  require_once($CFG->dirroot.'/grade/lib.php');
  29  
  30  $download      = optional_param('download', '', PARAM_ALPHA);
  31  $courseid      = required_param('id', PARAM_INT);        // Course id.
  32  $page          = optional_param('page', 0, PARAM_INT);   // Active page.
  33  $showreport    = optional_param('showreport', 0, PARAM_INT);
  34  
  35  $PAGE->set_pagelayout('report');
  36  $url = new moodle_url('/grade/report/history/index.php', array('id' => $courseid, 'showreport' => 1));
  37  $PAGE->set_url($url);
  38  
  39  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  40  require_login($course);
  41  $context = context_course::instance($course->id);
  42  
  43  require_capability('gradereport/history:view', $context);
  44  require_capability('moodle/grade:viewall', $context);
  45  
  46  // Last selected report session tracking.
  47  if (!isset($USER->grade_last_report)) {
  48      $USER->grade_last_report = array();
  49  }
  50  $USER->grade_last_report[$course->id] = 'history';
  51  
  52  $select = "itemtype <> 'course' AND courseid = :courseid AND " . $DB->sql_isnotempty('grade_items', 'itemname', true, true);
  53  $itemids = $DB->get_records_select_menu('grade_items', $select, array('courseid' => $course->id), 'itemname ASC', 'id, itemname');
  54  foreach ($itemids as $itemid => $itemname) {
  55      $itemids[$itemid] = format_string($itemname, false, array("context" => $context));
  56  }
  57  $itemids = array(0 => get_string('allgradeitems', 'gradereport_history')) + $itemids;
  58  
  59  $output = $PAGE->get_renderer('gradereport_history');
  60  $graders = \gradereport_history\helper::get_graders($course->id);
  61  $params = ['course' => $course, 'itemids' => $itemids, 'graders' => $graders,
  62          'userbutton' => null, 'userfullnames' => ''];
  63  $mform = new \gradereport_history\filter_form(null, $params);
  64  $filters = array();
  65  if ($data = $mform->get_data()) {
  66      $filters = (array)$data;
  67  
  68      if (!empty($filters['datetill'])) {
  69          $filters['datetill'] += DAYSECS - 1; // Set to end of the chosen day.
  70      }
  71  } else {
  72      $filters = array(
  73          'id' => $courseid,
  74          'userids' => optional_param('userids', '', PARAM_SEQUENCE),
  75          'itemid' => optional_param('itemid', 0, PARAM_INT),
  76          'grader' => optional_param('grader', 0, PARAM_INT),
  77          'datefrom' => optional_param('datefrom', 0, PARAM_INT),
  78          'datetill' => optional_param('datetill', 0, PARAM_INT),
  79          'revisedonly' => optional_param('revisedonly', 0, PARAM_INT),
  80      );
  81  }
  82  
  83  $table = new \gradereport_history\output\tablelog('gradereport_history', $context, $url, $filters, $download, $page);
  84  
  85  $names = array();
  86  foreach ($table->get_selected_users() as $key => $user) {
  87      $names[$key] = fullname($user);
  88  }
  89  $userfullnames = implode(', ', $names);
  90  
  91  // Set up js.
  92  \gradereport_history\helper::init_js($course->id, $names);
  93  
  94  // Now that we have the names, reinitialise the button so its able to control them.
  95  $button = new \gradereport_history\output\user_button($PAGE->url, get_string('selectusers', 'gradereport_history'), 'get');
  96  
  97  $userbutton = $output->render($button);
  98  $params = ['course' => $course, 'itemids' => $itemids, 'graders' => $graders,
  99          'userbutton' => $userbutton, 'userfullnames' => $userfullnames];
 100  $mform = new \gradereport_history\filter_form(null, $params);
 101  $mform->set_data($filters);
 102  
 103  if ($table->is_downloading()) {
 104      // Download file and exit.
 105      \core\session\manager::write_close();
 106      echo $output->render($table);
 107      die();
 108  }
 109  
 110  // Print header.
 111  $actionbar = new \core_grades\output\general_action_bar($context,
 112      new moodle_url('/grade/report/history/index.php', ['id' => $courseid]), 'report', 'history');
 113  print_grade_page_head($COURSE->id, 'report', 'history', get_string('pluginname',
 114      'gradereport_history'), false, false, true, null, null,
 115      null, $actionbar);
 116  $mform->display();
 117  
 118  if ($showreport) {
 119      // Only display report after form has been submitted.
 120      echo $output->render($table);
 121  
 122      $event = \gradereport_history\event\grade_report_viewed::create(
 123          array(
 124              'context' => $context,
 125              'courseid' => $courseid
 126          )
 127      );
 128      $event->trigger();
 129  }
 130  
 131  echo $OUTPUT->footer();