MDL-27550 workshop: display the feedback for the submission author when the workshop...
[moodle.git] / mod / workshop / exassessment.php
CommitLineData
becec954
DM
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 * Assess an example submission
20 *
65601f04
DM
21 * @package mod
22 * @subpackage workshop
23 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
becec954
DM
25 */
26
27require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
28require_once(dirname(__FILE__).'/locallib.php');
29
30$asid = required_param('asid', PARAM_INT); // assessment id
31$assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
32$example = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST);
33$workshop = $DB->get_record('workshop', array('id' => $example->workshopid), '*', MUST_EXIST);
34$course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
35$cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
36
37require_login($course, false, $cm);
38if (isguestuser()) {
39 print_error('guestsarenotallowed');
40}
41$workshop = new workshop($workshop, $cm, $course);
42
43$PAGE->set_url($workshop->exassess_url($assessment->id));
44$PAGE->set_title($workshop->name);
45$PAGE->set_heading($course->fullname);
46$PAGE->navbar->add(get_string('assessingexample', 'workshop'));
47$currenttab = 'assessment';
48
49$canmanage = has_capability('mod/workshop:manageexamples', $workshop->context);
50$isreviewer = ($USER->id == $assessment->reviewerid);
51
52if ($isreviewer or $canmanage) {
53 // such a user can continue
54} else {
60719642 55 print_error('nopermissions', 'error', $workshop->view_url(), 'assess example submission');
becec954
DM
56}
57
58// only the reviewer is allowed to modify the assessment
59if ($canmanage or ($isreviewer and $workshop->assessing_examples_allowed())) {
60 $assessmenteditable = true;
61} else {
62 $assessmenteditable = false;
63}
64
65// load the grading strategy logic
66$strategy = $workshop->grading_strategy_instance();
67
68// load the assessment form and process the submitted data eventually
69$mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
70if ($mform->is_cancelled()) {
71 redirect($workshop->view_url());
72} elseif ($assessmenteditable and ($data = $mform->get_data())) {
5450f7b6
DM
73 if ($canmanage) {
74 if (is_null($assessment->grade)) {
75 $workshop->log('add reference assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
76 } else {
77 $workshop->log('update reference assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
78 }
79 } else {
80 if (is_null($assessment->grade)) {
81 $workshop->log('add example assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
82 } else {
83 $workshop->log('update example assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
84 }
85 }
becec954 86 $rawgrade = $strategy->save_assessment($assessment, $data);
cbf87967
DM
87 if ($canmanage) {
88 // remember the last one who edited the reference assessment
89 $DB->set_field('workshop_assessments', 'reviewerid', $USER->id, array('id' => $assessment->id));
90 }
becec954 91 if (!is_null($rawgrade) and isset($data->saveandclose)) {
cbf87967
DM
92 if ($canmanage) {
93 redirect($workshop->view_url());
94 } else {
95 redirect($workshop->excompare_url($example->id, $assessment->id));
96 }
becec954
DM
97 } else {
98 // either it is not possible to calculate the $rawgrade
99 // or the reviewer has chosen "Save and continue"
100 redirect($PAGE->url);
101 }
102}
103
104// output starts here
81b22887
DM
105$output = $PAGE->get_renderer('mod_workshop'); // workshop renderer
106echo $output->header();
107echo $output->heading(get_string('assessedexample', 'workshop'), 2);
becec954 108
becec954 109$example = $workshop->get_example_by_id($example->id); // reload so can be passed to the renderer
81b22887 110echo $output->render($workshop->prepare_example_submission(($example)));
becec954 111
e0142f7e
DM
112// show instructions for assessing as thay may contain important information
113// for evaluating the assessment
114if (trim($workshop->instructreviewers)) {
115 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
116 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
117 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
367a75fa 118 echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
e0142f7e
DM
119 print_collapsible_region_end();
120}
121
becec954 122if ($canmanage) {
81b22887 123 echo $output->heading(get_string('assessmentreference', 'workshop'), 2);
becec954 124} elseif ($isreviewer) {
81b22887 125 echo $output->heading(get_string('assessmentbyyourself', 'workshop'), 2);
becec954
DM
126} else {
127 $assessment = $workshop->get_assessment_by_id($assessment->id); // extend the current record with user details
7a789aa8 128 $reviewer = new stdclass();
becec954
DM
129 $reviewer->firstname = $assessment->reviewerfirstname;
130 $reviewer->lastname = $assessment->reviewerlastname;
81b22887 131 echo $output->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
becec954
DM
132}
133
134$mform->display();
81b22887 135echo $output->footer();