-
Notifications
You must be signed in to change notification settings - Fork 3
/
renderer.php
250 lines (222 loc) · 9.43 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?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/>.
/**
* Renderer
*
* @package block
* @subpackage coursefeedback
* @copyright 2023 innoCampus, Technische Universität Berlin
* @author 2011-2023 onwards Jan Eberhardt
* @author 2022 onwards Felix Di Lenarda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_coursefeedback_renderer extends plugin_renderer_base {
/**
* @return string
*/
public function render_manage_link() {
return html_writer::link(new moodle_url("/admin/settings.php?section=blocksettingcoursefeedback"),
get_string("page_link_settings", "block_coursefeedback"));
}
/**
* @param number $courseid
* @param number $feedbackid
* @return string
*/
public function render_results_link($courseid, $feedbackid) {
return html_writer::link(new moodle_url("/blocks/coursefeedback/view.php",
array("course" => $courseid, "feedback" => $feedbackid)),
get_string("page_link_viewresults", "block_coursefeedback"));
}
/**
* @param number $courseid
* @return array
*/
public function render_result_links($answerredfbs) {
$results = [];
foreach ($answerredfbs as $feedback) {
$results[] = html_writer::link(new moodle_url("/blocks/coursefeedback/view.php",
["course" => $feedback->course, "feedback" => $feedback->id]), format_string($feedback->name));
}
return $results;
}
/**
* @return string
*/
public function render_ranking_link() {
return html_writer::link(new moodle_url("/blocks/coursefeedback/ranking.php"),
get_string("page_link_rankings", "block_coursefeedback"));
}
/**
* @return string
*/
public function render_moreinfo_link($params) {
return html_writer::link(new moodle_url("/blocks/coursefeedback/feedbackinfo.php", $params),
get_string("infopage_link_feedbackinfo", "block_coursefeedback"));
}
/**
* @param object $feedback
* @param array $openquestions
* @return string
*/
public function render_notif_message($feedback, $openquestions) {
// TODO do we need the export for template function here?
// Template vars are automatically escaped
$urlparams = [
'feedback' => $feedback->id,
'course' => $this->page->course->id
];
$data = [
'fbheading' => format_text($feedback->heading, FORMAT_HTML),
'qid' => $openquestions['currentopenqstn']->questionid,
'qsum' => $openquestions['questionsum'],
'qtext' => $openquestions['currentopenqstn']->question,
'link' => new moodle_url("/blocks/coursefeedback/feedbackinfo.php", $urlparams),
'questiontype' => intval($openquestions['currentopenqstn']->questiontype)
];
$questiontype = intval($openquestions['currentopenqstn']->questiontype);
return parent::render_from_template('block_coursefeedback/questionnotif', $data);
}
/**
* @param object $feedback
* @param int $courseid
* @return string
*/
public function render_notif_message_teacher($feedback, $courseid) {
$message = get_string("notif_feedbackactive", "block_coursefeedback");
if (get_config("block_coursefeedback", "allow_hiding")) {
$message .= ' ' . get_string("notif_deactivate_howto", "block_coursefeedback");
}
$message .= ' ' . $this->render_moreinfo_link(array("feedback" => $feedback->id, "course" => $courseid));
$message .= ' | ' . $this->render_results_link($courseid, $feedback->id);
return $message;
}
/**
* Renders the essayquestions
*
* @param array $essayquestions - array of question objects $essayquestions
* @param int $courseid
* @param int $feedbackid
* @return string
*/
public function render_essay_questions($essayquestions, $courseid, $feedbackid) {
// Provide downloadlink for textanswers for all questions.
$params = [
"course" => $courseid,
"feedback" => $feedbackid,
"download" => "csv"
];
$essayhtml = html_writer::link(new moodle_url("/blocks/coursefeedback/essayanswers.php", $params),
get_string("page_link_download", "block_coursefeedback", "CSV"));
// Create and fill Textanswer table.
$table = new html_table();
$table->data = [];
foreach ($essayquestions as $essayquestion) {
// Cell 1: "Question <id>:"
$text = get_string("form_header_question", "block_coursefeedback", $essayquestion->questionid)
. ": ";
// Cell 2: "<questiontext>"
$questiontext = format_string($essayquestion->question);
// Cell 3 "Show answers" (lnk).
$params = [
'course' => $courseid,
'feedback' => $essayquestion->coursefeedbackid,
'question' => $essayquestion->questionid
];
$answerlink = html_writer::link(new moodle_url("/blocks/coursefeedback/essayanswers.php", $params),
get_string("table_html_showanswers", "block_coursefeedback"));
// Insert in table
$cells = [ $text, $questiontext, $answerlink ];
$row = new html_table_row($cells);
$table->data[] = $row;
}
$essayhtml .= html_writer::table($table);
return $essayhtml;
}
/**
* Render the essayanswers page
*
* @param array $essayquestions - array of question objects $essayquestions
* @return string
*/
public function render_essay_answers($courseid, $feedbackid, $questionid, $anscount, $page=0, $perpage=30) {
global $DB;
// Start output with heading "Essay Feedbackresults"
$answerhtml = html_writer::tag('h3',get_string("questiontype_essay", "block_coursefeedback")
. ' ' . get_string("resultspage_title", "block_coursefeedback"));
// Add infos for $anscount and current $page.
$totalpages = ceil($anscount / $perpage);
$answerhtml .= html_writer::tag('div',
get_string("page_html_totalanscountinfo", "block_coursefeedback",
['anscount' => $anscount, 'page' => $page + 1, 'totalpages' => $totalpages ]));
// Count total amount of textanswer DB entries (including empty). Calculate $emptyans and add it.
$totalcount = $DB->count_records('block_coursefeedback_textans', [
'course' => $courseid,
'coursefeedbackid' => $feedbackid,
'questionid' => $questionid
]);
$emptyans = $totalcount - $anscount;
$answerhtml .= html_writer::tag('div',
get_string("qtype_empty_essayans", "block_coursefeedback", $emptyans));
// Add download link.
$params = [
"course" => $courseid,
"feedback" => $feedbackid,
"question" => $questionid,
"download" => "csv"
];
$link = html_writer::link(new moodle_url("/blocks/coursefeedback/essayanswers.php", $params),
get_string("page_link_download", "block_coursefeedback", "CSV"));
$answerhtml .= html_writer::tag('div', $link);
// Get all non-empty textanswers for the given $questionid and add them in a table.
$select = "course = :courseid
AND coursefeedbackid = :coursefeedbackid
AND questionid = :questionid
AND textanswer IS NOT NULL
AND textanswer <> ''";
$params = [
'courseid' => $courseid,
'coursefeedbackid' => $feedbackid,
'questionid' => $questionid,
];
$limitfrom = $perpage * $page;
$answers = $DB->get_records_select(
'block_coursefeedback_textans',
$select,
$params,
'',
'id, textanswer',
$limitfrom,
$perpage,
);
// Get the $question(text) of the given $questionid
$question = block_coursefeedback_get_questions_by_language($feedbackid, current_language(),
CFB_QUESTIONTYPE_ESSAY, 'questionid', 'questionid,question', $questionid);
$questiontext = format_string(reset($question)->question);
// Create and fill table.
$table = new html_table();
$table->head = [get_string("notif_question", "block_coursefeedback").' '.$questionid.': ',
$questiontext];
foreach ($answers as $answer) {
$cell = new html_table_cell(format_string($answer->textanswer));
$cell->colspan = 2;
$table->data[] = new html_table_row([$cell]);
}
// Add table with the non empty answers.
$answerhtml .= html_writer::table($table);
return $answerhtml;
}
}