mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-79874 qtype_ordering: Move feedback into exporter
Part of: MDL-79863
- Loading branch information
1 parent
e1357ee
commit 9d06092
Showing
5 changed files
with
562 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace qtype_ordering\output; | ||
|
||
use renderer_base; | ||
use question_attempt; | ||
use question_display_options; | ||
|
||
/** | ||
* Renderable class for the displaying the feedback. | ||
* | ||
* @package qtype_ordering | ||
* @copyright 2023 Mathew May <mathew.solutions> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class feedback extends renderable_base { | ||
|
||
/** @var question_display_options $options The question options. */ | ||
protected $options; | ||
|
||
/** | ||
* The class constructor. | ||
* | ||
* @param question_attempt $qa The question attempt object. | ||
* @param question_display_options $options Controls what should and should not be displayed via question_display_options but unit tests are fickle. | ||
*/ | ||
public function __construct(question_attempt $qa, question_display_options $options) { | ||
parent::__construct($qa); | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* Export the data for the mustache template. | ||
* | ||
* @param renderer_base $output renderer to be used to render the feedback elements. | ||
* @return array | ||
*/ | ||
public function export_for_template(renderer_base $output): array { | ||
global $PAGE; | ||
|
||
$data = []; | ||
$question = $this->qa->get_question(); | ||
$qtyperenderer = $PAGE->get_renderer('qtype_ordering'); | ||
|
||
if ($this->options->feedback) { | ||
// Literal render out but we trust the teacher. | ||
$data['specificfeedback'] = $qtyperenderer->specific_feedback($this->qa); | ||
|
||
$specificgradedetailfeedback = new specific_grade_detail_feedback($this->qa); | ||
$data['specificgradedetailfeedback'] = $specificgradedetailfeedback->export_for_template($output); | ||
|
||
if ($hint = $this->qa->get_applicable_hint()) { | ||
$data['hint'] = $question->format_hint($hint, $this->qa); | ||
} | ||
} | ||
|
||
if ($this->options->numpartscorrect) { | ||
$numpartscorrect = new num_parts_correct($this->qa); | ||
$data['numpartscorrect'] = $numpartscorrect->export_for_template($output); | ||
} | ||
|
||
if ($this->options->generalfeedback) { | ||
// Literal render out but we trust the teacher. | ||
$data['generalfeedback'] = $question->format_generalfeedback($this->qa); | ||
} | ||
|
||
if ($this->options->rightanswer) { | ||
$correctresponse = new correct_response($this->qa); | ||
$data['rightanswer'] = $correctresponse->export_for_template($output); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{{! | ||
This file is part of Moodle - http://moodle.org/ | ||
Moodle is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Moodle is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
}} | ||
{{! | ||
@template qtype_ordering/feedback | ||
Renders the feedback for the question. | ||
Context variables required for this template: | ||
* specificfeedback - Any specific feedback for the question. | ||
* numpartscorrect - The number of parts correct. | ||
* specificgradedetailfeedback - The specific grade detail feedback. | ||
* hint - The hint for the question. | ||
* generalfeedback - The general feedback for the question. | ||
* rightanswer - The right answer for the question. | ||
Example context (json): | ||
{ | ||
"specificfeedback": "Maybe you should try again.", | ||
"numpartscorrect": { | ||
"numcorrect": 1, | ||
"numpartial": 3, | ||
"numincorrect": 0 | ||
}, | ||
"specificgradedetailfeedback": { | ||
"showpartialwrong": true, | ||
"gradingtype": "Grading type: Absolute position", | ||
"gradedetails": "93", | ||
"orderinglayoutclass": "vertical", | ||
"scoredetails": [ | ||
{ | ||
"score": "1", | ||
"maxscore": "1", | ||
"percent": "100" | ||
}, | ||
{ | ||
"score": "0", | ||
"maxscore": "1", | ||
"percent": "0" | ||
} | ||
] | ||
}, | ||
"hint": "The cake is a lie.", | ||
"generalfeedback": "Here is some general feedback.", | ||
"rightanswer": { | ||
"hascorrectresponse": true, | ||
"showcorrect": "true", | ||
"orderinglayoutclass": "vertical", | ||
"correctanswers": [ | ||
{ | ||
"answertext": "Correct answer 1" | ||
}, | ||
{ | ||
"answertext": "Correct answer 2" | ||
} | ||
] | ||
} | ||
} | ||
}} | ||
{{#specificfeedback}} | ||
<div class="specificfeedback"> | ||
{{{.}}} | ||
</div> | ||
{{/specificfeedback}} | ||
{{#numpartscorrect}} | ||
<div class="numpartscorrect"> | ||
{{>qtype_ordering/num_parts_correct}} | ||
</div> | ||
{{/numpartscorrect}} | ||
{{#specificgradedetailfeedback}} | ||
{{>qtype_ordering/specific_grade_detail_feedback}} | ||
{{/specificgradedetailfeedback}} | ||
{{#hint}} | ||
<div class="hint"> | ||
{{{.}}} | ||
</div> | ||
{{/hint}} | ||
{{#generalfeedback}} | ||
<div class="generalfeedback"> | ||
{{{.}}} | ||
</div> | ||
{{/generalfeedback}} | ||
{{#rightanswer}} | ||
<div class="rightanswer"> | ||
{{>qtype_ordering/correct_response}} | ||
</div> | ||
{{/rightanswer}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.