Fixed regressions
[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);
0968b1a3
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
DM
71
72// load the grading strategy logic
6e309973 73$strategy = $workshop->grading_strategy_instance();
0968b1a3 74
0968b1a3 75// load the form to edit the grading strategy dimensions
0715308c 76$mform = $strategy->get_assessment_form($PAGE->url, $mode, $assessment);
0968b1a3 77
0968b1a3 78if ($mform->is_cancelled()) {
0715308c 79 redirect($workshop->view_url());
b8ead2e6 80
0968b1a3
DM
81} elseif ($data = $mform->get_data()) {
82 if (isset($data->backtoeditform)) {
a39d7d87 83 // user wants to return from preview to form editing
b8ead2e6 84 redirect($workshop->editform_url());
0968b1a3 85 }
a39d7d87 86 $strategy->save_assessment($assessment, $data);
0968b1a3 87 if (isset($data->saveandclose)) {
b8ead2e6 88 redirect($workshop->view_url());
0968b1a3
DM
89 } else {
90 // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
a39d7d87 91 redirect($PAGE->url);
0968b1a3
DM
92 }
93}
94
95// build the navigation and the header
96$navlinks = array();
53fad4b9
DM
97$navlinks[] = array('name' => get_string('modulenameplural', 'workshop'),
98 'link' => "index.php?id=$course->id",
0968b1a3 99 'type' => 'activity');
53fad4b9 100$navlinks[] = array('name' => format_string($workshop->name),
0968b1a3
DM
101 'link' => "view.php?id=$cm->id",
102 'type' => 'activityinstance');
103if ($mode == 'preview') {
53fad4b9 104 $navlinks[] = array('name' => get_string('editingassessmentform', 'workshop'),
a39d7d87 105 'link' => $workshop->editform_url()->out(),
0968b1a3 106 'type' => 'title');
53fad4b9 107 $navlinks[] = array('name' => get_string('previewassessmentform', 'workshop'),
0968b1a3
DM
108 'link' => '',
109 'type' => 'title');
110} elseif ($mode == 'assessment') {
53fad4b9 111 $navlinks[] = array('name' => get_string('assessingsubmission', 'workshop'),
0968b1a3
DM
112 'link' => '',
113 'type' => 'title');
114}
115$navigation = build_navigation($navlinks);
116
b8ead2e6 117// Output starts here
0968b1a3 118
b8ead2e6
DM
119echo $OUTPUT->header($navigation);
120echo $OUTPUT->heading(get_string('assessmentform', 'workshop'), 2);
a39d7d87
DM
121
122if ('assessment' === $mode) {
123 if (has_capability('mod/workshop:viewauthornames', $PAGE->context)) {
124 $showname = true;
125 $author = $workshop->user_info($submission->userid);
126 } else {
127 $showname = false;
128 $author = null;
129 }
130 $wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE); // workshop renderer
131 echo $wsoutput->submission_full($submission, $showname, $author);
b8ead2e6 132}
a39d7d87 133
0968b1a3 134$mform->display();
b8ead2e6 135echo $OUTPUT->footer();