Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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      print_error('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  $reportname = get_string('pluginname', 'gradereport_grader');
 111  
 112  // Do this check just before printing the grade header (and only do it once).
 113  grade_regrade_final_grades_if_required($course);
 114  
 115  // Print header
 116  print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $buttons);
 117  
 118  //Initialise the grader report object that produces the table
 119  //the class grade_report_grader_ajax was removed as part of MDL-21562
 120  $report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
 121  $numusers = $report->get_numusers(true, true);
 122  
 123  // make sure separate group does not prevent view
 124  if ($report->currentgroup == -2) {
 125      echo $OUTPUT->heading(get_string("notingroup"));
 126      echo $OUTPUT->footer();
 127      exit;
 128  }
 129  
 130  $warnings = [];
 131  $isediting = has_capability('moodle/grade:edit', $context) && isset($USER->editing) && $USER->editing;
 132  if ($isediting && ($data = data_submitted()) && confirm_sesskey()) {
 133      // Processing posted grades & feedback here.
 134      $warnings = $report->process_data($data);
 135  }
 136  
 137  // Final grades MUST be loaded after the processing.
 138  $report->load_users();
 139  $report->load_final_grades();
 140  echo $report->group_selector;
 141  
 142  // User search
 143  $url = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id));
 144  $firstinitial = $SESSION->gradereport["filterfirstname-{$context->id}"] ?? '';
 145  $lastinitial  = $SESSION->gradereport["filtersurname-{$context->id}"] ?? '';
 146  $totalusers = $report->get_numusers(true, false);
 147  $renderer = $PAGE->get_renderer('core_user');
 148  echo $renderer->user_search($url, $firstinitial, $lastinitial, $numusers, $totalusers, $report->currentgroupname);
 149  
 150  //show warnings if any
 151  foreach ($warnings as $warning) {
 152      echo $OUTPUT->notification($warning);
 153  }
 154  
 155  $studentsperpage = $report->get_students_per_page();
 156  // Don't use paging if studentsperpage is empty or 0 at course AND site levels
 157  if (!empty($studentsperpage)) {
 158      echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
 159  }
 160  
 161  $displayaverages = true;
 162  if ($numusers == 0) {
 163      $displayaverages = false;
 164  }
 165  
 166  $reporthtml = $report->get_grade_table($displayaverages);
 167  
 168  // print submit button
 169  if (!empty($USER->editing) && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading'))) {
 170      echo '<form action="index.php" enctype="application/x-www-form-urlencoded" method="post" id="gradereport_grader">'; // Enforce compatibility with our max_input_vars hack.
 171      echo '<div>';
 172      echo '<input type="hidden" value="'.s($courseid).'" name="id" />';
 173      echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
 174      echo '<input type="hidden" value="'.time().'" name="timepageload" />';
 175      echo '<input type="hidden" value="grader" name="report"/>';
 176      echo '<input type="hidden" value="'.$page.'" name="page"/>';
 177      echo $gpr->get_form_fields();
 178      echo $reporthtml;
 179      echo '<div class="submit"><input type="submit" id="gradersubmit" class="btn btn-primary"
 180          value="'.s(get_string('savechanges')).'" /></div>';
 181      echo '</div></form>';
 182  } else {
 183      echo $reporthtml;
 184  }
 185  
 186  // prints paging bar at bottom for large pages
 187  if (!empty($studentsperpage) && $studentsperpage >= 20) {
 188      echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
 189  }
 190  
 191  $event = \gradereport_grader\event\grade_report_viewed::create(
 192      array(
 193          'context' => $context,
 194          'courseid' => $courseid,
 195      )
 196  );
 197  $event->trigger();
 198  
 199  echo $OUTPUT->footer();