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 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   * Class to store the options for a {@link quiz_overview_report}.
  19   *
  20   * @package   quiz_overview
  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->dirroot . '/mod/quiz/report/attemptsreport_options.php');
  29  
  30  
  31  /**
  32   * Class to store the options for a {@link quiz_overview_report}.
  33   *
  34   * @copyright 2012 The Open University
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class quiz_overview_options extends mod_quiz_attempts_report_options {
  38  
  39      /** @var bool whether to show only attempt that need regrading. */
  40      public $onlyregraded = false;
  41  
  42      /** @var bool whether to show marks for each question (slot). */
  43      public $slotmarks = true;
  44  
  45      protected function get_url_params() {
  46          $params = parent::get_url_params();
  47          $params['onlyregraded'] = $this->onlyregraded;
  48          $params['slotmarks']    = $this->slotmarks;
  49          return $params;
  50      }
  51  
  52      public function get_initial_form_data() {
  53          $toform = parent::get_initial_form_data();
  54          $toform->onlyregraded = $this->onlyregraded;
  55          $toform->slotmarks    = $this->slotmarks;
  56  
  57          return $toform;
  58      }
  59  
  60      public function setup_from_form_data($fromform) {
  61          parent::setup_from_form_data($fromform);
  62  
  63          $this->onlyregraded = !empty($fromform->onlyregraded);
  64          $this->slotmarks    = $fromform->slotmarks;
  65      }
  66  
  67      public function setup_from_params() {
  68          parent::setup_from_params();
  69  
  70          $this->onlyregraded = optional_param('onlyregraded', $this->onlyregraded, PARAM_BOOL);
  71          $this->slotmarks    = optional_param('slotmarks', $this->slotmarks, PARAM_BOOL);
  72      }
  73  
  74      public function setup_from_user_preferences() {
  75          parent::setup_from_user_preferences();
  76  
  77          $this->slotmarks = get_user_preferences('quiz_overview_slotmarks', $this->slotmarks);
  78      }
  79  
  80      public function update_user_preferences() {
  81          parent::update_user_preferences();
  82  
  83          if (quiz_has_grades($this->quiz)) {
  84              set_user_preference('quiz_overview_slotmarks', $this->slotmarks);
  85          }
  86      }
  87  
  88      public function resolve_dependencies() {
  89          parent::resolve_dependencies();
  90  
  91          if ($this->attempts == quiz_attempts_report::ENROLLED_WITHOUT) {
  92              $this->onlyregraded = false;
  93          }
  94  
  95          if (!$this->usercanseegrades) {
  96              $this->slotmarks = false;
  97          }
  98  
  99          // We only want to show the checkbox to delete attempts
 100          // if the user has permissions and if the report mode is showing attempts.
 101          $this->checkboxcolumn = has_any_capability(
 102                  array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), context_module::instance($this->cm->id))
 103                  && ($this->attempts != quiz_attempts_report::ENROLLED_WITHOUT);
 104      }
 105  }