Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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   * This file defines the setting form for the quiz grading report.
  19   *
  20   * @package   quiz_grading
  21   * @copyright 2010 Tim Hunt
  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->libdir . '/formslib.php');
  29  
  30  
  31  /**
  32   * Quiz grading report settings form.
  33   *
  34   * @copyright 2010 Tim Hunt
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class quiz_grading_settings_form extends moodleform {
  38      protected $includeauto;
  39      protected $hidden = array();
  40      protected $counts;
  41      protected $shownames;
  42      protected $showidnumbers;
  43  
  44      public function __construct($hidden, $counts, $shownames, $showidnumbers) {
  45          global $CFG;
  46          $this->includeauto = !empty($hidden['includeauto']);
  47          $this->hidden = $hidden;
  48          $this->counts = $counts;
  49          $this->shownames = $shownames;
  50          $this->showidnumbers = $showidnumbers;
  51          parent::__construct($CFG->wwwroot . '/mod/quiz/report.php');
  52      }
  53  
  54      protected function definition() {
  55          $mform = $this->_form;
  56  
  57          $mform->addElement('header', 'options', get_string('options', 'quiz_grading'));
  58  
  59          $gradeoptions = array();
  60          foreach (array('needsgrading', 'manuallygraded', 'autograded', 'all') as $type) {
  61              if (empty($this->counts->$type)) {
  62                  continue;
  63              }
  64              if ($type == 'autograded' && !$this->includeauto) {
  65                  continue;
  66              }
  67              $gradeoptions[$type] = get_string('gradeattempts' . $type, 'quiz_grading',
  68                      $this->counts->$type);
  69          }
  70          $mform->addElement('select', 'grade', get_string('attemptstograde', 'quiz_grading'),
  71                  $gradeoptions);
  72  
  73          $mform->addElement('text', 'pagesize', get_string('questionsperpage', 'quiz_grading'),
  74                  array('size' => 3));
  75          $mform->setType('pagesize', PARAM_INT);
  76  
  77          $orderoptions = array(
  78              'random' => get_string('randomly', 'quiz_grading'),
  79              'date' => get_string('bydate', 'quiz_grading'),
  80          );
  81          if ($this->shownames) {
  82              $orderoptions['studentfirstname'] = get_string('bystudentfirstname', 'quiz_grading');
  83              $orderoptions['studentlastname']  = get_string('bystudentlastname', 'quiz_grading');
  84          }
  85          if ($this->showidnumbers) {
  86              $orderoptions['idnumber'] = get_string('bystudentidnumber', 'quiz_grading');
  87          }
  88          $mform->addElement('select', 'order', get_string('orderattempts', 'quiz_grading'),
  89                  $orderoptions);
  90  
  91          foreach ($this->hidden as $name => $value) {
  92              $mform->addElement('hidden', $name, $value);
  93              if ($name == 'mode') {
  94                  $mform->setType($name, PARAM_ALPHA);
  95              } else {
  96                  $mform->setType($name, PARAM_INT);
  97              }
  98          }
  99  
 100          $mform->addElement('submit', 'submitbutton', get_string('changeoptions', 'quiz_grading'));
 101      }
 102  }