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 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   * A page for editing course grade settings
  19   *
  20   * @package   core_grades
  21   * @copyright 2007 Petr Skoda
  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->dirroot.'/grade/lib.php';
  27  require_once $CFG->libdir.'/gradelib.php';
  28  require_once  'form.php';
  29  
  30  $courseid  = optional_param('id', SITEID, PARAM_INT);
  31  
  32  $PAGE->set_url('/grade/edit/settings/index.php', array('id'=>$courseid));
  33  $PAGE->set_pagelayout('admin');
  34  
  35  if (!$course = $DB->get_record('course', array('id' => $courseid))) {
  36      throw new \moodle_exception('invalidcourseid');
  37  }
  38  require_login($course);
  39  $context = context_course::instance($course->id);
  40  
  41  require_capability('moodle/grade:manage', $context);
  42  
  43  $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'settings', 'courseid'=>$courseid));
  44  
  45  $strgrades = get_string('grades');
  46  $pagename  = get_string('coursesettings', 'grades');
  47  
  48  $mform = new course_settings_form();
  49  
  50  $settings = grade_get_settings($course->id);
  51  
  52  $mform->set_data($settings);
  53  
  54  if ($data = $mform->get_data()) {
  55      $data = (array)$data;
  56      $general = array('displaytype', 'decimalpoints', 'aggregationposition', 'minmaxtouse');
  57      foreach ($data as $key=>$value) {
  58          if (!in_array($key, $general) and strpos($key, 'report_') !== 0
  59                                        and strpos($key, 'import_') !== 0
  60                                        and strpos($key, 'export_') !== 0) {
  61              continue;
  62          }
  63          if ($value == -1) {
  64              $value = null;
  65          }
  66          grade_set_setting($course->id, $key, $value);
  67  
  68          $previousvalue = isset($settings->{$key}) ? $settings->{$key} : null;
  69          if ($key == 'minmaxtouse' && $previousvalue != $value) {
  70              // The min max has changed, we need to regrade the grades.
  71              grade_force_full_regrading($courseid);
  72          }
  73      }
  74  }
  75  
  76  print_grade_page_head($courseid, 'settings', 'coursesettings', get_string('coursegradesettings', 'grades'));
  77  
  78  // The settings could have been changed due to a notice shown in print_grade_page_head, we need to refresh them.
  79  $settings = grade_get_settings($course->id);
  80  $mform->set_data($settings);
  81  
  82  echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal centerpara');
  83  echo get_string('coursesettingsexplanation', 'grades');
  84  echo $OUTPUT->box_end();
  85  
  86  $mform->display();
  87  
  88  echo $OUTPUT->footer();
  89  
  90