1 |
efrain |
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 |
namespace qtype_ordering\output;
|
|
|
18 |
|
|
|
19 |
use renderer_base;
|
|
|
20 |
use question_attempt;
|
|
|
21 |
use question_display_options;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Collate various sections of displayable feedback for render.
|
|
|
25 |
*
|
|
|
26 |
* @package qtype_ordering
|
|
|
27 |
* @copyright 2023 Mathew May <mathew.solutions>
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*/
|
|
|
30 |
class feedback extends renderable_base {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Define the feedback with options for display.
|
|
|
34 |
*
|
|
|
35 |
* @param question_attempt $qa The question attempt object.
|
|
|
36 |
* @param question_display_options $options Controls what should and should not be displayed
|
|
|
37 |
* via question_display_options but unit tests are fickle.
|
|
|
38 |
*/
|
|
|
39 |
public function __construct(
|
|
|
40 |
question_attempt $qa,
|
|
|
41 |
/** @var question_display_options The question display options. */
|
|
|
42 |
protected question_display_options $options
|
|
|
43 |
) {
|
|
|
44 |
parent::__construct($qa);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public function export_for_template(renderer_base $output): array {
|
|
|
48 |
global $PAGE;
|
|
|
49 |
|
|
|
50 |
$data = [];
|
|
|
51 |
$question = $this->qa->get_question();
|
|
|
52 |
$qtyperenderer = $PAGE->get_renderer('qtype_ordering');
|
|
|
53 |
|
|
|
54 |
if ($this->options->feedback) {
|
|
|
55 |
// Literal render out but we trust the teacher.
|
|
|
56 |
$data['specificfeedback'] = $qtyperenderer->specific_feedback($this->qa);
|
|
|
57 |
|
|
|
58 |
$specificgradedetailfeedback = new specific_grade_detail_feedback($this->qa);
|
|
|
59 |
$data['specificgradedetailfeedback'] = $specificgradedetailfeedback->export_for_template($output);
|
|
|
60 |
|
|
|
61 |
if ($hint = $this->qa->get_applicable_hint()) {
|
|
|
62 |
$data['hint'] = $question->format_hint($hint, $this->qa);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
if ($this->options->numpartscorrect) {
|
|
|
67 |
$numpartscorrect = new num_parts_correct($this->qa);
|
|
|
68 |
$data['numpartscorrect'] = $numpartscorrect->export_for_template($output);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
if ($this->options->generalfeedback) {
|
|
|
72 |
// Literal render out but we trust the teacher.
|
|
|
73 |
$data['generalfeedback'] = $question->format_generalfeedback($this->qa);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
if ($this->options->rightanswer) {
|
|
|
77 |
$correctresponse = new correct_response($this->qa);
|
|
|
78 |
$data['rightanswer'] = $correctresponse->export_for_template($output);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
return $data;
|
|
|
82 |
}
|
|
|
83 |
}
|