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 401 and 402] [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   * Administration settings definitions for the quiz module.
  19   *
  20   * @package   mod_quiz
  21   * @copyright 2010 Petr Skoda
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once($CFG->dirroot . '/mod/quiz/lib.php');
  29  
  30  // First get a list of quiz reports with there own settings pages. If there none,
  31  // we use a simpler overall menu structure.
  32  $reports = core_component::get_plugin_list_with_file('quiz', 'settings.php', false);
  33  $reportsbyname = array();
  34  foreach ($reports as $report => $reportdir) {
  35      $strreportname = get_string($report . 'report', 'quiz_'.$report);
  36      $reportsbyname[$strreportname] = $report;
  37  }
  38  core_collator::ksort($reportsbyname);
  39  
  40  // First get a list of quiz reports with there own settings pages. If there none,
  41  // we use a simpler overall menu structure.
  42  $rules = core_component::get_plugin_list_with_file('quizaccess', 'settings.php', false);
  43  $rulesbyname = array();
  44  foreach ($rules as $rule => $ruledir) {
  45      $strrulename = get_string('pluginname', 'quizaccess_' . $rule);
  46      $rulesbyname[$strrulename] = $rule;
  47  }
  48  core_collator::ksort($rulesbyname);
  49  
  50  // Create the quiz settings page.
  51  if (empty($reportsbyname) && empty($rulesbyname)) {
  52      $pagetitle = get_string('modulename', 'quiz');
  53  } else {
  54      $pagetitle = get_string('generalsettings', 'admin');
  55  }
  56  $quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site:config');
  57  
  58  if ($ADMIN->fulltree) {
  59      // Introductory explanation that all the settings are defaults for the add quiz form.
  60      $quizsettings->add(new admin_setting_heading('quizintro', '', get_string('configintro', 'quiz')));
  61  
  62      // Time limit.
  63      $setting = new admin_setting_configduration('quiz/timelimit',
  64              get_string('timelimit', 'quiz'), get_string('configtimelimitsec', 'quiz'),
  65              '0', 60);
  66      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, false);
  67      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
  68      $quizsettings->add($setting);
  69  
  70      // Delay to notify graded attempts.
  71      $quizsettings->add(new admin_setting_configduration('quiz/notifyattemptgradeddelay',
  72          get_string('attemptgradeddelay', 'quiz'), get_string('attemptgradeddelay_desc', 'quiz'), 5 * HOURSECS, HOURSECS));
  73  
  74      // What to do with overdue attempts.
  75      $setting = new mod_quiz_admin_setting_overduehandling('quiz/overduehandling',
  76              get_string('overduehandling', 'quiz'), get_string('overduehandling_desc', 'quiz'),
  77              array('value' => 'autosubmit', 'adv' => false), null);
  78      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
  79      $quizsettings->add($setting);
  80  
  81      // Grace period time.
  82      $setting = new admin_setting_configduration('quiz/graceperiod',
  83              get_string('graceperiod', 'quiz'), get_string('graceperiod_desc', 'quiz'),
  84              '86400');
  85      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, false);
  86      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
  87      $quizsettings->add($setting);
  88  
  89      // Minimum grace period used behind the scenes.
  90      $quizsettings->add(new admin_setting_configduration('quiz/graceperiodmin',
  91              get_string('graceperiodmin', 'quiz'), get_string('graceperiodmin_desc', 'quiz'),
  92              60, 1));
  93  
  94      // Number of attempts.
  95      $options = array(get_string('unlimited'));
  96      for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) {
  97          $options[$i] = $i;
  98      }
  99      $setting = new admin_setting_configselect('quiz/attempts',
 100              get_string('attemptsallowed', 'quiz'), get_string('configattemptsallowed', 'quiz'),
 101              0, $options);
 102      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, false);
 103      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 104      $quizsettings->add($setting);
 105  
 106      // Grading method.
 107      $setting = new mod_quiz_admin_setting_grademethod('quiz/grademethod',
 108              get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'),
 109              array('value' => QUIZ_GRADEHIGHEST, 'adv' => false), null);
 110      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 111      $quizsettings->add($setting);
 112  
 113      // Maximum grade.
 114      $setting = new admin_setting_configtext('quiz/maximumgrade',
 115              get_string('maximumgrade'), get_string('configmaximumgrade', 'quiz'), 10, PARAM_INT);
 116      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 117      $quizsettings->add($setting);
 118  
 119      // Questions per page.
 120      $perpage = array();
 121      $perpage[0] = get_string('never');
 122      $perpage[1] = get_string('aftereachquestion', 'quiz');
 123      for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) {
 124          $perpage[$i] = get_string('afternquestions', 'quiz', $i);
 125      }
 126      $setting = new admin_setting_configselect('quiz/questionsperpage',
 127              get_string('newpageevery', 'quiz'), get_string('confignewpageevery', 'quiz'),
 128              1, $perpage);
 129      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, false);
 130      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 131      $quizsettings->add($setting);
 132  
 133      // Navigation method.
 134      $setting = new admin_setting_configselect('quiz/navmethod',
 135              get_string('navmethod', 'quiz'), get_string('confignavmethod', 'quiz'),
 136              QUIZ_NAVMETHOD_FREE, quiz_get_navigation_options());
 137      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, true);
 138      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 139      $quizsettings->add($setting);
 140  
 141      // Shuffle within questions.
 142      $setting = new admin_setting_configcheckbox('quiz/shuffleanswers',
 143              get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'),
 144              1);
 145      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, false);
 146      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 147      $quizsettings->add($setting);
 148  
 149      // Preferred behaviour.
 150      $setting = new admin_setting_question_behaviour('quiz/preferredbehaviour',
 151              get_string('howquestionsbehave', 'question'), get_string('howquestionsbehave_desc', 'quiz'),
 152              'deferredfeedback');
 153      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 154      $quizsettings->add($setting);
 155  
 156      // Can redo completed questions.
 157      $setting = new admin_setting_configselect('quiz/canredoquestions',
 158              get_string('canredoquestions', 'quiz'), get_string('canredoquestions_desc', 'quiz'),
 159              0,
 160              array(0 => get_string('no'), 1 => get_string('canredoquestionsyes', 'quiz')));
 161      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, true);
 162      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 163      $quizsettings->add($setting);
 164  
 165      // Each attempt builds on last.
 166      $setting = new admin_setting_configcheckbox('quiz/attemptonlast',
 167              get_string('eachattemptbuildsonthelast', 'quiz'),
 168              get_string('configeachattemptbuildsonthelast', 'quiz'),
 169              0);
 170      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, true);
 171      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 172      $quizsettings->add($setting);
 173  
 174      // Review options.
 175      $quizsettings->add(new admin_setting_heading('reviewheading',
 176              get_string('reviewoptionsheading', 'quiz'), ''));
 177      foreach (mod_quiz_admin_review_setting::fields() as $field => $name) {
 178          $default = mod_quiz_admin_review_setting::all_on();
 179          $forceduring = null;
 180          if ($field == 'attempt') {
 181              $forceduring = true;
 182          } else if ($field == 'overallfeedback') {
 183              $default = $default ^ mod_quiz_admin_review_setting::DURING;
 184              $forceduring = false;
 185          }
 186          $quizsettings->add(new mod_quiz_admin_review_setting('quiz/review' . $field,
 187                  $name, '', $default, $forceduring));
 188      }
 189  
 190      // Show the user's picture.
 191      $setting = new mod_quiz_admin_setting_user_image('quiz/showuserpicture',
 192              get_string('showuserpicture', 'quiz'), get_string('configshowuserpicture', 'quiz'),
 193              array('value' => 0, 'adv' => false), null);
 194      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 195      $quizsettings->add($setting);
 196  
 197      // Decimal places for overall grades.
 198      $options = array();
 199      for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION; $i++) {
 200          $options[$i] = $i;
 201      }
 202      $setting = new admin_setting_configselect('quiz/decimalpoints',
 203              get_string('decimalplaces', 'quiz'), get_string('configdecimalplaces', 'quiz'),
 204              2, $options);
 205      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, false);
 206      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 207      $quizsettings->add($setting);
 208  
 209      // Decimal places for question grades.
 210      $options = array(-1 => get_string('sameasoverall', 'quiz'));
 211      for ($i = 0; $i <= QUIZ_MAX_Q_DECIMAL_OPTION; $i++) {
 212          $options[$i] = $i;
 213      }
 214      $setting = new admin_setting_configselect('quiz/questiondecimalpoints',
 215              get_string('decimalplacesquestion', 'quiz'),
 216              get_string('configdecimalplacesquestion', 'quiz'),
 217              -1, $options);
 218      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, false);
 219      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 220      $quizsettings->add($setting);
 221  
 222      // Show blocks during quiz attempts.
 223      $setting = new admin_setting_configcheckbox('quiz/showblocks',
 224              get_string('showblocks', 'quiz'), get_string('configshowblocks', 'quiz'),
 225              0);
 226      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, true);
 227      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 228      $quizsettings->add($setting);
 229  
 230      // Password.
 231      $setting = new admin_setting_configpasswordunmask('quiz/quizpassword',
 232              get_string('requirepassword', 'quiz'), get_string('configrequirepassword', 'quiz'),
 233              '');
 234      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, false);
 235      $setting->set_required_flag_options(admin_setting_flag::ENABLED, false);
 236      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 237      $quizsettings->add($setting);
 238  
 239      // IP restrictions.
 240      $setting = new admin_setting_configtext('quiz/subnet',
 241              get_string('requiresubnet', 'quiz'), get_string('configrequiresubnet', 'quiz'),
 242              '', PARAM_TEXT);
 243      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, true);
 244      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 245      $quizsettings->add($setting);
 246  
 247      // Enforced delay between attempts.
 248      $setting = new admin_setting_configduration('quiz/delay1',
 249              get_string('delay1st2nd', 'quiz'), get_string('configdelay1st2nd', 'quiz'),
 250              0, 60);
 251      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, true);
 252      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 253      $quizsettings->add($setting);
 254      $setting = new admin_setting_configduration('quiz/delay2',
 255              get_string('delaylater', 'quiz'), get_string('configdelaylater', 'quiz'),
 256              0, 60);
 257      $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, true);
 258      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 259      $quizsettings->add($setting);
 260  
 261      // Browser security.
 262      $setting = new mod_quiz_admin_setting_browsersecurity('quiz/browsersecurity',
 263              get_string('showinsecurepopup', 'quiz'), get_string('configpopup', 'quiz'),
 264              array('value' => '-', 'adv' => true), null);
 265      $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false);
 266      $quizsettings->add($setting);
 267  
 268      $quizsettings->add(new admin_setting_configtext('quiz/initialnumfeedbacks',
 269              get_string('initialnumfeedbacks', 'quiz'), get_string('initialnumfeedbacks_desc', 'quiz'),
 270              2, PARAM_INT, 5));
 271  
 272      // Allow user to specify if setting outcomes is an advanced setting.
 273      if (!empty($CFG->enableoutcomes)) {
 274          $quizsettings->add(new admin_setting_configcheckbox('quiz/outcomes_adv',
 275              get_string('outcomesadvanced', 'quiz'), get_string('configoutcomesadvanced', 'quiz'),
 276              '0'));
 277      }
 278  
 279      // Autosave frequency.
 280      $quizsettings->add(new admin_setting_configduration('quiz/autosaveperiod',
 281              get_string('autosaveperiod', 'quiz'), get_string('autosaveperiod_desc', 'quiz'), 60, 1));
 282  }
 283  
 284  // Now, depending on whether any reports have their own settings page, add
 285  // the quiz setting page to the appropriate place in the tree.
 286  if (empty($reportsbyname) && empty($rulesbyname)) {
 287      $ADMIN->add('modsettings', $quizsettings);
 288  } else {
 289      $ADMIN->add('modsettings', new admin_category('modsettingsquizcat',
 290              get_string('modulename', 'quiz'), $module->is_enabled() === false));
 291      $ADMIN->add('modsettingsquizcat', $quizsettings);
 292  
 293      // Add settings pages for the quiz report subplugins.
 294      foreach ($reportsbyname as $strreportname => $report) {
 295          $reportname = $report;
 296  
 297          $settings = new admin_settingpage('modsettingsquizcat'.$reportname,
 298                  $strreportname, 'moodle/site:config', $module->is_enabled() === false);
 299          include($CFG->dirroot . "/mod/quiz/report/$reportname/settings.php");
 300          if (!empty($settings)) {
 301              $ADMIN->add('modsettingsquizcat', $settings);
 302          }
 303      }
 304  
 305      // Add settings pages for the quiz access rule subplugins.
 306      foreach ($rulesbyname as $strrulename => $rule) {
 307          $settings = new admin_settingpage('modsettingsquizcat' . $rule,
 308                  $strrulename, 'moodle/site:config', $module->is_enabled() === false);
 309          include($CFG->dirroot . "/mod/quiz/accessrule/$rule/settings.php");
 310          if (!empty($settings)) {
 311              $ADMIN->add('modsettingsquizcat', $settings);
 312          }
 313      }
 314  }
 315  
 316  $settings = null; // We do not want standard settings link.