mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
assessment.php
242 lines (219 loc) · 11.2 KB
/
assessment.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
<?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/>.
/**
* Assess a submission or view the single assessment
*
* Assessment id parameter must be passed. The script displays the submission and
* the assessment form. If the current user is the reviewer and the assessing is
* allowed, new assessment can be saved.
* If the assessing is not allowed (for example, the assessment period is over
* or the current user is eg a teacher), the assessment form is opened
* in a non-editable mode.
* The capability 'mod/workshop:peerassess' is intentionally not checked here.
* The user is considered as a reviewer if the corresponding assessment record
* has been prepared for him/her (during the allocation). So even a user without the
* peerassess capability (like a 'teacher', for example) can become a reviewer.
*
* @package mod
* @subpackage workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');
$asid = required_param('asid', PARAM_INT); // assessment id
$assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
$submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 0), '*', MUST_EXIST);
$workshop = $DB->get_record('workshop', array('id' => $submission->workshopid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
require_login($course, false, $cm);
if (isguestuser()) {
print_error('guestsarenotallowed');
}
$workshop = new workshop($workshop, $cm, $course);
$PAGE->set_url($workshop->assess_url($assessment->id));
$PAGE->set_title($workshop->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('assessingsubmission', 'workshop'));
$canviewallassessments = has_capability('mod/workshop:viewallassessments', $workshop->context);
$canviewallsubmissions = has_capability('mod/workshop:viewallsubmissions', $workshop->context);
$cansetassessmentweight = has_capability('mod/workshop:allocate', $workshop->context);
$canoverridegrades = has_capability('mod/workshop:overridegrades', $workshop->context);
$isreviewer = ($USER->id == $assessment->reviewerid);
$isauthor = ($USER->id == $submission->authorid);
if ($canviewallsubmissions) {
// check this flag against the group membership yet
if (groups_get_activity_groupmode($workshop->cm) == SEPARATEGROUPS) {
// user must have accessallgroups or share at least one group with the submission author
if (!has_capability('moodle/site:accessallgroups', $workshop->context)) {
$usersgroups = groups_get_activity_allowed_groups($workshop->cm);
$authorsgroups = groups_get_all_groups($workshop->course->id, $submission->authorid, $workshop->cm->groupingid, 'g.id');
$sharedgroups = array_intersect_key($usersgroups, $authorsgroups);
if (empty($sharedgroups)) {
$canviewallsubmissions = false;
}
}
}
}
if ($isreviewer or $isauthor or ($canviewallassessments and $canviewallsubmissions)) {
// such a user can continue
} else {
print_error('nopermissions', 'error', $workshop->view_url(), 'view this assessment');
}
if ($isauthor and !$isreviewer and !$canviewallassessments and $workshop->phase != workshop::PHASE_CLOSED) {
// authors can see assessments of their work at the end of workshop only
print_error('nopermissions', 'error', $workshop->view_url(), 'view assessment of own work before workshop is closed');
}
// only the reviewer is allowed to modify the assessment
if ($isreviewer and $workshop->assessing_allowed($USER->id)) {
$assessmenteditable = true;
} else {
$assessmenteditable = false;
}
// check that all required examples have been assessed by the user
if ($assessmenteditable and $workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT
and !has_capability('mod/workshop:manageexamples', $workshop->context)) {
// the reviewer must have submitted their own submission
$reviewersubmission = $workshop->get_submission_by_author($assessment->reviewerid);
if (!$reviewersubmission) {
// no money, no love
$assessmenteditable = false;
echo $output->header();
echo $output->heading(get_string('exampleneedsubmission', 'workshop'), 2);
echo $output->footer();
exit;
} else {
$examples = $workshop->get_examples_for_reviewer($assessment->reviewerid);
foreach ($examples as $exampleid => $example) {
if (is_null($example->grade)) {
$assessmenteditable = false;
echo $output->header();
echo $output->heading(get_string('exampleneedassessed', 'workshop'), 2);
echo $output->footer();
exit;
}
}
}
}
// load the grading strategy logic
$strategy = $workshop->grading_strategy_instance();
if (is_null($assessment->grade) and !$assessmenteditable) {
$mform = null;
} else {
// Are there any other pending assessments to do but this one?
if ($assessmenteditable) {
$pending = $workshop->get_pending_assessments_by_reviewer($assessment->reviewerid, $assessment->id);
} else {
$pending = array();
}
// load the assessment form and process the submitted data eventually
$mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable,
array('editableweight' => $cansetassessmentweight, 'pending' => !empty($pending)));
$mform->set_data(array('weight' => $assessment->weight)); // other values are set by subplugins
if ($mform->is_cancelled()) {
redirect($workshop->view_url());
} elseif ($assessmenteditable and ($data = $mform->get_data())) {
if (is_null($assessment->grade)) {
$workshop->log('add assessment', $workshop->assess_url($assessment->id), $assessment->submissionid);
} else {
$workshop->log('update assessment', $workshop->assess_url($assessment->id), $assessment->submissionid);
}
$rawgrade = $strategy->save_assessment($assessment, $data);
if (isset($data->weight) and $cansetassessmentweight) {
$DB->set_field('workshop_assessments', 'weight', $data->weight, array('id' => $assessment->id));
}
if (!is_null($rawgrade) and isset($data->saveandclose)) {
redirect($workshop->view_url());
} else if (!is_null($rawgrade) and isset($data->saveandshownext)) {
$next = reset($pending);
if (!empty($next)) {
redirect($workshop->assess_url($next->id));
} else {
redirect($PAGE->url); // This should never happen but just in case...
}
} else {
// either it is not possible to calculate the $rawgrade
// or the reviewer has chosen "Save and continue"
redirect($PAGE->url);
}
}
}
// load the form to override gradinggrade and/or set weight and process the submitted data eventually
if ($canoverridegrades or $cansetassessmentweight) {
$options = array(
'editable' => true,
'editableweight' => $cansetassessmentweight,
'overridablegradinggrade' => $canoverridegrades);
$feedbackform = $workshop->get_feedbackreviewer_form($PAGE->url, $assessment, $options);
if ($data = $feedbackform->get_data()) {
$data = file_postupdate_standard_editor($data, 'feedbackreviewer', array(), $workshop->context);
$record = new stdclass();
$record->id = $assessment->id;
if ($cansetassessmentweight) {
$record->weight = $data->weight;
}
if ($canoverridegrades) {
$record->gradinggradeover = $workshop->raw_grade_value($data->gradinggradeover, $workshop->gradinggrade);
$record->gradinggradeoverby = $USER->id;
$record->feedbackreviewer = $data->feedbackreviewer;
$record->feedbackreviewerformat = $data->feedbackreviewerformat;
}
$DB->update_record('workshop_assessments', $record);
redirect($workshop->view_url());
}
}
// output starts here
$output = $PAGE->get_renderer('mod_workshop'); // workshop renderer
echo $output->header();
echo $output->heading(get_string('assessedsubmission', 'workshop'), 2);
$submission = $workshop->get_submission_by_id($submission->id); // reload so can be passed to the renderer
echo $output->render($workshop->prepare_submission($submission, has_capability('mod/workshop:viewauthornames', $workshop->context)));
// show instructions for assessing as they may contain important information
// for evaluating the assessment
if (trim($workshop->instructreviewers)) {
$instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
print_collapsible_region_end();
}
// extend the current assessment record with user details
$assessment = $workshop->get_assessment_by_id($assessment->id);
if ($isreviewer) {
$options = array(
'showreviewer' => true,
'showauthor' => has_capability('mod/workshop:viewauthornames', $workshop->context),
'showform' => $assessmenteditable or !is_null($assessment->grade),
'showweight' => true,
);
$assessment = $workshop->prepare_assessment($assessment, $mform, $options);
$assessment->title = get_string('assessmentbyyourself', 'workshop');
echo $output->render($assessment);
} else {
$options = array(
'showreviewer' => has_capability('mod/workshop:viewreviewernames', $workshop->context),
'showauthor' => has_capability('mod/workshop:viewauthornames', $workshop->context),
'showform' => $assessmenteditable or !is_null($assessment->grade),
'showweight' => true,
);
$assessment = $workshop->prepare_assessment($assessment, $mform, $options);
echo $output->render($assessment);
}
if (!$assessmenteditable and $canoverridegrades) {
$feedbackform->display();
}
echo $output->footer();