MDL-20192 Moving settings.php into suplugins and a small fix
[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);
0968b1a3 61
b8ead2e6 62} elseif ('assessment' == $mode) {
a39d7d87 63 if (!has_any_capability(array('mod/workshop:peerassess', 'mod/workshop:assessallsubmissions'), $PAGE->context)) {
b8ead2e6
DM
64 print_error('nopermissions', '', $workshop->view_url());
65 }
0715308c 66 // todo do a check that the user is allowed to assess this submission
b8ead2e6
DM
67 $PAGE->set_url($workshop->assess_url($assessment->id));
68 $PAGE->set_title($workshop->name);
69 $PAGE->set_heading($course->fullname);
0968b1a3 70}
0968b1a3 71
05e69e56 72// build the navigation and the header - todo this will be changed by the new navigation api
0968b1a3 73$navlinks = array();
53fad4b9
DM
74$navlinks[] = array('name' => get_string('modulenameplural', 'workshop'),
75 'link' => "index.php?id=$course->id",
0968b1a3 76 'type' => 'activity');
53fad4b9 77$navlinks[] = array('name' => format_string($workshop->name),
0968b1a3
DM
78 'link' => "view.php?id=$cm->id",
79 'type' => 'activityinstance');
80if ($mode == 'preview') {
53fad4b9 81 $navlinks[] = array('name' => get_string('editingassessmentform', 'workshop'),
a39d7d87 82 'link' => $workshop->editform_url()->out(),
0968b1a3 83 'type' => 'title');
53fad4b9 84 $navlinks[] = array('name' => get_string('previewassessmentform', 'workshop'),
0968b1a3
DM
85 'link' => '',
86 'type' => 'title');
87} elseif ($mode == 'assessment') {
53fad4b9 88 $navlinks[] = array('name' => get_string('assessingsubmission', 'workshop'),
0968b1a3
DM
89 'link' => '',
90 'type' => 'title');
91}
92$navigation = build_navigation($navlinks);
93
05e69e56
DM
94// load the grading strategy logic
95$strategy = $workshop->grading_strategy_instance();
96
97// load the form to edit the grading strategy dimensions
98$mform = $strategy->get_assessment_form($PAGE->url, $mode, $assessment);
99
100if ($mform->is_cancelled()) {
101 redirect($workshop->view_url());
102
103} elseif ($data = $mform->get_data()) {
104 if (isset($data->backtoeditform)) {
105 // user wants to return from preview to form editing
106 redirect($workshop->editform_url());
107 }
108 $rawgrade = $strategy->save_assessment($assessment, $data);
2fe703ed 109 if (!is_null($rawgrade) and isset($data->saveandclose)) {
05e69e56
DM
110 echo $OUTPUT->header($navigation);
111 echo $OUTPUT->heading(get_string('assessmentresult', 'workshop'), 2);
2fe703ed 112 echo $OUTPUT->box('Given grade: ' . sprintf("%01.2f", $rawgrade * 100) . ' %'); // todo more detailed info using own renderer
05e69e56
DM
113 echo $OUTPUT->continue_button($workshop->view_url());
114 echo $OUTPUT->footer();
115 die(); // bye-bye
116 } else {
bc40ea0a
DM
117 // either it is not possible to calculate the $rawgrade or the reviewer has chosen "Save and continue"
118 // redirect to self to prevent data being re-posted by pressing "Reload"
05e69e56
DM
119 redirect($PAGE->url);
120 }
121}
122
b8ead2e6 123// Output starts here
0968b1a3 124
b8ead2e6
DM
125echo $OUTPUT->header($navigation);
126echo $OUTPUT->heading(get_string('assessmentform', 'workshop'), 2);
a39d7d87
DM
127
128if ('assessment' === $mode) {
129 if (has_capability('mod/workshop:viewauthornames', $PAGE->context)) {
130 $showname = true;
131 $author = $workshop->user_info($submission->userid);
132 } else {
133 $showname = false;
134 $author = null;
135 }
136 $wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE); // workshop renderer
137 echo $wsoutput->submission_full($submission, $showname, $author);
b8ead2e6 138}
a39d7d87 139
0968b1a3 140$mform->display();
b8ead2e6 141echo $OUTPUT->footer();