Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 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_responses_report}.
  19   *
  20   * @package   quiz_responses
  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_responses_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_responses_options extends mod_quiz_attempts_report_options {
  38  
  39      /** @var bool whether to show the question text columns. */
  40      public $showqtext = false;
  41  
  42      /** @var bool whether to show the students' response columns. */
  43      public $showresponses = true;
  44  
  45      /** @var bool whether to show the correct response columns. */
  46      public $showright = false;
  47  
  48      /** @var bool which try/tries to show responses from. */
  49      public $whichtries = question_attempt::LAST_TRY;
  50  
  51      protected function get_url_params() {
  52          $params = parent::get_url_params();
  53          $params['qtext']      = $this->showqtext;
  54          $params['resp']       = $this->showresponses;
  55          $params['right']      = $this->showright;
  56          if (quiz_allows_multiple_tries($this->quiz)) {
  57              $params['whichtries'] = $this->whichtries;
  58          }
  59          return $params;
  60      }
  61  
  62      public function get_initial_form_data() {
  63          $toform = parent::get_initial_form_data();
  64          $toform->qtext      = $this->showqtext;
  65          $toform->resp       = $this->showresponses;
  66          $toform->right      = $this->showright;
  67          if (quiz_allows_multiple_tries($this->quiz)) {
  68              $toform->whichtries = $this->whichtries;
  69          }
  70  
  71          return $toform;
  72      }
  73  
  74      public function setup_from_form_data($fromform) {
  75          parent::setup_from_form_data($fromform);
  76  
  77          $this->showqtext     = $fromform->qtext;
  78          $this->showresponses = $fromform->resp;
  79          $this->showright     = $fromform->right;
  80          if (quiz_allows_multiple_tries($this->quiz)) {
  81              $this->whichtries = $fromform->whichtries;
  82          }
  83      }
  84  
  85      public function setup_from_params() {
  86          parent::setup_from_params();
  87  
  88          $this->showqtext     = optional_param('qtext', $this->showqtext,     PARAM_BOOL);
  89          $this->showresponses = optional_param('resp',  $this->showresponses, PARAM_BOOL);
  90          $this->showright     = optional_param('right', $this->showright,     PARAM_BOOL);
  91          if (quiz_allows_multiple_tries($this->quiz)) {
  92              $this->whichtries    = optional_param('whichtries', $this->whichtries, PARAM_ALPHA);
  93          }
  94      }
  95  
  96      public function setup_from_user_preferences() {
  97          parent::setup_from_user_preferences();
  98  
  99          $this->showqtext     = get_user_preferences('quiz_report_responses_qtext', $this->showqtext);
 100          $this->showresponses = get_user_preferences('quiz_report_responses_resp',  $this->showresponses);
 101          $this->showright     = get_user_preferences('quiz_report_responses_right', $this->showright);
 102          if (quiz_allows_multiple_tries($this->quiz)) {
 103              $this->whichtries    = get_user_preferences('quiz_report_responses_which_tries', $this->whichtries);
 104          }
 105      }
 106  
 107      public function update_user_preferences() {
 108          parent::update_user_preferences();
 109  
 110          set_user_preference('quiz_report_responses_qtext', $this->showqtext);
 111          set_user_preference('quiz_report_responses_resp',  $this->showresponses);
 112          set_user_preference('quiz_report_responses_right', $this->showright);
 113          if (quiz_allows_multiple_tries($this->quiz)) {
 114              set_user_preference('quiz_report_responses_which_tries', $this->whichtries);
 115          }
 116      }
 117  
 118      public function resolve_dependencies() {
 119          parent::resolve_dependencies();
 120  
 121          if (!$this->showqtext && !$this->showresponses && !$this->showright) {
 122              // We have to show at least something.
 123              $this->showresponses = true;
 124          }
 125  
 126          // We only want to show the checkbox to delete attempts
 127          // if the user has permissions and if the report mode is showing attempts.
 128          $this->checkboxcolumn = has_capability('mod/quiz:deleteattempts', context_module::instance($this->cm->id))
 129                  && ($this->attempts != quiz_attempts_report::ENROLLED_WITHOUT);
 130      }
 131  }