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   * Displays the Single view
  19   *
  20   * @package   gradereport_singleview
  21   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  define('NO_OUTPUT_BUFFERING', true);
  26  
  27  require_once('../../../config.php');
  28  require_once($CFG->dirroot.'/lib/gradelib.php');
  29  require_once($CFG->dirroot.'/grade/lib.php');
  30  require_once($CFG->dirroot.'/grade/report/singleview/lib.php');
  31  
  32  $courseid = required_param('id', PARAM_INT);
  33  $groupid  = optional_param('group', null, PARAM_INT);
  34  
  35  // Making this work with profile reports.
  36  $userid   = optional_param('userid', null, PARAM_INT);
  37  
  38  $defaulttype = $userid ? 'user' : 'select';
  39  
  40  $itemid = optional_param('itemid', null, PARAM_INT);
  41  $itemtype = optional_param('item', $defaulttype, PARAM_TEXT);
  42  $page = optional_param('page', 0, PARAM_INT);
  43  $perpage = optional_param('perpage', 100, PARAM_INT);
  44  
  45  if (empty($itemid)) {
  46      $itemid = $userid;
  47      $itemtype = $defaulttype;
  48  }
  49  
  50  $courseparams = array('id' => $courseid);
  51  $pageparams = array(
  52          'id'        => $courseid,
  53          'group'     => $groupid,
  54          'userid'    => $userid,
  55          'itemid'    => $itemid,
  56          'item'      => $itemtype,
  57          'page'      => $page,
  58          'perpage'   => $perpage,
  59      );
  60  $PAGE->set_url(new moodle_url('/grade/report/singleview/index.php', $pageparams));
  61  $PAGE->set_pagelayout('incourse');
  62  
  63  if (!$course = $DB->get_record('course', $courseparams)) {
  64      print_error('invalidcourseid');
  65  }
  66  
  67  require_login($course);
  68  
  69  if (!in_array($itemtype, gradereport_singleview::valid_screens())) {
  70      print_error('notvalid', 'gradereport_singleview', '', $itemtype);
  71  }
  72  
  73  $context = context_course::instance($course->id);
  74  
  75  // This is the normal requirements.
  76  require_capability('gradereport/singleview:view', $context);
  77  require_capability('moodle/grade:viewall', $context);
  78  require_capability('moodle/grade:edit', $context);
  79  
  80  $gpr = new grade_plugin_return(array(
  81      'type' => 'report',
  82      'plugin' => 'singleview',
  83      'courseid' => $courseid
  84  ));
  85  
  86  // Last selected report session tracking.
  87  if (!isset($USER->grade_last_report)) {
  88      $USER->grade_last_report = array();
  89  }
  90  $USER->grade_last_report[$course->id] = 'singleview';
  91  
  92  // First make sure we have proper final grades.
  93  grade_regrade_final_grades_if_required($course);
  94  
  95  $report = new gradereport_singleview($courseid, $gpr, $context, $itemtype, $itemid);
  96  
  97  $reportname = $report->screen->heading();
  98  
  99  $pluginname = get_string('pluginname', 'gradereport_singleview');
 100  
 101  $pageparams = array(
 102      'id' => $courseid,
 103      'itemid' => $itemid,
 104      'item' => $itemtype,
 105      'userid' => $userid,
 106      'group' => $groupid,
 107      'page' => $page,
 108      'perpage' => $perpage
 109  );
 110  
 111  $currentpage = new moodle_url('/grade/report/singleview/index.php', $pageparams);
 112  
 113  if ($data = data_submitted()) {
 114      $PAGE->set_pagelayout('redirect');
 115      $PAGE->set_title(get_string('savegrades', 'gradereport_singleview'));
 116      echo $OUTPUT->header();
 117  
 118      require_sesskey(); // Must have a sesskey for all actions.
 119      $result = $report->process_data($data);
 120  
 121      if (!empty($result->warnings)) {
 122          foreach ($result->warnings as $warning) {
 123              echo $OUTPUT->notification($warning);
 124          }
 125      }
 126      echo $OUTPUT->notification(
 127          get_string('savegradessuccess', 'gradereport_singleview', count ((array)$result->changecount)),
 128          'success'
 129      );
 130      echo $OUTPUT->continue_button($currentpage);
 131      echo $OUTPUT->footer();
 132      die();
 133  }
 134  
 135  $PAGE->set_pagelayout('report');
 136  if ($itemtype == 'user') {
 137      print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, false, true, null, null, $report->screen->item);
 138  } else {
 139      print_grade_page_head($course->id, 'report', 'singleview', $reportname);
 140  }
 141  
 142  $graderrightnav = $graderleftnav = null;
 143  
 144  $options = $report->screen->options();
 145  
 146  if (!empty($options)) {
 147  
 148      $optionkeys = array_keys($options);
 149      $optionitemid = array_shift($optionkeys);
 150  
 151      $relreport = new gradereport_singleview(
 152                  $courseid, $gpr, $context,
 153                  $report->screen->item_type(), $optionitemid
 154      );
 155      $reloptions = $relreport->screen->options();
 156      $reloptionssorting = array_keys($relreport->screen->options());
 157  
 158      $i = array_search($itemid, $reloptionssorting);
 159      $navparams = array('item' => $itemtype, 'id' => $courseid, 'group' => $groupid);
 160      if ($i > 0) {
 161          $navparams['itemid'] = $reloptionssorting[$i - 1];
 162          $link = new moodle_url('/grade/report/singleview/index.php', $navparams);
 163          $navprev = html_writer::link($link, $OUTPUT->larrow() . ' ' . $reloptions[$reloptionssorting[$i - 1]]);
 164          $graderleftnav = html_writer::tag('div', $navprev, array('class' => 'itemnav previtem'));
 165      }
 166      if ($i < count($reloptionssorting) - 1) {
 167          $navparams['itemid'] = $reloptionssorting[$i + 1];
 168          $link = new moodle_url('/grade/report/singleview/index.php', $navparams);
 169          $navnext = html_writer::link($link, $reloptions[$reloptionssorting[$i + 1]] . ' ' . $OUTPUT->rarrow());
 170          $graderrightnav = html_writer::tag('div', $navnext, array('class' => 'itemnav nextitem'));
 171      }
 172  }
 173  
 174  if (!is_null($graderleftnav)) {
 175      echo $graderleftnav;
 176  }
 177  if (!is_null($graderrightnav)) {
 178      echo $graderrightnav;
 179  }
 180  
 181  if ($report->screen->supports_paging()) {
 182      echo $report->screen->pager();
 183  }
 184  
 185  if ($report->screen->display_group_selector()) {
 186      echo $report->group_selector;
 187  }
 188  
 189  echo $report->output();
 190  
 191  if ($report->screen->supports_paging()) {
 192      echo $report->screen->perpage_select();
 193      echo $report->screen->pager();
 194  }
 195  
 196  if (!is_null($graderleftnav)) {
 197      echo $graderleftnav;
 198  }
 199  if (!is_null($graderrightnav)) {
 200      echo $graderrightnav;
 201  }
 202  
 203  $event = \gradereport_singleview\event\grade_report_viewed::create(
 204      array(
 205          'context' => $context,
 206          'courseid' => $courseid,
 207          'relateduserid' => $USER->id,
 208      )
 209  );
 210  $event->trigger();
 211  
 212  echo $OUTPUT->footer();