Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

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