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 310 and 311] [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   * 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_ALPHANUM); // sort by which grade item
  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->requires->yui_module('moodle-gradereport_grader-gradereporttable', 'Y.M.gradereport_grader.init', null, null, true);
  48  
  49  // basic access checks
  50  if (!$course = $DB->get_record('course', array('id' => $courseid))) {
  51      print_error('invalidcourseid');
  52  }
  53  require_login($course);
  54  $context = context_course::instance($course->id);
  55  
  56  // The report object is recreated each time, save search information to SESSION object for future use.
  57  if (isset($graderreportsifirst)) {
  58      $SESSION->gradereport["filterfirstname-{$context->id}"] = $graderreportsifirst;
  59  }
  60  if (isset($graderreportsilast)) {
  61      $SESSION->gradereport["filtersurname-{$context->id}"] = $graderreportsilast;
  62  }
  63  
  64  require_capability('gradereport/grader:view', $context);
  65  require_capability('moodle/grade:viewall', $context);
  66  
  67  // return tracking object
  68  $gpr = new grade_plugin_return(
  69      array(
  70          'type' => 'report',
  71          'plugin' => 'grader',
  72          'course' => $course,
  73          'page' => $page
  74      )
  75  );
  76  
  77  // last selected report session tracking
  78  if (!isset($USER->grade_last_report)) {
  79      $USER->grade_last_report = array();
  80  }
  81  $USER->grade_last_report[$course->id] = 'grader';
  82  
  83  // Build editing on/off buttons
  84  
  85  if (!isset($USER->gradeediting)) {
  86      $USER->gradeediting = array();
  87  }
  88  
  89  if (has_capability('moodle/grade:edit', $context)) {
  90      if (!isset($USER->gradeediting[$course->id])) {
  91          $USER->gradeediting[$course->id] = 0;
  92      }
  93  
  94      if (($edit == 1) and confirm_sesskey()) {
  95          $USER->gradeediting[$course->id] = 1;
  96      } else if (($edit == 0) and confirm_sesskey()) {
  97          $USER->gradeediting[$course->id] = 0;
  98      }
  99  
 100      // page params for the turn editting on
 101      $options = $gpr->get_options();
 102      $options['sesskey'] = sesskey();
 103  
 104      if ($USER->gradeediting[$course->id]) {
 105          $options['edit'] = 0;
 106          $string = get_string('turneditingoff');
 107      } else {
 108          $options['edit'] = 1;
 109          $string = get_string('turneditingon');
 110      }
 111  
 112      $buttons = new single_button(new moodle_url('index.php', $options), $string, 'get');
 113  } else {
 114      $USER->gradeediting[$course->id] = 0;
 115      $buttons = '';
 116  }
 117  
 118  $gradeserror = array();
 119  
 120  // Handle toggle change request
 121  if (!is_null($toggle) && !empty($toggle_type)) {
 122      set_user_preferences(array('grade_report_show'.$toggle_type => $toggle));
 123  }
 124  
 125  // Perform actions
 126  if (!empty($target) && !empty($action) && confirm_sesskey()) {
 127      grade_report_grader::do_process_action($target, $action, $courseid);
 128  }
 129  
 130  $reportname = get_string('pluginname', 'gradereport_grader');
 131  
 132  // Do this check just before printing the grade header (and only do it once).
 133  grade_regrade_final_grades_if_required($course);
 134  
 135  // Print header
 136  print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $buttons);
 137  
 138  //Initialise the grader report object that produces the table
 139  //the class grade_report_grader_ajax was removed as part of MDL-21562
 140  $report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
 141  $numusers = $report->get_numusers(true, true);
 142  
 143  // make sure separate group does not prevent view
 144  if ($report->currentgroup == -2) {
 145      echo $OUTPUT->heading(get_string("notingroup"));
 146      echo $OUTPUT->footer();
 147      exit;
 148  }
 149  
 150  // processing posted grades & feedback here
 151  if ($data = data_submitted() and confirm_sesskey() and has_capability('moodle/grade:edit', $context)) {
 152      $warnings = $report->process_data($data);
 153  } else {
 154      $warnings = array();
 155  }
 156  
 157  // final grades MUST be loaded after the processing
 158  $report->load_users();
 159  $report->load_final_grades();
 160  echo $report->group_selector;
 161  
 162  // User search
 163  $url = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id));
 164  $firstinitial = $SESSION->gradereport["filterfirstname-{$context->id}"] ?? '';
 165  $lastinitial  = $SESSION->gradereport["filtersurname-{$context->id}"] ?? '';
 166  $totalusers = $report->get_numusers(true, false);
 167  $renderer = $PAGE->get_renderer('core_user');
 168  echo $renderer->user_search($url, $firstinitial, $lastinitial, $numusers, $totalusers, $report->currentgroupname);
 169  
 170  //show warnings if any
 171  foreach ($warnings as $warning) {
 172      echo $OUTPUT->notification($warning);
 173  }
 174  
 175  $studentsperpage = $report->get_students_per_page();
 176  // Don't use paging if studentsperpage is empty or 0 at course AND site levels
 177  if (!empty($studentsperpage)) {
 178      echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
 179  }
 180  
 181  $displayaverages = true;
 182  if ($numusers == 0) {
 183      $displayaverages = false;
 184  }
 185  
 186  $reporthtml = $report->get_grade_table($displayaverages);
 187  
 188  // print submit button
 189  if ($USER->gradeediting[$course->id] && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading'))) {
 190      echo '<form action="index.php" enctype="application/x-www-form-urlencoded" method="post" id="gradereport_grader">'; // Enforce compatibility with our max_input_vars hack.
 191      echo '<div>';
 192      echo '<input type="hidden" value="'.s($courseid).'" name="id" />';
 193      echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
 194      echo '<input type="hidden" value="'.time().'" name="timepageload" />';
 195      echo '<input type="hidden" value="grader" name="report"/>';
 196      echo '<input type="hidden" value="'.$page.'" name="page"/>';
 197      echo $gpr->get_form_fields();
 198      echo $reporthtml;
 199      echo '<div class="submit"><input type="submit" id="gradersubmit" class="btn btn-primary"
 200          value="'.s(get_string('savechanges')).'" /></div>';
 201      echo '</div></form>';
 202  } else {
 203      echo $reporthtml;
 204  }
 205  
 206  // prints paging bar at bottom for large pages
 207  if (!empty($studentsperpage) && $studentsperpage >= 20) {
 208      echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
 209  }
 210  
 211  $event = \gradereport_grader\event\grade_report_viewed::create(
 212      array(
 213          'context' => $context,
 214          'courseid' => $courseid,
 215      )
 216  );
 217  $event->trigger();
 218  
 219  echo $OUTPUT->footer();