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] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 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 grader report
  19   *
  20   * @package   gradereport_grader
  21   * @copyright 2007 Moodle Pty Ltd (http://moodle.com)
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once('../../../config.php');
  26  require_once($CFG->libdir.'/gradelib.php');
  27  require_once($CFG->dirroot.'/user/renderer.php');
  28  require_once($CFG->dirroot.'/grade/lib.php');
  29  require_once($CFG->dirroot.'/grade/report/grader/lib.php');
  30  
  31  $courseid      = required_param('id', PARAM_INT);        // course id
  32  $page          = optional_param('page', 0, PARAM_INT);   // active page
  33  $edit          = optional_param('edit', -1, PARAM_BOOL); // sticky editting mode
  34  
  35  $sortitemid    = optional_param('sortitemid', 0, PARAM_ALPHANUMEXT);
  36  $action        = optional_param('action', 0, PARAM_ALPHAEXT);
  37  $move          = optional_param('move', 0, PARAM_INT);
  38  $type          = optional_param('type', 0, PARAM_ALPHA);
  39  $target        = optional_param('target', 0, PARAM_ALPHANUM);
  40  $toggle        = optional_param('toggle', null, PARAM_INT);
  41  $toggle_type   = optional_param('toggle_type', 0, PARAM_ALPHANUM);
  42  
  43  $graderreportsifirst  = optional_param('sifirst', null, PARAM_NOTAGS);
  44  $graderreportsilast   = optional_param('silast', null, PARAM_NOTAGS);
  45  
  46  $PAGE->set_url(new moodle_url('/grade/report/grader/index.php', array('id'=>$courseid)));
  47  $PAGE->set_pagelayout('report');
  48  $PAGE->requires->js_call_amd('gradereport_grader/stickycolspan', 'init');
  49  
  50  // basic access checks
  51  if (!$course = $DB->get_record('course', array('id' => $courseid))) {
  52      throw new \moodle_exception('invalidcourseid');
  53  }
  54  require_login($course);
  55  $context = context_course::instance($course->id);
  56  
  57  // The report object is recreated each time, save search information to SESSION object for future use.
  58  if (isset($graderreportsifirst)) {
  59      $SESSION->gradereport["filterfirstname-{$context->id}"] = $graderreportsifirst;
  60  }
  61  if (isset($graderreportsilast)) {
  62      $SESSION->gradereport["filtersurname-{$context->id}"] = $graderreportsilast;
  63  }
  64  
  65  require_capability('gradereport/grader:view', $context);
  66  require_capability('moodle/grade:viewall', $context);
  67  
  68  // return tracking object
  69  $gpr = new grade_plugin_return(
  70      array(
  71          'type' => 'report',
  72          'plugin' => 'grader',
  73          'course' => $course,
  74          'page' => $page
  75      )
  76  );
  77  
  78  // last selected report session tracking
  79  if (!isset($USER->grade_last_report)) {
  80      $USER->grade_last_report = array();
  81  }
  82  $USER->grade_last_report[$course->id] = 'grader';
  83  
  84  // Build editing on/off buttons.
  85  $buttons = '';
  86  
  87  $PAGE->set_other_editing_capability('moodle/grade:edit');
  88  if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) {
  89      if ($edit != - 1) {
  90          $USER->editing = $edit;
  91      }
  92  
  93      // Page params for the turn editing on button.
  94      $options = $gpr->get_options();
  95      $buttons = $OUTPUT->edit_button(new moodle_url($PAGE->url, $options), 'get');
  96  }
  97  
  98  $gradeserror = array();
  99  
 100  // Handle toggle change request
 101  if (!is_null($toggle) && !empty($toggle_type)) {
 102      set_user_preferences(array('grade_report_show'.$toggle_type => $toggle));
 103  }
 104  
 105  // Perform actions
 106  if (!empty($target) && !empty($action) && confirm_sesskey()) {
 107      grade_report_grader::do_process_action($target, $action, $courseid);
 108  }
 109  
 110  // Do this check just before printing the grade header (and only do it once).
 111  grade_regrade_final_grades_if_required($course);
 112  
 113  // Print header
 114  print_grade_page_head($COURSE->id, 'report', 'grader', false, false, $buttons);
 115  
 116  //Initialise the grader report object that produces the table
 117  //the class grade_report_grader_ajax was removed as part of MDL-21562
 118  $report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
 119  $numusers = $report->get_numusers(true, true);
 120  
 121  // make sure separate group does not prevent view
 122  if ($report->currentgroup == -2) {
 123      echo $OUTPUT->heading(get_string("notingroup"));
 124      echo $OUTPUT->footer();
 125      exit;
 126  }
 127  
 128  $warnings = [];
 129  $isediting = has_capability('moodle/grade:edit', $context) && isset($USER->editing) && $USER->editing;
 130  if ($isediting && ($data = data_submitted()) && confirm_sesskey()) {
 131      // Processing posted grades & feedback here.
 132      $warnings = $report->process_data($data);
 133  }
 134  
 135  // Final grades MUST be loaded after the processing.
 136  $report->load_users();
 137  $report->load_final_grades();
 138  echo $report->group_selector;
 139  
 140  // User search
 141  $url = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id));
 142  $firstinitial = $SESSION->gradereport["filterfirstname-{$context->id}"] ?? '';
 143  $lastinitial  = $SESSION->gradereport["filtersurname-{$context->id}"] ?? '';
 144  $totalusers = $report->get_numusers(true, false);
 145  $renderer = $PAGE->get_renderer('core_user');
 146  echo $renderer->user_search($url, $firstinitial, $lastinitial, $numusers, $totalusers, $report->currentgroupname);
 147  
 148  //show warnings if any
 149  foreach ($warnings as $warning) {
 150      echo $OUTPUT->notification($warning);
 151  }
 152  
 153  $studentsperpage = $report->get_students_per_page();
 154  // Don't use paging if studentsperpage is empty or 0 at course AND site levels
 155  if (!empty($studentsperpage)) {
 156      echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
 157  }
 158  
 159  $displayaverages = true;
 160  if ($numusers == 0) {
 161      $displayaverages = false;
 162  }
 163  
 164  $reporthtml = $report->get_grade_table($displayaverages);
 165  
 166  // print submit button
 167  if (!empty($USER->editing) && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading'))) {
 168      echo '<form action="index.php" enctype="application/x-www-form-urlencoded" method="post" id="gradereport_grader">'; // Enforce compatibility with our max_input_vars hack.
 169      echo '<div>';
 170      echo '<input type="hidden" value="'.s($courseid).'" name="id" />';
 171      echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
 172      echo '<input type="hidden" value="'.time().'" name="timepageload" />';
 173      echo '<input type="hidden" value="grader" name="report"/>';
 174      echo '<input type="hidden" value="'.$page.'" name="page"/>';
 175      echo $gpr->get_form_fields();
 176      echo $reporthtml;
 177      echo '<div class="submit"><input type="submit" id="gradersubmit" class="btn btn-primary"
 178          value="'.s(get_string('savechanges')).'" /></div>';
 179      echo '</div></form>';
 180  } else {
 181      echo $reporthtml;
 182  }
 183  
 184  // prints paging bar at bottom for large pages
 185  if (!empty($studentsperpage) && $studentsperpage >= 20) {
 186      echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
 187  }
 188  
 189  $event = \gradereport_grader\event\grade_report_viewed::create(
 190      array(
 191          'context' => $context,
 192          'courseid' => $courseid,
 193      )
 194  );
 195  $event->trigger();
 196  
 197  echo $OUTPUT->footer();