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 |
/**
|
|
|
18 |
* Defines the renderer for the quiz_grading module.
|
|
|
19 |
*
|
|
|
20 |
* @package quiz_grading
|
|
|
21 |
* @copyright 2018 Huong Nguyen <huongnv13@gmail.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* The renderer for the quiz_grading module.
|
|
|
27 |
*
|
|
|
28 |
* @copyright 2018 Huong Nguyen <huongnv13@gmail.com>
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class quiz_grading_renderer extends plugin_renderer_base {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Render no question notification.
|
|
|
35 |
*
|
|
|
36 |
* @param stdClass $quiz The quiz settings.
|
|
|
37 |
* @param stdClass $cm The course-module for this quiz.
|
|
|
38 |
* @param stdClass $context The quiz context.
|
|
|
39 |
* @return string The HTML for the no questions message.
|
|
|
40 |
*/
|
|
|
41 |
public function render_quiz_no_question_notification($quiz, $cm, $context) {
|
|
|
42 |
return quiz_no_questions_message($quiz, $cm, $context);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Render no question need to grade notification.
|
|
|
47 |
*
|
|
|
48 |
* @throws coding_exception
|
|
|
49 |
*/
|
|
|
50 |
public function render_quiz_no_grade_question_notification() {
|
|
|
51 |
return $this->notification(get_string('nothingfound', 'quiz_grading'), 'info', false);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Render index display.
|
|
|
56 |
*
|
|
|
57 |
* @param string $linktext The text of the link.
|
|
|
58 |
* @param moodle_url $listquestionurl Url of the page that list all questions.
|
|
|
59 |
* @return string The HTML for the display heading.
|
|
|
60 |
* @throws coding_exception
|
|
|
61 |
*/
|
|
|
62 |
public function render_display_index_heading($linktext, $listquestionurl) {
|
|
|
63 |
$output = '';
|
|
|
64 |
|
|
|
65 |
$output .= $this->heading(get_string('questionsthatneedgrading', 'quiz_grading'), 3);
|
|
|
66 |
$output .= html_writer::tag('p', html_writer::link($listquestionurl, $linktext), ['class' => 'toggleincludeauto']);
|
|
|
67 |
|
|
|
68 |
return $output;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Render questions list table.
|
|
|
73 |
*
|
|
|
74 |
* @param bool $includeauto True to show automatically graded questions.
|
|
|
75 |
* @param array $data List of questions.
|
|
|
76 |
* @param array $header List of table headers.
|
|
|
77 |
* @return string The HTML for the question table.
|
|
|
78 |
* @throws coding_exception
|
|
|
79 |
*/
|
|
|
80 |
public function render_questions_table($includeauto, $data, $header) {
|
|
|
81 |
if (empty($data)) {
|
|
|
82 |
return $this->render_quiz_no_grade_question_notification();
|
|
|
83 |
}
|
|
|
84 |
$output = '';
|
|
|
85 |
|
|
|
86 |
$table = new html_table();
|
|
|
87 |
$table->class = 'generaltable';
|
|
|
88 |
$table->id = 'questionstograde';
|
|
|
89 |
$table->head = $header;
|
|
|
90 |
$table->data = $data;
|
|
|
91 |
|
|
|
92 |
$output .= html_writer::table($table);
|
|
|
93 |
|
|
|
94 |
return $output;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
* Render grade link for question.
|
|
|
99 |
*
|
|
|
100 |
* @param stdClass $counts
|
|
|
101 |
* @param string $type Type of grade.
|
|
|
102 |
* @param string $string Lang string.
|
|
|
103 |
* @param string $component Lang string component.
|
|
|
104 |
* @param moodle_url $gradequestionurl Url to grade question.
|
|
|
105 |
* @return string The HTML for the question grade link.
|
|
|
106 |
* @throws coding_exception
|
|
|
107 |
*/
|
|
|
108 |
public function render_grade_link($counts, $type, $string, $component, $gradequestionurl) {
|
|
|
109 |
$output = '';
|
|
|
110 |
if ($counts->$type > 0) {
|
|
|
111 |
$output .= ' ' . html_writer::link(
|
|
|
112 |
$gradequestionurl,
|
|
|
113 |
get_string($string, $component),
|
|
|
114 |
['class' => 'gradetheselink']);
|
|
|
115 |
}
|
|
|
116 |
return $output;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
* Render grading page.
|
|
|
121 |
*
|
|
|
122 |
* @param stdClass $questioninfo Information of a question.
|
|
|
123 |
* @param moodle_url $listquestionsurl Url of the page that list all questions.
|
|
|
124 |
* @param quiz_grading_settings_form $filterform Question filter form.
|
|
|
125 |
* @param stdClass $paginginfo Pagination information.
|
|
|
126 |
* @param stdClass $pagingbar Pagination bar information.
|
|
|
127 |
* @param moodle_url $formaction Form submit url.
|
|
|
128 |
* @param array $hiddeninputs List of hidden input fields.
|
|
|
129 |
* @param string $gradequestioncontent HTML string of question content.
|
|
|
130 |
* @return string The HTML for the grading interface.
|
|
|
131 |
* @throws coding_exception
|
|
|
132 |
* @throws moodle_exception
|
|
|
133 |
*/
|
|
|
134 |
public function render_grading_interface($questioninfo, $listquestionsurl, $filterform, $paginginfo, $pagingbar, $formaction,
|
|
|
135 |
$hiddeninputs, $gradequestioncontent) {
|
|
|
136 |
$output = '';
|
|
|
137 |
|
|
|
138 |
$output .= question_engine::initialise_js();
|
|
|
139 |
|
|
|
140 |
$output .= $this->heading(get_string('gradingquestionx', 'quiz_grading', $questioninfo), 3);
|
|
|
141 |
|
|
|
142 |
$output .= html_writer::tag('p', html_writer::link($listquestionsurl,
|
|
|
143 |
get_string('backtothelistofquestions', 'quiz_grading')),
|
|
|
144 |
['class' => 'mdl-align']);
|
|
|
145 |
|
|
|
146 |
$output .= $filterform->render();
|
|
|
147 |
|
|
|
148 |
$output .= $this->heading(get_string('gradingattemptsxtoyofz', 'quiz_grading', $paginginfo), 3);
|
|
|
149 |
|
|
|
150 |
$output .= $this->render_paging_bar($pagingbar);
|
|
|
151 |
|
|
|
152 |
$output .= html_writer::start_tag('form', [
|
|
|
153 |
'method' => 'post',
|
|
|
154 |
'action' => $formaction,
|
|
|
155 |
'class' => 'mform',
|
|
|
156 |
'id' => 'manualgradingform'
|
|
|
157 |
]);
|
|
|
158 |
$output .= html_writer::start_tag('div');
|
|
|
159 |
$output .= html_writer::input_hidden_params(new moodle_url('', $hiddeninputs));
|
|
|
160 |
|
|
|
161 |
$output .= $gradequestioncontent;
|
|
|
162 |
|
|
|
163 |
$output .= html_writer::tag('div', html_writer::empty_tag('input', [
|
|
|
164 |
'type' => 'submit',
|
|
|
165 |
'class' => 'btn btn-primary',
|
|
|
166 |
'value' => get_string('saveandnext', 'quiz_grading')
|
|
|
167 |
]), ['class' => 'mdl-align']);
|
|
|
168 |
$output .= html_writer::end_tag('div') . html_writer::end_tag('form');
|
|
|
169 |
|
|
|
170 |
$output .= $this->render_paging_bar($pagingbar);
|
|
|
171 |
|
|
|
172 |
// Add the form change checker.
|
|
|
173 |
$this->page->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['manualgradingform']);
|
|
|
174 |
|
|
|
175 |
return $output;
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
/**
|
|
|
179 |
* Render grade question content.
|
|
|
180 |
*
|
|
|
181 |
* @param question_usage_by_activity $questionusage The question usage that need to grade.
|
|
|
182 |
* @param int $slot the number used to identify this question within this usage.
|
|
|
183 |
* @param question_display_options $displayoptions the display options to use.
|
|
|
184 |
* @param int $questionnumber the number of the question to check.
|
|
|
185 |
* @param string $heading the question heading text.
|
|
|
186 |
* @return string The HTML for the question display.
|
|
|
187 |
*/
|
|
|
188 |
public function render_grade_question($questionusage, $slot, $displayoptions, $questionnumber, $heading) {
|
|
|
189 |
$output = '';
|
|
|
190 |
|
|
|
191 |
if ($heading) {
|
|
|
192 |
$output .= $this->heading($heading, 4);
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
$output .= $questionusage->render_question($slot, $displayoptions, $questionnumber);
|
|
|
196 |
|
|
|
197 |
return $output;
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* Render paging bar.
|
|
|
202 |
*
|
|
|
203 |
* @param object $pagingbar Pagination bar information.
|
|
|
204 |
* @return string The HTML for the question display.
|
|
|
205 |
*/
|
|
|
206 |
public function render_paging_bar(object $pagingbar): string {
|
|
|
207 |
if ($pagingbar->count > $pagingbar->pagesize && $pagingbar->order != 'random') {
|
|
|
208 |
return $this->paging_bar($pagingbar->count, $pagingbar->page, $pagingbar->pagesize, $pagingbar->pagingurl);
|
|
|
209 |
}
|
|
|
210 |
return '';
|
|
|
211 |
}
|
|
|
212 |
}
|