Fixed submission grade aggregation
[moodle.git] / mod / workshop / assessment.php
CommitLineData
0968b1a3 1<?php
53fad4b9
DM
2
3// This file is part of Moodle - http://moodle.org/
4//
0968b1a3
DM
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.
53fad4b9 14//
0968b1a3
DM
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/>.
53fad4b9 17
0968b1a3
DM
18/**
19 * Assess a submission or preview the assessment form
20 *
21 * Displays an assessment form and saves the grades given by current user (reviewer)
22 * for the dimensions.
23 *
24 * @package mod-workshop
25 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 */
28
29require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
0968b1a3
DM
30require_once(dirname(__FILE__).'/locallib.php');
31
32if ($preview = optional_param('preview', 0, PARAM_INT)) {
b8ead2e6
DM
33 $mode = 'preview';
34 $cm = get_coursemodule_from_id('workshop', $preview, 0, false, MUST_EXIST);
35 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
36 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
65ba104c
DM
37 $submission = new stdClass();
38 $assessment = new stdClass();
b8ead2e6 39
0968b1a3 40} else {
b8ead2e6
DM
41 $mode = 'assessment';
42 $asid = required_param('asid', PARAM_INT); // assessment id
43 $assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
44 $submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid), '*', MUST_EXIST);
45 $workshop = $DB->get_record('workshop', array('id' => $submission->workshopid), '*', MUST_EXIST);
46 $course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
47 $cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
0968b1a3
DM
48}
49
50require_login($course, false, $cm);
a39d7d87
DM
51if (isguestuser()) {
52 print_error('guestsarenotallowed');
53}
54$workshop = new workshop($workshop, $cm, $course);
6e309973 55
b8ead2e6
DM
56if ('preview' == $mode) {
57 require_capability('mod/workshop:editdimensions', $PAGE->context);
b8ead2e6
DM
58 $PAGE->set_url($workshop->previewform_url());
59 $PAGE->set_title($workshop->name);
60 $PAGE->set_heading($course->fullname);
b761e6d9 61 $PAGE->navbar->add(get_string('editingassessmentform', 'workshop'), $workshop->editform_url(), navigation_node::TYPE_CUSTOM);
39861053 62 $PAGE->navbar->add(get_string('previewassessmentform', 'workshop'));
b761e6d9 63 $currenttab = 'editform';
0968b1a3 64
b8ead2e6 65} elseif ('assessment' == $mode) {
b761e6d9
DM
66 // we do not require 'mod/workshop:peerassess' here, we just check that the assessment record
67 // has been prepared for the current user. So even a user without the peerassess capability
68 // (like a 'teacher', for example) can become a reviewer
00aca3c1 69 if ($USER->id !== $assessment->reviewerid) {
b8ead2e6
DM
70 print_error('nopermissions', '', $workshop->view_url());
71 }
b8ead2e6
DM
72 $PAGE->set_url($workshop->assess_url($assessment->id));
73 $PAGE->set_title($workshop->name);
74 $PAGE->set_heading($course->fullname);
39861053 75 $PAGE->navbar->add(get_string('assessingsubmission', 'workshop'));
b761e6d9 76 $currenttab = 'assessment';
0968b1a3 77}
0968b1a3 78
05e69e56
DM
79// load the grading strategy logic
80$strategy = $workshop->grading_strategy_instance();
81
82// load the form to edit the grading strategy dimensions
83$mform = $strategy->get_assessment_form($PAGE->url, $mode, $assessment);
84
85if ($mform->is_cancelled()) {
86 redirect($workshop->view_url());
87
88} elseif ($data = $mform->get_data()) {
89 if (isset($data->backtoeditform)) {
90 // user wants to return from preview to form editing
91 redirect($workshop->editform_url());
92 }
93 $rawgrade = $strategy->save_assessment($assessment, $data);
2fe703ed 94 if (!is_null($rawgrade) and isset($data->saveandclose)) {
39861053 95 echo $OUTPUT->header();
05e69e56 96 echo $OUTPUT->heading(get_string('assessmentresult', 'workshop'), 2);
00aca3c1 97 echo $OUTPUT->box('Given grade: ' . $rawgrade . ' %'); // todo more detailed info using own renderer, format grade
05e69e56
DM
98 echo $OUTPUT->continue_button($workshop->view_url());
99 echo $OUTPUT->footer();
100 die(); // bye-bye
101 } else {
bc40ea0a
DM
102 // either it is not possible to calculate the $rawgrade or the reviewer has chosen "Save and continue"
103 // redirect to self to prevent data being re-posted by pressing "Reload"
05e69e56
DM
104 redirect($PAGE->url);
105 }
106}
107
b8ead2e6 108// Output starts here
0968b1a3 109
39861053 110echo $OUTPUT->header();
b8ead2e6 111echo $OUTPUT->heading(get_string('assessmentform', 'workshop'), 2);
a39d7d87
DM
112
113if ('assessment' === $mode) {
114 if (has_capability('mod/workshop:viewauthornames', $PAGE->context)) {
115 $showname = true;
00aca3c1 116 $author = $workshop->user_info($submission->authorid);
a39d7d87
DM
117 } else {
118 $showname = false;
119 $author = null;
120 }
ddb59c77
DM
121 $wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE); // workshop renderer
122 $submission = $workshop->get_submission_by_id($submission->id); // reload so can be passed to the renderer
123 echo $wsoutput->submission_full($submission, $showname);
b8ead2e6 124}
a39d7d87 125
0968b1a3 126$mform->display();
b8ead2e6 127echo $OUTPUT->footer();