-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.php
executable file
·74 lines (65 loc) · 2.85 KB
/
renderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?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/>.
/**
* Flashcard question renderer classes.
*
* @package qtype_flashcard
* @copyright 2020 University of vienna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Class qtype_flashcard_renderer renders the flashcard
*
* @copyright 2020 University of vienna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_flashcard_renderer extends qtype_with_combined_feedback_renderer {
/**
* Renders the flashcard question with the flashcard template
* @param question_attempt $qa
* @param question_display_options $options
* @return bool|string
* @throws coding_exception
* @throws moodle_exception
*/
public function formulation_and_controls(question_attempt $qa,
question_display_options $options) {
$this->page->requires->js_call_amd('qtype_flashcard/flipquestion', 'init');
$renderer = $this->page->get_renderer('core');
$question = $qa->get_question();
$qaid = $qa->get_database_id();
foreach ($question->answers as $answer) {
$ans = $answer;
}
$templatecontext['questiontext'] = $question->format_questiontext($qa);
$templatecontext['answer'] = $question->format_text(
$ans->answer, $ans->answerformat,
$qa, 'question', 'answer', $ans->id);
$templatecontext['fliptext'] = get_string('flipbutton', 'qtype_flashcard');
$templatecontext['iwasrighttext'] = $this->pix_icon('t/check', '') . get_string('iwasrightbutton', 'qtype_flashcard');
$templatecontext['iwaswrongtext'] = $this->pix_icon('e/cancel', '') . get_string('iwaswrongbutton', 'qtype_flashcard');
$templatecontext['qaid'] = $qaid;
$content = $renderer->render_from_template('qtype_flashcard/questionview', $templatecontext);
$result = $content;
if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div',
$question->get_validation_error($qa->get_last_qt_data()),
array('class' => 'validationerror'));
}
return $result;
}
}