3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * Assess an example submission
21 * @package mod_workshop
22 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require(__DIR__
.'/../../config.php');
27 require_once(__DIR__
.'/locallib.php');
29 $asid = required_param('asid', PARAM_INT
); // assessment id
30 $assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST
);
31 $example = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid
, 'example' => 1), '*', MUST_EXIST
);
32 $workshop = $DB->get_record('workshop', array('id' => $example->workshopid
), '*', MUST_EXIST
);
33 $course = $DB->get_record('course', array('id' => $workshop->course
), '*', MUST_EXIST
);
34 $cm = get_coursemodule_from_instance('workshop', $workshop->id
, $course->id
, false, MUST_EXIST
);
36 require_login($course, false, $cm);
38 throw new \
moodle_exception('guestsarenotallowed');
40 $workshop = new workshop($workshop, $cm, $course);
42 $PAGE->set_url($workshop->exassess_url($assessment->id
));
43 $PAGE->set_title($workshop->name
);
44 $PAGE->set_heading($course->fullname
);
45 $PAGE->navbar
->add(get_string('assessingexample', 'workshop'));
46 $PAGE->set_secondary_active_tab('modulepage');
47 $currenttab = 'assessment';
49 $canmanage = has_capability('mod/workshop:manageexamples', $workshop->context
);
50 $isreviewer = ($USER->id
== $assessment->reviewerid
);
52 if ($isreviewer or $canmanage) {
53 // such a user can continue
55 throw new \
moodle_exception('nopermissions', 'error', $workshop->view_url(), 'assess example submission');
58 // only the reviewer is allowed to modify the assessment
59 if (($canmanage and $assessment->weight
== 1) or ($isreviewer and $workshop->assessing_examples_allowed())) {
60 $assessmenteditable = true;
62 $assessmenteditable = false;
65 // load the grading strategy logic
66 $strategy = $workshop->grading_strategy_instance();
68 // load the assessment form and process the submitted data eventually
69 $mform = $strategy->get_assessment_form($PAGE->url
, 'assessment', $assessment, $assessmenteditable);
71 // Set data managed by the workshop core, subplugins set their own data themselves.
72 $currentdata = (object)array(
73 'feedbackauthor' => $assessment->feedbackauthor
,
74 'feedbackauthorformat' => $assessment->feedbackauthorformat
,
76 if ($assessmenteditable and $workshop->overallfeedbackmode
) {
77 $currentdata = file_prepare_standard_editor($currentdata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
78 $workshop->context
, 'mod_workshop', 'overallfeedback_content', $assessment->id
);
79 if ($workshop->overallfeedbackfiles
) {
80 $currentdata = file_prepare_standard_filemanager($currentdata, 'feedbackauthorattachment',
81 $workshop->overall_feedback_attachment_options(), $workshop->context
, 'mod_workshop', 'overallfeedback_attachment',
85 $mform->set_data($currentdata);
87 if ($mform->is_cancelled()) {
88 redirect($workshop->view_url());
89 } elseif ($assessmenteditable and ($data = $mform->get_data())) {
91 // Let the grading strategy subplugin save its data.
92 $rawgrade = $strategy->save_assessment($assessment, $data);
94 // Store the data managed by the workshop core.
95 $coredata = (object)array('id' => $assessment->id
);
96 if (isset($data->feedbackauthor_editor
)) {
97 $coredata->feedbackauthor_editor
= $data->feedbackauthor_editor
;
98 $coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
99 $workshop->context
, 'mod_workshop', 'overallfeedback_content', $assessment->id
);
100 unset($coredata->feedbackauthor_editor
);
102 if (isset($data->feedbackauthorattachment_filemanager
)) {
103 $coredata->feedbackauthorattachment_filemanager
= $data->feedbackauthorattachment_filemanager
;
104 $coredata = file_postupdate_standard_filemanager($coredata, 'feedbackauthorattachment',
105 $workshop->overall_feedback_attachment_options(), $workshop->context
, 'mod_workshop', 'overallfeedback_attachment',
107 unset($coredata->feedbackauthorattachment_filemanager
);
108 if (empty($coredata->feedbackauthorattachment
)) {
109 $coredata->feedbackauthorattachment
= 0;
113 // Remember the last one who edited the reference assessment.
114 $coredata->reviewerid
= $USER->id
;
116 // Update the assessment data if there is something other than just the 'id'.
117 if (count((array)$coredata) > 1 ) {
118 $DB->update_record('workshop_assessments', $coredata);
121 if (!is_null($rawgrade) and isset($data->saveandclose
)) {
123 redirect($workshop->view_url());
125 redirect($workshop->excompare_url($example->id
, $assessment->id
));
128 // either it is not possible to calculate the $rawgrade
129 // or the reviewer has chosen "Save and continue"
130 redirect($PAGE->url
);
134 // output starts here
135 $output = $PAGE->get_renderer('mod_workshop'); // workshop renderer
136 echo $output->header();
137 if (!$PAGE->has_secondary_navigation()) {
138 echo $output->heading(format_string($workshop->name
));
140 echo $output->heading(get_string('assessedexample', 'workshop'), 3);
142 $example = $workshop->get_example_by_id($example->id
); // reload so can be passed to the renderer
143 echo $output->render($workshop->prepare_example_submission(($example)));
145 // show instructions for assessing as thay may contain important information
146 // for evaluating the assessment
147 if (trim($workshop->instructreviewers
)) {
148 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers
, 'pluginfile.php', $PAGE->context
->id
,
149 'mod_workshop', 'instructreviewers', null, workshop
::instruction_editors_options($PAGE->context
));
150 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'),
151 'workshop-viewlet-instructreviewers-collapsed');
152 echo $output->box(format_text($instructions, $workshop->instructreviewersformat
, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
153 print_collapsible_region_end();
156 // extend the current assessment record with user details
157 $assessment = $workshop->get_assessment_by_id($assessment->id
);
159 if ($canmanage and $assessment->weight
== 1) {
161 'showreviewer' => false,
162 'showauthor' => false,
165 $assessment = $workshop->prepare_example_reference_assessment($assessment, $mform, $options);
166 $assessment->title
= get_string('assessmentreference', 'workshop');
167 echo $output->render($assessment);
169 } else if ($isreviewer) {
171 'showreviewer' => true,
172 'showauthor' => false,
175 $assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
176 $assessment->title
= get_string('assessmentbyyourself', 'workshop');
177 echo $output->render($assessment);
179 } else if ($canmanage) {
181 'showreviewer' => true,
182 'showauthor' => false,
184 'showweight' => false,
186 $assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
187 echo $output->render($assessment);
190 echo $output->footer();