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   * 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      print_error('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  $returnurl = $CFG->wwwroot.'/grade/index.php?id='.$course->id;
  49  
  50  $mform = new course_settings_form();
  51  
  52  $settings = grade_get_settings($course->id);
  53  
  54  $mform->set_data($settings);
  55  
  56  if ($mform->is_cancelled()) {
  57      redirect($returnurl);
  58  
  59  } else if ($data = $mform->get_data()) {
  60      $data = (array)$data;
  61      $general = array('displaytype', 'decimalpoints', 'aggregationposition', 'minmaxtouse');
  62      foreach ($data as $key=>$value) {
  63          if (!in_array($key, $general) and strpos($key, 'report_') !== 0
  64                                        and strpos($key, 'import_') !== 0
  65                                        and strpos($key, 'export_') !== 0) {
  66              continue;
  67          }
  68          if ($value == -1) {
  69              $value = null;
  70          }
  71          grade_set_setting($course->id, $key, $value);
  72  
  73          $previousvalue = isset($settings->{$key}) ? $settings->{$key} : null;
  74          if ($key == 'minmaxtouse' && $previousvalue != $value) {
  75              // The min max has changed, we need to regrade the grades.
  76              grade_force_full_regrading($courseid);
  77          }
  78      }
  79  
  80      redirect($returnurl);
  81  }
  82  
  83  print_grade_page_head($courseid, 'settings', 'coursesettings', get_string('coursegradesettings', 'grades'));
  84  
  85  // The settings could have been changed due to a notice shown in print_grade_page_head, we need to refresh them.
  86  $settings = grade_get_settings($course->id);
  87  $mform->set_data($settings);
  88  
  89  echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal centerpara');
  90  echo get_string('coursesettingsexplanation', 'grades');
  91  echo $OUTPUT->box_end();
  92  
  93  $mform->display();
  94  
  95  echo $OUTPUT->footer();
  96  
  97