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.
   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   * Defines the renderer for the deferred feedback with certainty based marking
  19   * behaviour.
  20   *
  21   * @package    qbehaviour
  22   * @subpackage deferredcbm
  23   * @copyright  2009 The Open University
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  
  31  /**
  32   * Renderer for outputting parts of a question belonging to the deferred
  33   * feedback with certainty based marking behaviour.
  34   *
  35   * @copyright  2009 The Open University
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class qbehaviour_deferredcbm_renderer extends qbehaviour_renderer {
  39      protected function certainty_choices($controlname, $selected, $readonly) {
  40          $attributes = array(
  41              'type' => 'radio',
  42              'name' => $controlname,
  43          );
  44          if ($readonly) {
  45              $attributes['disabled'] = 'disabled';
  46          }
  47  
  48          $choices = '';
  49          foreach (question_cbm::$certainties as $certainty) {
  50              $id = $controlname . $certainty;
  51              $attributes['id'] = $id;
  52              $attributes['value'] = $certainty;
  53              if ($selected == $certainty) {
  54                  $attributes['checked'] = 'checked';
  55              } else {
  56                  unset($attributes['checked']);
  57              }
  58              $choices .= ' ' .
  59                      html_writer::tag('label', html_writer::empty_tag('input', $attributes) .
  60                              question_cbm::get_string($certainty), array('for' => $id));
  61          }
  62          return $choices;
  63      }
  64  
  65      public function controls(question_attempt $qa, question_display_options $options) {
  66          $a = new stdClass();
  67          $a->help = $this->output->help_icon('certainty', 'qbehaviour_deferredcbm');
  68          $a->choices = $this->certainty_choices($qa->get_behaviour_field_name('certainty'),
  69                  $qa->get_last_behaviour_var('certainty'), $options->readonly);
  70  
  71          return html_writer::tag('div', get_string('howcertainareyou', 'qbehaviour_deferredcbm', $a),
  72                  array('class' => 'certaintychoices'));
  73      }
  74  
  75      public function feedback(question_attempt $qa, question_display_options $options) {
  76          if (!$options->feedback) {
  77              return '';
  78          }
  79  
  80          if ($qa->get_state() == question_state::$gaveup || $qa->get_state() ==
  81                  question_state::$mangaveup) {
  82              return '';
  83          }
  84  
  85          $feedback = '';
  86          if (!$qa->get_last_behaviour_var('certainty') &&
  87                  $qa->get_last_behaviour_var('_assumedcertainty')) {
  88              $feedback .= html_writer::tag('p',
  89                      get_string('assumingcertainty', 'qbehaviour_deferredcbm',
  90                      question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))));
  91          }
  92  
  93          return $feedback;
  94      }
  95  
  96      public function marked_out_of_max(question_attempt $qa, core_question_renderer $qoutput,
  97              question_display_options $options) {
  98          return get_string('weightx', 'qbehaviour_deferredcbm', $qa->format_fraction_as_mark(
  99                  question_cbm::adjust_fraction(1, question_cbm::default_certainty()),
 100                  $options->markdp));
 101      }
 102  
 103      public function mark_out_of_max(question_attempt $qa, core_question_renderer $qoutput,
 104              question_display_options $options) {
 105          return get_string('cbmmark', 'qbehaviour_deferredcbm', $qa->format_mark($options->markdp)) .
 106                  '<br>' . $this->marked_out_of_max($qa, $qoutput, $options);
 107      }
 108  }