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 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   * Base class for the settings form for {@link quiz_attempts_report}s.
  19   *
  20   * @package   mod_quiz
  21   * @copyright 2012 The Open University
  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   * Base class for the settings form for {@link quiz_attempts_report}s.
  33   *
  34   * @copyright 2012 The Open University
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  abstract class mod_quiz_attempts_report_form extends moodleform {
  38  
  39      protected function definition() {
  40          $mform = $this->_form;
  41  
  42          $mform->addElement('header', 'preferencespage',
  43                  get_string('reportwhattoinclude', 'quiz'));
  44  
  45          $this->standard_attempt_fields($mform);
  46          $this->other_attempt_fields($mform);
  47  
  48          $mform->addElement('header', 'preferencesuser',
  49                  get_string('reportdisplayoptions', 'quiz'));
  50  
  51          $this->standard_preference_fields($mform);
  52          $this->other_preference_fields($mform);
  53  
  54          $mform->addElement('submit', 'submitbutton',
  55                  get_string('showreport', 'quiz'));
  56      }
  57  
  58      protected function standard_attempt_fields(MoodleQuickForm $mform) {
  59  
  60          $mform->addElement('select', 'attempts', get_string('reportattemptsfrom', 'quiz'), array(
  61                      quiz_attempts_report::ENROLLED_WITH    => get_string('reportuserswith', 'quiz'),
  62                      quiz_attempts_report::ENROLLED_WITHOUT => get_string('reportuserswithout', 'quiz'),
  63                      quiz_attempts_report::ENROLLED_ALL     => get_string('reportuserswithorwithout', 'quiz'),
  64                      quiz_attempts_report::ALL_WITH        => get_string('reportusersall', 'quiz'),
  65                   ));
  66  
  67          $stategroup = array(
  68              $mform->createElement('advcheckbox', 'stateinprogress', '',
  69                      get_string('stateinprogress', 'quiz')),
  70              $mform->createElement('advcheckbox', 'stateoverdue', '',
  71                      get_string('stateoverdue', 'quiz')),
  72              $mform->createElement('advcheckbox', 'statefinished', '',
  73                      get_string('statefinished', 'quiz')),
  74              $mform->createElement('advcheckbox', 'stateabandoned', '',
  75                      get_string('stateabandoned', 'quiz')),
  76          );
  77          $mform->addGroup($stategroup, 'stateoptions',
  78                  get_string('reportattemptsthatare', 'quiz'), array(' '), false);
  79          $mform->setDefault('stateinprogress', 1);
  80          $mform->setDefault('stateoverdue',    1);
  81          $mform->setDefault('statefinished',   1);
  82          $mform->setDefault('stateabandoned',  1);
  83          $mform->disabledIf('stateinprogress', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
  84          $mform->disabledIf('stateoverdue',    'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
  85          $mform->disabledIf('statefinished',   'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
  86          $mform->disabledIf('stateabandoned',  'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
  87  
  88          if (quiz_report_can_filter_only_graded($this->_customdata['quiz'])) {
  89              $gm = html_writer::tag('span',
  90                      quiz_get_grading_option_name($this->_customdata['quiz']->grademethod),
  91                      array('class' => 'highlight'));
  92              $mform->addElement('advcheckbox', 'onlygraded', '',
  93                      get_string('reportshowonlyfinished', 'quiz', $gm));
  94              $mform->disabledIf('onlygraded', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
  95              $mform->disabledIf('onlygraded', 'statefinished', 'notchecked');
  96          }
  97      }
  98  
  99      protected function other_attempt_fields(MoodleQuickForm $mform) {
 100      }
 101  
 102      protected function standard_preference_fields(MoodleQuickForm $mform) {
 103          $mform->addElement('text', 'pagesize', get_string('pagesize', 'quiz'));
 104          $mform->setType('pagesize', PARAM_INT);
 105      }
 106  
 107      protected function other_preference_fields(MoodleQuickForm $mform) {
 108      }
 109  
 110      public function validation($data, $files) {
 111          $errors = parent::validation($data, $files);
 112  
 113          if ($data['attempts'] != quiz_attempts_report::ENROLLED_WITHOUT && !(
 114                  $data['stateinprogress'] || $data['stateoverdue'] || $data['statefinished'] || $data['stateabandoned'])) {
 115              $errors['stateoptions'] = get_string('reportmustselectstate', 'quiz');
 116          }
 117  
 118          return $errors;
 119      }
 120  }