1 |
efrain |
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 |
* This file defines mforms to assess a submission by rubric grading strategy
|
|
|
20 |
*
|
|
|
21 |
* Rubric can be displayed in two possible layouts - list or grid. This file defines
|
|
|
22 |
* therefore defines two classes, respectively.
|
|
|
23 |
*
|
|
|
24 |
* @package workshopform_rubric
|
|
|
25 |
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
|
|
|
29 |
defined('MOODLE_INTERNAL') || die();
|
|
|
30 |
|
|
|
31 |
require_once(__DIR__ . '/../assessment_form.php'); // parent class definition
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Base class representing a form for assessing submissions by rubric grading strategy
|
|
|
35 |
*/
|
|
|
36 |
abstract class workshop_rubric_assessment_form extends workshop_assessment_form {
|
|
|
37 |
|
|
|
38 |
public function validation($data, $files) {
|
|
|
39 |
|
|
|
40 |
$errors = parent::validation($data, $files);
|
|
|
41 |
for ($i = 0; isset($data['dimensionid__idx_'.$i]); $i++) {
|
|
|
42 |
if (empty($data['chosenlevelid__idx_'.$i])) {
|
|
|
43 |
$errors['chosenlevelid__idx_'.$i] = get_string('mustchooseone', 'workshopform_rubric'); // used in grid
|
|
|
44 |
$errors['levelgrp__idx_'.$i] = get_string('mustchooseone', 'workshopform_rubric'); // used in list
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
return $errors;
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Class representing a form for assessing submissions by rubric grading strategy - list layout
|
|
|
53 |
*/
|
|
|
54 |
class workshop_rubric_list_assessment_form extends workshop_rubric_assessment_form {
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Define the elements to be displayed at the form
|
|
|
58 |
*
|
|
|
59 |
* Called by the parent::definition()
|
|
|
60 |
*
|
|
|
61 |
* @return void
|
|
|
62 |
*/
|
|
|
63 |
protected function definition_inner(&$mform) {
|
|
|
64 |
$workshop = $this->_customdata['workshop'];
|
|
|
65 |
$fields = $this->_customdata['fields'];
|
|
|
66 |
$current = $this->_customdata['current'];
|
|
|
67 |
$nodims = $this->_customdata['nodims']; // number of assessment dimensions
|
|
|
68 |
|
|
|
69 |
for ($i = 0; $i < $nodims; $i++) {
|
|
|
70 |
// dimension header
|
|
|
71 |
$dimtitle = get_string('dimensionnumber', 'workshopform_rubric', $i+1);
|
|
|
72 |
$mform->addElement('header', 'dimensionhdr__idx_'.$i, $dimtitle);
|
|
|
73 |
|
|
|
74 |
// dimension id
|
|
|
75 |
$mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i});
|
|
|
76 |
$mform->setType('dimensionid__idx_'.$i, PARAM_INT);
|
|
|
77 |
|
|
|
78 |
// grade id
|
|
|
79 |
$mform->addElement('hidden', 'gradeid__idx_'.$i); // value set by set_data() later
|
|
|
80 |
$mform->setType('gradeid__idx_'.$i, PARAM_INT);
|
|
|
81 |
|
|
|
82 |
// dimension description
|
|
|
83 |
$desc = '<div id="id_dim_'.$fields->{'dimensionid__idx_'.$i}.'_desc" class="fitem description rubric">'."\n";
|
|
|
84 |
$desc .= format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
|
|
|
85 |
$desc .= "\n</div>";
|
|
|
86 |
$mform->addElement('html', $desc);
|
|
|
87 |
|
|
|
88 |
$numoflevels = $fields->{'numoflevels__idx_'.$i};
|
|
|
89 |
$levelgrp = array();
|
|
|
90 |
for ($j = 0; $j < $numoflevels; $j++) {
|
|
|
91 |
$levelid = $fields->{'levelid__idx_'.$i.'__idy_'.$j};
|
|
|
92 |
$definition = $fields->{'definition__idx_'.$i.'__idy_'.$j};
|
|
|
93 |
$definitionformat = $fields->{'definition__idx_'.$i.'__idy_'.$j.'format'};
|
|
|
94 |
$levelgrp[] = $mform->createElement(
|
|
|
95 |
'radio',
|
|
|
96 |
"chosenlevelid__idx_{$i}",
|
|
|
97 |
'',
|
|
|
98 |
format_text($definition, $definitionformat, [
|
|
|
99 |
'context' => \core\context\course::instance($workshop->course->id),
|
|
|
100 |
]),
|
|
|
101 |
$levelid,
|
|
|
102 |
);
|
|
|
103 |
}
|
|
|
104 |
$mform->addGroup($levelgrp, 'levelgrp__idx_'.$i, '', "<br />\n", false);
|
|
|
105 |
}
|
|
|
106 |
$this->set_data($current);
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Class representing a form for assessing submissions by rubric grading strategy - grid layout
|
|
|
112 |
*/
|
|
|
113 |
class workshop_rubric_grid_assessment_form extends workshop_rubric_assessment_form {
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* Define the elements to be displayed at the form
|
|
|
117 |
*
|
|
|
118 |
* Called by the parent::definition()
|
|
|
119 |
*
|
|
|
120 |
* @return void
|
|
|
121 |
*/
|
|
|
122 |
protected function definition_inner(&$mform) {
|
|
|
123 |
$workshop = $this->_customdata['workshop'];
|
|
|
124 |
$fields = $this->_customdata['fields'];
|
|
|
125 |
$current = $this->_customdata['current'];
|
|
|
126 |
$nodims = $this->_customdata['nodims']; // number of assessment dimensions
|
|
|
127 |
|
|
|
128 |
// get the number of required grid columns
|
|
|
129 |
$levelcounts = array();
|
|
|
130 |
for ($i = 0; $i < $nodims; $i++) {
|
|
|
131 |
if ($fields->{'numoflevels__idx_'.$i} > 0) {
|
|
|
132 |
$levelcounts[] = $fields->{'numoflevels__idx_'.$i};
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
$numofcolumns = array_reduce($levelcounts, 'workshop::lcm', 1);
|
|
|
136 |
|
|
|
137 |
$mform->addElement('header', 'rubric-grid-wrapper', get_string('layoutgrid', 'workshopform_rubric'));
|
|
|
138 |
|
|
|
139 |
$mform->addElement('html', '<table class="rubric-grid">' . "\n");
|
|
|
140 |
$mform->addElement('html', '<th class="header">' . get_string('criteria', 'workshopform_rubric') . '</th>');
|
|
|
141 |
$mform->addElement('html', '<th class="header" colspan="'.$numofcolumns.'">'.get_string('levels', 'workshopform_rubric').'</th>');
|
|
|
142 |
|
|
|
143 |
for ($i = 0; $i < $nodims; $i++) {
|
|
|
144 |
|
|
|
145 |
$mform->addElement('html', '<tr class="r'. $i % 2 .'"><td class="criterion">' . "\n");
|
|
|
146 |
|
|
|
147 |
// dimension id
|
|
|
148 |
$mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i});
|
|
|
149 |
$mform->setType('dimensionid__idx_'.$i, PARAM_INT);
|
|
|
150 |
|
|
|
151 |
// given grade id
|
|
|
152 |
$mform->addElement('hidden', 'gradeid__idx_'.$i); // value set by set_data() later
|
|
|
153 |
$mform->setType('gradeid__idx_'.$i, PARAM_INT);
|
|
|
154 |
|
|
|
155 |
// dimension description
|
|
|
156 |
$desc = format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
|
|
|
157 |
$desc .= "</td>\n";
|
|
|
158 |
$mform->addElement('html', $desc);
|
|
|
159 |
|
|
|
160 |
$numoflevels = $fields->{'numoflevels__idx_'.$i};
|
|
|
161 |
for ($j = 0; $j < $numoflevels; $j++) {
|
|
|
162 |
$colspan = $numofcolumns / $numoflevels;
|
|
|
163 |
$mform->addElement('html', '<td class="level c' . $j % 2 . '" colspan="' . $colspan . '">' . "\n");
|
|
|
164 |
$levelid = $fields->{'levelid__idx_'.$i.'__idy_'.$j};
|
|
|
165 |
$definition = $fields->{'definition__idx_'.$i.'__idy_'.$j};
|
|
|
166 |
$definitionformat = $fields->{'definition__idx_'.$i.'__idy_'.$j.'format'};
|
|
|
167 |
$mform->addElement('radio', 'chosenlevelid__idx_'.$i, '',
|
|
|
168 |
format_text($definition, $definitionformat, null, $workshop->course->id), $levelid);
|
|
|
169 |
$mform->addElement('html', '</td>' . "\n");
|
|
|
170 |
}
|
|
|
171 |
$mform->addElement('html', '</tr>' . "\n");
|
|
|
172 |
}
|
|
|
173 |
$mform->addElement('html', '</table>' . "\n");
|
|
|
174 |
|
|
|
175 |
$this->set_data($current);
|
|
|
176 |
}
|
|
|
177 |
}
|