Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 form 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  if (!defined('MOODLE_INTERNAL')) {
  26      die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
  27  }
  28  
  29  require_once($CFG->libdir.'/formslib.php');
  30  
  31  /**
  32   * First implementation of the preferences in the form of a moodleform.
  33   * TODO add "reset to site defaults" button
  34   */
  35  class course_settings_form extends moodleform {
  36  
  37      function definition() {
  38          global $USER, $CFG;
  39  
  40          $mform =& $this->_form;
  41  
  42          $systemcontext = context_system::instance();
  43          $can_view_admin_links = false;
  44          if (has_capability('moodle/grade:manage', $systemcontext)) {
  45              $can_view_admin_links = true;
  46          }
  47  
  48          // General settings
  49          $strchangedefaults = get_string('changedefaults', 'grades');
  50          $mform->addElement('header', 'general', get_string('generalsettings', 'grades'));
  51          if ($can_view_admin_links) {
  52              $link = '<a href="' . $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=gradessettings">' . $strchangedefaults . '</a>';
  53              $mform->addElement('static', 'generalsettingslink', null, $link);
  54          }
  55          $options = array(-1                                      => get_string('default', 'grades'),
  56                           GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
  57                           GRADE_REPORT_AGGREGATION_POSITION_LAST  => get_string('positionlast', 'grades'));
  58          $default_gradedisplaytype = $CFG->grade_aggregationposition;
  59          foreach ($options as $key=>$option) {
  60              if ($key == $default_gradedisplaytype) {
  61                  $options[-1] = get_string('defaultprev', 'grades', $option);
  62                  break;
  63              }
  64          }
  65          $mform->addElement('select', 'aggregationposition', get_string('aggregationposition', 'grades'), $options);
  66          $mform->addHelpButton('aggregationposition', 'aggregationposition', 'grades');
  67  
  68          if ($CFG->grade_minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_ITEM) {
  69              $default = get_string('gradeitemminmax', 'grades');
  70          } else if ($CFG->grade_minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE) {
  71              $default = get_string('gradegrademinmax', 'grades');
  72          } else {
  73              throw new coding_exception('Invalid $CFG->grade_minmaxtouse value.');
  74          }
  75  
  76          $options = array(
  77              -1 => get_string('defaultprev', 'grades', $default),
  78              GRADE_MIN_MAX_FROM_GRADE_ITEM => get_string('gradeitemminmax', 'grades'),
  79              GRADE_MIN_MAX_FROM_GRADE_GRADE => get_string('gradegrademinmax', 'grades')
  80          );
  81          $mform->addElement('select', 'minmaxtouse', get_string('minmaxtouse', 'grades'), $options);
  82          $mform->addHelpButton('minmaxtouse', 'minmaxtouse', 'grades');
  83  
  84          // Grade item settings
  85          $mform->addElement('header', 'grade_item_settings', get_string('gradeitemsettings', 'grades'));
  86          $mform->setExpanded('grade_item_settings');
  87          if ($can_view_admin_links) {
  88              $link = '<a href="' . $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=gradeitemsettings">' . $strchangedefaults . '</a>';
  89              $mform->addElement('static', 'gradeitemsettingslink', null, $link);
  90          }
  91  
  92          $options = array(-1                            => get_string('default', 'grades'),
  93                           GRADE_DISPLAY_TYPE_REAL       => get_string('real', 'grades'),
  94                           GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'),
  95                           GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'),
  96                           GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
  97                           GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades'),
  98                           GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'),
  99                           GRADE_DISPLAY_TYPE_LETTER     => get_string('letter', 'grades'),
 100                           GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'),
 101                           GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'));
 102  
 103          $default_gradedisplaytype = $CFG->grade_displaytype;
 104          foreach ($options as $key=>$option) {
 105              if ($key == $default_gradedisplaytype) {
 106                  $options[-1] = get_string('defaultprev', 'grades', $option);
 107                  break;
 108              }
 109          }
 110          $mform->addElement('select', 'displaytype', get_string('gradedisplaytype', 'grades'), $options);
 111          $mform->addHelpButton('displaytype', 'gradedisplaytype', 'grades');
 112          $mform->setDefault('displaytype', -1);
 113  
 114          $options = array(-1=> get_string('defaultprev', 'grades', $CFG->grade_decimalpoints), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
 115          $mform->addElement('select', 'decimalpoints', get_string('decimalpoints', 'grades'), $options);
 116          $mform->addHelpButton('decimalpoints', 'decimalpoints', 'grades');
 117  
 118  // add setting options for plugins
 119          $types = array('report', 'export', 'import');
 120  
 121          foreach($types as $type) {
 122              foreach (core_component::get_plugin_list('grade'.$type) as $plugin => $plugindir) {
 123               // Include all the settings commands for this plugin if there are any
 124                  if (file_exists($plugindir.'/lib.php')) {
 125                      require_once($plugindir.'/lib.php');
 126                      $functionname = 'grade_'.$type.'_'.$plugin.'_settings_definition';
 127                      if (function_exists($functionname)) {
 128                          $mform->addElement('header', 'grade_'.$type.$plugin, get_string('pluginname', 'grade'.$type.'_'.$plugin, NULL));
 129                          $mform->setExpanded('grade_'.$type.$plugin);
 130                          if ($can_view_admin_links) {
 131                              $link = '<a href="' . $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=gradereport' . $plugin . '">' . $strchangedefaults . '</a>';
 132                              $mform->addElement('static', 'gradeitemsettingslink', null, $link);
 133                          }
 134                          $functionname($mform);
 135                      }
 136                  }
 137              }
 138          }
 139  
 140          $mform->addElement('hidden', 'id');
 141          $mform->setType('id', PARAM_INT);
 142  
 143          $this->add_action_buttons();
 144      }
 145  }
 146