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] [Versions 39 and 311]

   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->addRule('pagesize', null, 'positiveint', null, 'client');
  76          $mform->setType('pagesize', PARAM_INT);
  77  
  78          $orderoptions = array(
  79              'random' => get_string('randomly', 'quiz_grading'),
  80              'date' => get_string('bydate', 'quiz_grading'),
  81          );
  82          if ($this->shownames) {
  83              $orderoptions['studentfirstname'] = get_string('bystudentfirstname', 'quiz_grading');
  84              $orderoptions['studentlastname']  = get_string('bystudentlastname', 'quiz_grading');
  85          }
  86          if ($this->showidnumbers) {
  87              $orderoptions['idnumber'] = get_string('bystudentidnumber', 'quiz_grading');
  88          }
  89          $mform->addElement('select', 'order', get_string('orderattempts', 'quiz_grading'),
  90                  $orderoptions);
  91  
  92          foreach ($this->hidden as $name => $value) {
  93              $mform->addElement('hidden', $name, $value);
  94              if ($name == 'mode') {
  95                  $mform->setType($name, PARAM_ALPHA);
  96              } else {
  97                  $mform->setType($name, PARAM_INT);
  98              }
  99          }
 100  
 101          $mform->addElement('submit', 'submitbutton', get_string('changeoptions', 'quiz_grading'));
 102      }
 103  }