MDL-36754 output: Support token pluginfiles in group pic
[moodle.git] / mod / workshop / exassessment.php
blob9320238a2bdbf48083c9a102c3707dbb165f6dcb
1 <?php
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.
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/>.
18 /**
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);
37 if (isguestuser()) {
38 print_error('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 $currenttab = 'assessment';
48 $canmanage = has_capability('mod/workshop:manageexamples', $workshop->context);
49 $isreviewer = ($USER->id == $assessment->reviewerid);
51 if ($isreviewer or $canmanage) {
52 // such a user can continue
53 } else {
54 print_error('nopermissions', 'error', $workshop->view_url(), 'assess example submission');
57 // only the reviewer is allowed to modify the assessment
58 if (($canmanage and $assessment->weight == 1) or ($isreviewer and $workshop->assessing_examples_allowed())) {
59 $assessmenteditable = true;
60 } else {
61 $assessmenteditable = false;
64 // load the grading strategy logic
65 $strategy = $workshop->grading_strategy_instance();
67 // load the assessment form and process the submitted data eventually
68 $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
70 // Set data managed by the workshop core, subplugins set their own data themselves.
71 $currentdata = (object)array(
72 'feedbackauthor' => $assessment->feedbackauthor,
73 'feedbackauthorformat' => $assessment->feedbackauthorformat,
75 if ($assessmenteditable and $workshop->overallfeedbackmode) {
76 $currentdata = file_prepare_standard_editor($currentdata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
77 $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
78 if ($workshop->overallfeedbackfiles) {
79 $currentdata = file_prepare_standard_filemanager($currentdata, 'feedbackauthorattachment',
80 $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
81 $assessment->id);
84 $mform->set_data($currentdata);
86 if ($mform->is_cancelled()) {
87 redirect($workshop->view_url());
88 } elseif ($assessmenteditable and ($data = $mform->get_data())) {
90 // Let the grading strategy subplugin save its data.
91 $rawgrade = $strategy->save_assessment($assessment, $data);
93 // Store the data managed by the workshop core.
94 $coredata = (object)array('id' => $assessment->id);
95 if (isset($data->feedbackauthor_editor)) {
96 $coredata->feedbackauthor_editor = $data->feedbackauthor_editor;
97 $coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
98 $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
99 unset($coredata->feedbackauthor_editor);
101 if (isset($data->feedbackauthorattachment_filemanager)) {
102 $coredata->feedbackauthorattachment_filemanager = $data->feedbackauthorattachment_filemanager;
103 $coredata = file_postupdate_standard_filemanager($coredata, 'feedbackauthorattachment',
104 $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
105 $assessment->id);
106 unset($coredata->feedbackauthorattachment_filemanager);
107 if (empty($coredata->feedbackauthorattachment)) {
108 $coredata->feedbackauthorattachment = 0;
111 if ($canmanage) {
112 // Remember the last one who edited the reference assessment.
113 $coredata->reviewerid = $USER->id;
115 // Update the assessment data if there is something other than just the 'id'.
116 if (count((array)$coredata) > 1 ) {
117 $DB->update_record('workshop_assessments', $coredata);
120 if (!is_null($rawgrade) and isset($data->saveandclose)) {
121 if ($canmanage) {
122 redirect($workshop->view_url());
123 } else {
124 redirect($workshop->excompare_url($example->id, $assessment->id));
126 } else {
127 // either it is not possible to calculate the $rawgrade
128 // or the reviewer has chosen "Save and continue"
129 redirect($PAGE->url);
133 // output starts here
134 $output = $PAGE->get_renderer('mod_workshop'); // workshop renderer
135 echo $output->header();
136 echo $output->heading(format_string($workshop->name));
137 echo $output->heading(get_string('assessedexample', 'workshop'), 3);
139 $example = $workshop->get_example_by_id($example->id); // reload so can be passed to the renderer
140 echo $output->render($workshop->prepare_example_submission(($example)));
142 // show instructions for assessing as thay may contain important information
143 // for evaluating the assessment
144 if (trim($workshop->instructreviewers)) {
145 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
146 'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context));
147 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
148 echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
149 print_collapsible_region_end();
152 // extend the current assessment record with user details
153 $assessment = $workshop->get_assessment_by_id($assessment->id);
155 if ($canmanage and $assessment->weight == 1) {
156 $options = array(
157 'showreviewer' => false,
158 'showauthor' => false,
159 'showform' => true,
161 $assessment = $workshop->prepare_example_reference_assessment($assessment, $mform, $options);
162 $assessment->title = get_string('assessmentreference', 'workshop');
163 echo $output->render($assessment);
165 } else if ($isreviewer) {
166 $options = array(
167 'showreviewer' => true,
168 'showauthor' => false,
169 'showform' => true,
171 $assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
172 $assessment->title = get_string('assessmentbyyourself', 'workshop');
173 echo $output->render($assessment);
175 } else if ($canmanage) {
176 $options = array(
177 'showreviewer' => true,
178 'showauthor' => false,
179 'showform' => true,
180 'showweight' => false,
182 $assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
183 echo $output->render($assessment);
186 echo $output->footer();