MDL-66999 theme_boost: @extend remove extends for questions
[moodle.git] / question / behaviour / adaptive / renderer.php
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/>.
17 /**
18  * Renderer for outputting parts of a question belonging to the legacy
19  * adaptive behaviour.
20  *
21  * @package    qbehaviour
22  * @subpackage adaptive
23  * @copyright  2009 The Open University
24  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25  */
28 defined('MOODLE_INTERNAL') || die();
31 /**
32  * Renderer for outputting parts of a question belonging to the legacy
33  * adaptive 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_adaptive_renderer extends qbehaviour_renderer {
40     public function controls(question_attempt $qa, question_display_options $options) {
41         return $this->submit_button($qa, $options);
42     }
44     public function feedback(question_attempt $qa, question_display_options $options) {
46         // If the latest answer was invalid, display an informative message.
47         if ($qa->get_state() == question_state::$invalid) {
48             return html_writer::nonempty_tag('div', $this->disregarded_info(),
49                     array('class' => 'gradingdetails'));
50         }
52         // Otherwise get the details.
53         return $this->render_adaptive_marks(
54                 $qa->get_behaviour()->get_adaptive_marks(), $options);
55     }
57     /**
58      * Display the scoring information about an adaptive attempt.
59      * @param qbehaviour_adaptive_mark_details contains all the score details we need.
60      * @param question_display_options $options display options.
61      */
62     public function render_adaptive_marks(qbehaviour_adaptive_mark_details $details, question_display_options $options) {
63         if ($details->state == question_state::$todo || $options->marks < question_display_options::MARK_AND_MAX) {
64             // No grades yet.
65             return '';
66         }
68         // Display the grading details from the last graded state.
69         $class = $details->state->get_feedback_class();
70         return html_writer::tag('div', get_string($class, 'question'),
71                         array('class' => 'correctness badge ' . $class))
72                 . html_writer::tag('div', $this->grading_details($details, $options),
73                         array('class' => 'gradingdetails'));
74     }
76     /**
77      * Display the information about the penalty calculations.
78      * @param qbehaviour_adaptive_mark_details contains all the score details we need.
79      * @param question_display_options $options display options.
80      * @return string html fragment
81      */
82     protected function grading_details(qbehaviour_adaptive_mark_details $details, question_display_options $options) {
84         $mark = $details->get_formatted_marks($options->markdp);
86         if ($details->currentpenalty == 0 && $details->totalpenalty == 0) {
87             return get_string('gradingdetails', 'qbehaviour_adaptive', $mark);
88         }
90         $output = '';
92         // Print details of grade adjustment due to penalties
93         if ($details->rawmark != $details->actualmark) {
94             if (!$details->improvable) {
95                 return get_string('gradingdetailswithadjustment', 'qbehaviour_adaptive', $mark);
96             } else if ($details->totalpenalty > $details->currentpenalty) {
97                 return get_string('gradingdetailswithadjustmenttotalpenalty', 'qbehaviour_adaptive', $mark);
98             } else {
99                 return get_string('gradingdetailswithadjustmentpenalty', 'qbehaviour_adaptive', $mark);
100             }
102         } else {
103             if (!$details->improvable) {
104                 return get_string('gradingdetails', 'qbehaviour_adaptive', $mark);
105             } else if ($details->totalpenalty > $details->currentpenalty) {
106                 return get_string('gradingdetailswithtotalpenalty', 'qbehaviour_adaptive', $mark);
107             } else {
108                 return get_string('gradingdetailswithpenalty', 'qbehaviour_adaptive', $mark);
109             }
110         }
112         return $output;
113     }
115     /**
116      * Display information about a disregarded (incomplete) response.
117      */
118     protected function disregarded_info() {
119         return get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
120     }