forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexassessment.php
190 lines (166 loc) · 8.03 KB
/
exassessment.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
<?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 an example submission
*
* @package mod_workshop
* @copyright 2009 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/locallib.php');
$asid = required_param('asid', PARAM_INT); // assessment id
$assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
$example = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST);
$workshop = $DB->get_record('workshop', array('id' => $example->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()) {
throw new \moodle_exception('guestsarenotallowed');
}
$workshop = new workshop($workshop, $cm, $course);
$PAGE->set_url($workshop->exassess_url($assessment->id));
$PAGE->set_title($workshop->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('assessingexample', 'workshop'));
$PAGE->set_secondary_active_tab('modulepage');
$currenttab = 'assessment';
$canmanage = has_capability('mod/workshop:manageexamples', $workshop->context);
$isreviewer = ($USER->id == $assessment->reviewerid);
if ($isreviewer or $canmanage) {
// such a user can continue
} else {
throw new \moodle_exception('nopermissions', 'error', $workshop->view_url(), 'assess example submission');
}
// only the reviewer is allowed to modify the assessment
if (($canmanage and $assessment->weight == 1) or ($isreviewer and $workshop->assessing_examples_allowed())) {
$assessmenteditable = true;
} else {
$assessmenteditable = false;
}
// load the grading strategy logic
$strategy = $workshop->grading_strategy_instance();
// load the assessment form and process the submitted data eventually
$mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
// Set data managed by the workshop core, subplugins set their own data themselves.
$currentdata = (object)array(
'feedbackauthor' => $assessment->feedbackauthor,
'feedbackauthorformat' => $assessment->feedbackauthorformat,
);
if ($assessmenteditable and $workshop->overallfeedbackmode) {
$currentdata = file_prepare_standard_editor($currentdata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
$workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
if ($workshop->overallfeedbackfiles) {
$currentdata = file_prepare_standard_filemanager($currentdata, 'feedbackauthorattachment',
$workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
$assessment->id);
}
}
$mform->set_data($currentdata);
if ($mform->is_cancelled()) {
redirect($workshop->view_url());
} elseif ($assessmenteditable and ($data = $mform->get_data())) {
// Let the grading strategy subplugin save its data.
$rawgrade = $strategy->save_assessment($assessment, $data);
// Store the data managed by the workshop core.
$coredata = (object)array('id' => $assessment->id);
if (isset($data->feedbackauthor_editor)) {
$coredata->feedbackauthor_editor = $data->feedbackauthor_editor;
$coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
$workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
unset($coredata->feedbackauthor_editor);
}
if (isset($data->feedbackauthorattachment_filemanager)) {
$coredata->feedbackauthorattachment_filemanager = $data->feedbackauthorattachment_filemanager;
$coredata = file_postupdate_standard_filemanager($coredata, 'feedbackauthorattachment',
$workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
$assessment->id);
unset($coredata->feedbackauthorattachment_filemanager);
if (empty($coredata->feedbackauthorattachment)) {
$coredata->feedbackauthorattachment = 0;
}
}
if ($canmanage) {
// Remember the last one who edited the reference assessment.
$coredata->reviewerid = $USER->id;
}
// Update the assessment data if there is something other than just the 'id'.
if (count((array)$coredata) > 1 ) {
$DB->update_record('workshop_assessments', $coredata);
}
if (!is_null($rawgrade) and isset($data->saveandclose)) {
if ($canmanage) {
redirect($workshop->view_url());
} else {
redirect($workshop->excompare_url($example->id, $assessment->id));
}
} else {
// either it is not possible to calculate the $rawgrade
// or the reviewer has chosen "Save and continue"
redirect($PAGE->url);
}
}
// output starts here
$output = $PAGE->get_renderer('mod_workshop'); // workshop renderer
echo $output->header();
if (!$PAGE->has_secondary_navigation()) {
echo $output->heading(format_string($workshop->name));
}
echo $output->heading(get_string('assessedexample', 'workshop'), 3);
$example = $workshop->get_example_by_id($example->id); // reload so can be passed to the renderer
echo $output->render($workshop->prepare_example_submission(($example)));
// show instructions for assessing as thay 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', null, workshop::instruction_editors_options($PAGE->context));
print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'),
'workshop-viewlet-instructreviewers-collapsed');
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 ($canmanage and $assessment->weight == 1) {
$options = array(
'showreviewer' => false,
'showauthor' => false,
'showform' => true,
);
$assessment = $workshop->prepare_example_reference_assessment($assessment, $mform, $options);
$assessment->title = get_string('assessmentreference', 'workshop');
echo $output->render($assessment);
} else if ($isreviewer) {
$options = array(
'showreviewer' => true,
'showauthor' => false,
'showform' => true,
);
$assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
$assessment->title = get_string('assessmentbyyourself', 'workshop');
echo $output->render($assessment);
} else if ($canmanage) {
$options = array(
'showreviewer' => true,
'showauthor' => false,
'showform' => true,
'showweight' => false,
);
$assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
echo $output->render($assessment);
}
echo $output->footer();