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 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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 overview report
  19   *
  20   * @package   gradereport_overview
  21   * @copyright 2007 Nicolas Connault
  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.'/grade/lib.php';
  28  require_once $CFG->dirroot.'/grade/report/overview/lib.php';
  29  
  30  $courseid = optional_param('id', SITEID, PARAM_INT);
  31  $userid   = optional_param('userid', $USER->id, PARAM_INT);
  32  
  33  $PAGE->set_url(new moodle_url('/grade/report/overview/index.php', array('id' => $courseid, 'userid' => $userid)));
  34  
  35  if (!$course = $DB->get_record('course', array('id' => $courseid))) {
  36      print_error('invalidcourseid');
  37  }
  38  require_login(null, false);
  39  $PAGE->set_course($course);
  40  
  41  $context = context_course::instance($course->id);
  42  $systemcontext = context_system::instance();
  43  $personalcontext = null;
  44  
  45  // If we are accessing the page from a site context then ignore this check.
  46  if ($courseid != SITEID) {
  47      require_capability('gradereport/overview:view', $context);
  48  }
  49  
  50  if (empty($userid)) {
  51      require_capability('moodle/grade:viewall', $context);
  52  
  53  } else {
  54      if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) {
  55          print_error('invaliduserid');
  56      }
  57      $personalcontext = context_user::instance($userid);
  58  }
  59  
  60  if (isset($personalcontext) && $courseid == SITEID) {
  61      $PAGE->set_context($personalcontext);
  62  } else {
  63      $PAGE->set_context($context);
  64  }
  65  if ($userid == $USER->id) {
  66      $settings = $PAGE->settingsnav->find('mygrades', null);
  67      $settings->make_active();
  68  } else if ($courseid != SITEID && $userid) {
  69      // Show some other navbar thing.
  70      $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
  71      $PAGE->navigation->extend_for_user($user);
  72  }
  73  
  74  $access = grade_report_overview::check_access($systemcontext, $context, $personalcontext, $course, $userid);
  75  
  76  if (!$access) {
  77      // no access to grades!
  78      print_error('nopermissiontoviewgrades', 'error',  $CFG->wwwroot.'/course/view.php?id='.$courseid);
  79  }
  80  
  81  /// return tracking object
  82  $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid));
  83  
  84  /// last selected report session tracking
  85  if (!isset($USER->grade_last_report)) {
  86      $USER->grade_last_report = array();
  87  }
  88  $USER->grade_last_report[$course->id] = 'overview';
  89  
  90  // First make sure we have proper final grades.
  91  grade_regrade_final_grades_if_required($course);
  92  
  93  if (has_capability('moodle/grade:viewall', $context) && $courseid != SITEID) {
  94      // Please note this would be extremely slow if we wanted to implement this properly for all teachers.
  95      $groupmode    = groups_get_course_groupmode($course);   // Groups are being used
  96      $currentgroup = $gpr->groupid;
  97  
  98      if (!$currentgroup) {      // To make some other functions work better later
  99          $currentgroup = NULL;
 100      }
 101  
 102      $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
 103  
 104      if ($isseparategroups and (!$currentgroup)) {
 105          // no separate group access, can view only self
 106          $userid = $USER->id;
 107          $user_selector = false;
 108      } else {
 109          $user_selector = true;
 110      }
 111  
 112      if (empty($userid)) {
 113          // Add tabs
 114          print_grade_page_head($courseid, 'report', 'overview');
 115  
 116          groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
 117  
 118          if ($user_selector) {
 119              $renderer = $PAGE->get_renderer('gradereport_overview');
 120              echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false);
 121          }
 122          // do not list all users
 123  
 124      } else { // Only show one user's report
 125          $report = new grade_report_overview($userid, $gpr, $context);
 126          print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview') .
 127                  ' - ' . fullname($report->user), false, false, true, null, null, $report->user);
 128          groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
 129  
 130          if ($user_selector) {
 131              $renderer = $PAGE->get_renderer('gradereport_overview');
 132              echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false);
 133          }
 134  
 135          if ($currentgroup and !groups_is_member($currentgroup, $userid)) {
 136              echo $OUTPUT->notification(get_string('groupusernotmember', 'error'));
 137          } else {
 138              if ($report->fill_table()) {
 139                  echo '<br />'.$report->print_table(true);
 140              }
 141          }
 142      }
 143  } else { // Non-admins and users viewing from the site context can just see their own report.
 144  
 145      // Create a report instance
 146      $report = new grade_report_overview($userid, $gpr, $context);
 147  
 148      if (!empty($report->studentcourseids)) {
 149          // If the course id matches the site id then we don't have a course context to work with.
 150          // Display a standard page.
 151          if ($courseid == SITEID) {
 152              $PAGE->set_pagelayout('standard');
 153              $header = get_string('grades', 'grades') . ' - ' . fullname($report->user);
 154              $PAGE->set_title($header);
 155              $PAGE->set_heading(fullname($report->user));
 156  
 157              if ($USER->id != $report->user->id) {
 158                  $PAGE->navigation->extend_for_user($report->user);
 159                  if ($node = $PAGE->settingsnav->get('userviewingsettings'.$report->user->id)) {
 160                      $node->forceopen = true;
 161                  }
 162              } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) {
 163                  $node->forceopen = true;
 164              }
 165  
 166              echo $OUTPUT->header();
 167              if ($report->fill_table(true, true)) {
 168                  echo html_writer::tag('h3', get_string('coursesiamtaking', 'grades'));
 169                  echo '<br />' . $report->print_table(true);
 170              }
 171          } else { // We have a course context. We must be navigating from the gradebook.
 172              print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview')
 173                      . ' - ' . fullname($report->user));
 174              if ($report->fill_table()) {
 175                  echo '<br />' . $report->print_table(true);
 176              }
 177          }
 178      } else {
 179          $PAGE->set_pagelayout('standard');
 180          $header = get_string('grades', 'grades') . ' - ' . fullname($report->user);
 181          $PAGE->set_title($header);
 182          $PAGE->set_heading(fullname($report->user));
 183          echo $OUTPUT->header();
 184      }
 185  
 186      if (count($report->teachercourses)) {
 187          echo html_writer::tag('h3', get_string('coursesiamteaching', 'grades'));
 188          $report->print_teacher_table();
 189      }
 190  
 191      if (empty($report->studentcourseids) && empty($report->teachercourses)) {
 192          // We have no report to show the user. Let them know something.
 193          echo $OUTPUT->notification(get_string('noreports', 'grades'), 'notifymessage');
 194      }
 195  }
 196  
 197  grade_report_overview::viewed($context, $courseid, $userid);
 198  
 199  echo $OUTPUT->footer();