Commit | Line | Data |
---|---|---|
c586d2bf MG |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * @package gradingform | |
20 | * @subpackage rubric | |
21 | * @copyright 2011 Marina Glancy | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
24 | ||
c586d2bf MG |
25 | defined('MOODLE_INTERNAL') || die(); |
26 | ||
27 | /** | |
28 | * Grading method plugin renderer | |
29 | */ | |
ab156741 | 30 | class gradingform_rubric_renderer { |
c586d2bf | 31 | |
ab156741 | 32 | /** |
fc5adc3b MG |
33 | * This function returns html code for displaying criterion. Depending on $mode it may be the |
34 | * code to edit rubric, to preview the rubric, to evaluate somebody or to review the evaluation. | |
35 | * | |
36 | * This function may be called from display_rubric() to display the whole rubric, or it can be | |
37 | * called by itself to return a template used by JavaScript to add new empty criteria to the | |
38 | * rubric being designed. | |
39 | * In this case it will use macros like {NAME}, {LEVELS}, {CRITERION-id}, etc. | |
40 | * | |
41 | * When overriding this function it is very important to remember that all elements of html | |
42 | * form (in edit or evaluate mode) must have the name $elementname. | |
ab156741 | 43 | * |
fc5adc3b MG |
44 | * Also JavaScript relies on the class names of elements and when developer changes them |
45 | * script might stop working. | |
46 | * | |
47 | * @param int $mode rubric display mode @see gradingform_rubric_controller | |
48 | * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode) | |
49 | * @param array|null $criterion criterion data | |
50 | * @param string $levels_str evaluated templates for this criterion levels | |
51 | * @param array|null $value (only in view mode) teacher's feedback on this criterion | |
ab156741 MG |
52 | * @return string |
53 | */ | |
39c6f4b6 | 54 | public function criterion_template($mode, $options, $elementname = '{NAME}', $criterion = null, $levels_str = '{LEVELS}', $value = null) { |
5060997b | 55 | // TODO description format, remark format |
ab156741 MG |
56 | if ($criterion === null || !is_array($criterion) || !array_key_exists('id', $criterion)) { |
57 | $criterion = array('id' => '{CRITERION-id}', 'description' => '{CRITERION-description}', 'sortorder' => '{CRITERION-sortorder}', 'class' => '{CRITERION-class}'); | |
58 | } else { | |
59 | foreach (array('sortorder', 'description', 'class') as $key) { | |
60 | // set missing array elements to empty strings to avoid warnings | |
61 | if (!array_key_exists($key, $criterion)) { | |
62 | $criterion[$key] = ''; | |
63 | } | |
64 | } | |
65 | } | |
39c6f4b6 | 66 | $criterion_template = html_writer::start_tag('tr', array('class' => 'criterion'. $criterion['class'], 'id' => '{NAME}-criteria-{CRITERION-id}')); |
ab156741 | 67 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) { |
8df55bbe | 68 | $criterion_template .= html_writer::start_tag('td', array('class' => 'controls')); |
ab156741 MG |
69 | foreach (array('moveup', 'delete', 'movedown') as $key) { |
70 | $value = get_string('criterion'.$key, 'gradingform_rubric'); | |
39c6f4b6 MG |
71 | $button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}]['.$key.']', |
72 | 'id' => '{NAME}-criteria-{CRITERION-id}-'.$key, 'value' => $value, 'title' => $value)); | |
ab156741 MG |
73 | $criterion_template .= html_writer::tag('div', $button, array('class' => $key)); |
74 | } | |
8df55bbe | 75 | $criterion_template .= html_writer::end_tag('td'); // .controls |
39c6f4b6 MG |
76 | $criterion_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder'])); |
77 | $description = html_writer::tag('textarea', htmlspecialchars($criterion['description']), array('name' => '{NAME}[criteria][{CRITERION-id}][description]', 'cols' => '10', 'rows' => '5')); | |
ab156741 MG |
78 | } else { |
79 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN) { | |
39c6f4b6 MG |
80 | $criterion_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder'])); |
81 | $criterion_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][description]', 'value' => $criterion['description'])); | |
ab156741 MG |
82 | } |
83 | $description = $criterion['description']; | |
84 | } | |
39c6f4b6 MG |
85 | $criterion_template .= html_writer::tag('td', $description, array('class' => 'description', 'id' => '{NAME}-criteria-{CRITERION-id}-description')); |
86 | $levels_str_table = html_writer::tag('table', html_writer::tag('tr', $levels_str, array('id' => '{NAME}-criteria-{CRITERION-id}-levels'))); | |
87 | $criterion_template .= html_writer::tag('td', $levels_str_table, array('class' => 'levels')); | |
ab156741 MG |
88 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) { |
89 | $value = get_string('criterionaddlevel', 'gradingform_rubric'); | |
39c6f4b6 MG |
90 | $button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][addlevel]', |
91 | 'id' => '{NAME}-criteria-{CRITERION-id}-levels-addlevel', 'value' => $value, 'title' => $value)); | |
8df55bbe | 92 | $criterion_template .= html_writer::tag('td', $button, array('class' => 'addlevel')); |
ab156741 | 93 | } |
39c6f4b6 MG |
94 | $displayremark = ($options['enableremarks'] && ($mode != gradingform_rubric_controller::DISPLAY_VIEW || $options['showremarksstudent'])); |
95 | if ($displayremark) { | |
5060997b | 96 | $currentremark = ''; |
39c6f4b6 MG |
97 | if (isset($value['remark'])) { |
98 | $currentremark = $value['remark']; | |
99 | } | |
100 | if ($mode == gradingform_rubric_controller::DISPLAY_EVAL) { | |
101 | $input = html_writer::tag('textarea', htmlspecialchars($currentremark), array('name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'cols' => '10', 'rows' => '5')); | |
102 | $criterion_template .= html_writer::tag('td', $input, array('class' => 'remark')); | |
103 | } else if ($mode == gradingform_rubric_controller::DISPLAY_EVAL_FROZEN) { | |
104 | $criterion_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'value' => $currentremark)); | |
105 | }else if ($mode == gradingform_rubric_controller::DISPLAY_REVIEW || $mode == gradingform_rubric_controller::DISPLAY_VIEW) { | |
106 | $criterion_template .= html_writer::tag('td', $currentremark, array('class' => 'remark')); // TODO maybe some prefix here like 'Teacher remark:' | |
107 | } | |
5060997b | 108 | } |
8df55bbe | 109 | $criterion_template .= html_writer::end_tag('tr'); // .criterion |
ab156741 MG |
110 | |
111 | $criterion_template = str_replace('{NAME}', $elementname, $criterion_template); | |
112 | $criterion_template = str_replace('{CRITERION-id}', $criterion['id'], $criterion_template); | |
113 | return $criterion_template; | |
114 | } | |
115 | ||
fc5adc3b MG |
116 | /** |
117 | * This function returns html code for displaying one level of one criterion. Depending on $mode | |
118 | * it may be the code to edit rubric, to preview the rubric, to evaluate somebody or to review the evaluation. | |
119 | * | |
120 | * This function may be called from display_rubric() to display the whole rubric, or it can be | |
121 | * called by itself to return a template used by JavaScript to add new empty level to the | |
122 | * criterion during the design of rubric. | |
123 | * In this case it will use macros like {NAME}, {CRITERION-id}, {LEVEL-id}, etc. | |
124 | * | |
125 | * When overriding this function it is very important to remember that all elements of html | |
126 | * form (in edit or evaluate mode) must have the name $elementname. | |
127 | * | |
128 | * Also JavaScript relies on the class names of elements and when developer changes them | |
129 | * script might stop working. | |
130 | * | |
131 | * @param int $mode rubric display mode @see gradingform_rubric_controller | |
132 | * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode) | |
133 | * @param string|int $criterionid either id of the nesting criterion or a macro for template | |
134 | * @param array|null $level level data, also in view mode it might also have property $level['checked'] whether this level is checked | |
135 | * @return string | |
136 | */ | |
39c6f4b6 | 137 | public function level_template($mode, $options, $elementname = '{NAME}', $criterionid = '{CRITERION-id}', $level = null) { |
ab156741 | 138 | // TODO definition format |
5060997b | 139 | if (!isset($level['id'])) { |
ab156741 MG |
140 | $level = array('id' => '{LEVEL-id}', 'definition' => '{LEVEL-definition}', 'score' => '{LEVEL-score}', 'class' => '{LEVEL-class}', 'checked' => false); |
141 | } else { | |
142 | foreach (array('score', 'definition', 'class', 'checked') as $key) { | |
143 | // set missing array elements to empty strings to avoid warnings | |
144 | if (!array_key_exists($key, $level)) { | |
145 | $level[$key] = ''; | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
150 | // Template for one level within one criterion | |
39c6f4b6 MG |
151 | $tdattributes = array('id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}', 'class' => 'level'. $level['class']); |
152 | if (isset($level['tdwidth'])) { | |
153 | $tdattributes['width'] = round($level['tdwidth']).'%'; | |
154 | } | |
155 | $level_template = html_writer::start_tag('td', $tdattributes); | |
156 | $level_template .= html_writer::start_tag('div', array('class' => 'level-wrapper')); | |
ab156741 | 157 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) { |
39c6f4b6 MG |
158 | $definition = html_writer::tag('textarea', htmlspecialchars($level['definition']), array('name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][definition]', 'cols' => '10', 'rows' => '4')); |
159 | $score = html_writer::empty_tag('input', array('type' => 'text', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][score]', 'size' => '4', 'value' => $level['score'])); | |
ab156741 MG |
160 | } else { |
161 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN) { | |
39c6f4b6 MG |
162 | $level_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][definition]', 'value' => $level['definition'])); |
163 | $level_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][score]', 'value' => $level['score'])); | |
ab156741 MG |
164 | } |
165 | $definition = $level['definition']; | |
166 | $score = $level['score']; | |
167 | } | |
168 | if ($mode == gradingform_rubric_controller::DISPLAY_EVAL) { | |
5060997b | 169 | $input = html_writer::empty_tag('input', array('type' => 'radio', 'name' => '{NAME}[criteria][{CRITERION-id}][levelid]', 'value' => $level['id']) + |
ab156741 MG |
170 | ($level['checked'] ? array('checked' => 'checked') : array())); |
171 | $level_template .= html_writer::tag('div', $input, array('class' => 'radio')); | |
172 | } | |
173 | if ($mode == gradingform_rubric_controller::DISPLAY_EVAL_FROZEN && $level['checked']) { | |
5060997b | 174 | $level_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levelid]', 'value' => $level['id'])); |
ab156741 | 175 | } |
39c6f4b6 MG |
176 | $score = html_writer::tag('span', $score, array('id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-score')); |
177 | $level_template .= html_writer::tag('div', $definition, array('class' => 'definition', 'id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-definition')); | |
178 | $displayscore = true; | |
179 | if (!$options['showscoreteacher'] && in_array($mode, array(gradingform_rubric_controller::DISPLAY_EVAL, gradingform_rubric_controller::DISPLAY_EVAL_FROZEN, gradingform_rubric_controller::DISPLAY_REVIEW))) { | |
180 | $displayscore = false; | |
181 | } | |
182 | if (!$options['showscorestudent'] && $mode == gradingform_rubric_controller::DISPLAY_VIEW) { | |
183 | $displayscore = false; | |
184 | } | |
185 | if ($displayscore) { | |
186 | $level_template .= html_writer::tag('div', $score. get_string('scorepostfix', 'gradingform_rubric'), array('class' => 'score')); | |
187 | } | |
ab156741 MG |
188 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) { |
189 | $value = get_string('leveldelete', 'gradingform_rubric'); | |
39c6f4b6 | 190 | $button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][delete]', 'id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-delete', 'value' => $value, 'title' => $value)); |
ab156741 MG |
191 | $level_template .= html_writer::tag('div', $button, array('class' => 'delete')); |
192 | } | |
39c6f4b6 | 193 | $level_template .= html_writer::end_tag('div'); // .level-wrapper |
8df55bbe | 194 | $level_template .= html_writer::end_tag('td'); // .level |
ab156741 MG |
195 | |
196 | $level_template = str_replace('{NAME}', $elementname, $level_template); | |
197 | $level_template = str_replace('{CRITERION-id}', $criterionid, $level_template); | |
198 | $level_template = str_replace('{LEVEL-id}', $level['id'], $level_template); | |
199 | return $level_template; | |
200 | } | |
201 | ||
fc5adc3b MG |
202 | /** |
203 | * This function returns html code for displaying rubric template (content before and after | |
204 | * criteria list). Depending on $mode it may be the code to edit rubric, to preview the rubric, | |
205 | * to evaluate somebody or to review the evaluation. | |
206 | * | |
207 | * This function is called from display_rubric() to display the whole rubric. | |
208 | * | |
209 | * When overriding this function it is very important to remember that all elements of html | |
210 | * form (in edit or evaluate mode) must have the name $elementname. | |
211 | * | |
212 | * Also JavaScript relies on the class names of elements and when developer changes them | |
213 | * script might stop working. | |
214 | * | |
215 | * @param int $mode rubric display mode @see gradingform_rubric_controller | |
216 | * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode) | |
217 | * @param string $criteria_str evaluated templates for this rubric's criteria | |
218 | * @return string | |
219 | */ | |
39c6f4b6 | 220 | protected function rubric_template($mode, $options, $elementname, $criteria_str) { |
ab156741 MG |
221 | $classsuffix = ''; // CSS suffix for class of the main div. Depends on the mode |
222 | switch ($mode) { | |
223 | case gradingform_rubric_controller::DISPLAY_EDIT_FULL: | |
224 | $classsuffix = ' editor editable'; break; | |
225 | case gradingform_rubric_controller::DISPLAY_EDIT_FROZEN: | |
226 | $classsuffix = ' editor frozen'; break; | |
227 | case gradingform_rubric_controller::DISPLAY_PREVIEW: | |
228 | $classsuffix = ' editor preview'; break; | |
229 | case gradingform_rubric_controller::DISPLAY_EVAL: | |
230 | $classsuffix = ' evaluate editable'; break; | |
231 | case gradingform_rubric_controller::DISPLAY_EVAL_FROZEN: | |
232 | $classsuffix = ' evaluate frozen'; break; | |
233 | case gradingform_rubric_controller::DISPLAY_REVIEW: | |
234 | $classsuffix = ' review'; break; | |
39c6f4b6 MG |
235 | case gradingform_rubric_controller::DISPLAY_VIEW: |
236 | $classsuffix = ' view'; break; | |
ab156741 MG |
237 | } |
238 | ||
fc5adc3b | 239 | $rubric_template = html_writer::start_tag('div', array('id' => 'rubric-{NAME}', 'class' => 'clearfix gradingform_rubric'.$classsuffix)); |
8df55bbe | 240 | $rubric_template .= html_writer::tag('table', $criteria_str, array('class' => 'criteria', 'id' => '{NAME}-criteria')); |
ab156741 MG |
241 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) { |
242 | $value = get_string('addcriterion', 'gradingform_rubric'); | |
39c6f4b6 | 243 | $input = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][addcriterion]', 'id' => '{NAME}-criteria-addcriterion', 'value' => $value, 'title' => $value)); |
ab156741 MG |
244 | $rubric_template .= html_writer::tag('div', $input, array('class' => 'addcriterion')); |
245 | } | |
39c6f4b6 | 246 | $rubric_template .= $this->rubric_edit_options($mode, $options); |
ab156741 MG |
247 | $rubric_template .= html_writer::end_tag('div'); |
248 | ||
249 | return str_replace('{NAME}', $elementname, $rubric_template); | |
250 | } | |
251 | ||
39c6f4b6 MG |
252 | protected function rubric_edit_options($mode, $options) { |
253 | if ($mode != gradingform_rubric_controller::DISPLAY_EDIT_FULL | |
254 | && $mode != gradingform_rubric_controller::DISPLAY_EDIT_FROZEN | |
255 | && $mode != gradingform_rubric_controller::DISPLAY_PREVIEW) { | |
256 | // Options are displayed only in edit mode | |
257 | return; | |
258 | } | |
259 | $html = html_writer::start_tag('div', array('class' => 'options')); | |
260 | $html .= html_writer::tag('div', get_string('rubricoptions', 'gradingform_rubric'), array('class' => 'optionsheading')); | |
261 | $attrs = array('type' => 'hidden', 'name' => '{NAME}[options][optionsset]', 'value' => 1); | |
262 | foreach ($options as $option => $value) { | |
263 | $html .= html_writer::start_tag('div', array('class' => 'option '.$option)); | |
264 | $attrs = array('name' => '{NAME}[options]['.$option.']', 'id' => '{NAME}-options-'.$option); | |
265 | switch ($option) { | |
266 | case 'sortlevelsasc': | |
267 | // Display option as dropdown | |
268 | $html .= html_writer::tag('span', get_string($option, 'gradingform_rubric'), array('class' => 'label')); | |
269 | $value = (int)(!!$value); // make sure $value is either 0 or 1 | |
270 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) { | |
271 | $selectoptions = array(0 => get_string($option.'0', 'gradingform_rubric'), 1 => get_string($option.'1', 'gradingform_rubric')); | |
272 | $value_str = html_writer::select($selectoptions, $attrs['name'], $value, false, array('id' => $attrs['id'])); | |
273 | $html .= html_writer::tag('span', $value_str, array('class' => 'value')); | |
274 | // TODO add here button 'Sort levels' | |
275 | } else { | |
276 | $html .= html_writer::tag('span', get_string($option.$value, 'gradingform_rubric'), array('class' => 'value')); | |
277 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN) { | |
278 | $html .= html_writer::empty_tag('input', $attrs + array('type' => 'hidden', 'value' => $value)); | |
279 | } | |
280 | } | |
281 | break; | |
282 | default: | |
283 | // Display option as checkbox | |
284 | $attrs['type'] = 'checkbox'; | |
285 | $attrs['value'] = 1; | |
286 | if ($value) { | |
287 | $attrs['checked'] = 'checked'; | |
288 | } | |
289 | if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN) { | |
290 | $attrs['disabled'] = 'disabled'; | |
291 | } | |
292 | if ($mode == gradingform_rubric_controller::DISPLAY_PREVIEW) { | |
293 | $attrs['disabled'] = 'disabled'; | |
294 | unset($attrs['name']); | |
295 | } | |
296 | $html .= html_writer::empty_tag('input', $attrs); | |
297 | $html .= html_writer::tag('label', get_string($option, 'gradingform_rubric'), array('for' => $attrs['id'])); | |
298 | break; | |
299 | } | |
300 | $html .= html_writer::end_tag('div'); // .option | |
301 | } | |
302 | $html .= html_writer::end_tag('div'); // .options | |
303 | return $html; | |
304 | } | |
305 | ||
ab156741 | 306 | /** |
fc5adc3b MG |
307 | * This function returns html code for displaying rubric. Depending on $mode it may be the code |
308 | * to edit rubric, to preview the rubric, to evaluate somebody or to review the evaluation. | |
309 | * | |
310 | * It is very unlikely that this function needs to be overriden by theme. It does not produce | |
311 | * any html code, it just prepares data about rubric design and evaluation, adds the CSS | |
312 | * class to elements and calls the functions level_template, criterion_template and | |
313 | * rubric_template | |
ab156741 | 314 | * |
fc5adc3b MG |
315 | * @param array $criteria data about the rubric design |
316 | * @param int $mode rubric display mode @see gradingform_rubric_controller | |
317 | * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode) | |
318 | * @param array $values evaluation result | |
ab156741 MG |
319 | * @return string |
320 | */ | |
39c6f4b6 | 321 | public function display_rubric($criteria, $options, $mode, $elementname = null, $values = null) { |
ab156741 MG |
322 | $criteria_str = ''; |
323 | $cnt = 0; | |
324 | foreach ($criteria as $id => $criterion) { | |
325 | $criterion['class'] = $this->get_css_class_suffix($cnt++, sizeof($criteria) -1); | |
39c6f4b6 | 326 | $criterion['id'] = $id; |
ab156741 MG |
327 | $levels_str = ''; |
328 | $levelcnt = 0; | |
5060997b MG |
329 | if (isset($values['criteria'][$id])) { |
330 | $criterionvalue = $values['criteria'][$id]; | |
331 | } else { | |
332 | $criterionvalue = null; | |
333 | } | |
ab156741 | 334 | foreach ($criterion['levels'] as $levelid => $level) { |
39c6f4b6 | 335 | $level['id'] = $levelid; |
ab156741 MG |
336 | $level['score'] = (float)$level['score']; // otherwise the display will look like 1.00000 |
337 | $level['class'] = $this->get_css_class_suffix($levelcnt++, sizeof($criterion['levels']) -1); | |
5060997b | 338 | $level['checked'] = (isset($criterionvalue['levelid']) && ((int)$criterionvalue['levelid'] === $levelid)); |
39c6f4b6 | 339 | if ($level['checked'] && ($mode == gradingform_rubric_controller::DISPLAY_EVAL_FROZEN || $mode == gradingform_rubric_controller::DISPLAY_REVIEW || $mode == gradingform_rubric_controller::DISPLAY_VIEW)) { |
ab156741 | 340 | $level['class'] .= ' checked'; |
fc5adc3b | 341 | //in mode DISPLAY_EVAL the class 'checked' will be added by JS if it is enabled. If JS is not enabled, the 'checked' class will only confuse |
ab156741 | 342 | } |
39c6f4b6 MG |
343 | $level['tdwidth'] = 100/count($criterion['levels']); |
344 | $levels_str .= $this->level_template($mode, $options, $elementname, $id, $level); | |
ab156741 | 345 | } |
39c6f4b6 | 346 | $criteria_str .= $this->criterion_template($mode, $options, $elementname, $criterion, $levels_str, $criterionvalue); |
ab156741 | 347 | } |
39c6f4b6 | 348 | return $this->rubric_template($mode, $options, $elementname, $criteria_str); |
ab156741 MG |
349 | } |
350 | ||
351 | /** | |
fc5adc3b | 352 | * Help function to return CSS class names for element (first/last/even/odd) with leading space |
ab156741 | 353 | * |
fc5adc3b MG |
354 | * @param int $cnt |
355 | * @param int $maxcnt | |
ab156741 MG |
356 | * @return string |
357 | */ | |
fc5adc3b | 358 | protected function get_css_class_suffix($cnt, $maxcnt) { |
ab156741 MG |
359 | $class = ''; |
360 | if ($cnt == 0) { | |
361 | $class .= ' first'; | |
362 | } | |
363 | if ($cnt == $maxcnt) { | |
364 | $class .= ' last'; | |
365 | } | |
366 | if ($cnt%2) { | |
367 | $class .= ' odd'; | |
368 | } else { | |
369 | $class .= ' even'; | |
370 | } | |
371 | return $class; | |
372 | } | |
36937f02 MG |
373 | |
374 | /** | |
375 | * Displays for the student the list of instances or default content if no instances found | |
376 | * | |
377 | * @param array $instances array of objects of type gradingform_rubric_instance | |
378 | * @param string $defaultcontent default string that would be displayed without advanced grading | |
379 | * @return string | |
380 | */ | |
381 | public function display_instances($instances, $defaultcontent) { | |
382 | if (sizeof($instances)) { | |
383 | $rv = html_writer::start_tag('div', array('class' => 'advancedgrade')); | |
384 | $idx = 0; | |
385 | foreach ($instances as $instance) { | |
386 | $rv .= $this->display_instance($instance, $idx++); | |
387 | } | |
388 | $rv .= html_writer::end_tag('div'); | |
389 | } | |
390 | return $rv. $defaultcontent; | |
391 | } | |
392 | ||
393 | /** | |
394 | * Displays one grading instance | |
395 | * | |
396 | * @param gradingform_rubric_instance $instance | |
397 | * @param int idx unique number of instance on page | |
398 | */ | |
399 | public function display_instance(gradingform_rubric_instance $instance, $idx) { | |
400 | $criteria = $instance->get_controller()->get_definition()->rubric_criteria; | |
39c6f4b6 | 401 | $options = $instance->get_controller()->get_options(); |
36937f02 | 402 | $values = $instance->get_rubric_filling(); |
39c6f4b6 MG |
403 | // TODO mode should be DISPLAY_REVIEW if this user is a teacher |
404 | return $this->display_rubric($criteria, $options, gradingform_rubric_controller::DISPLAY_VIEW, 'rubric'.$idx, $values); | |
36937f02 | 405 | } |
c586d2bf | 406 | } |