MDL-19941 Submission attachments and embedded files draft support
[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)) {
33 $mode = 'preview';
34 if (!$cm = get_coursemodule_from_id('workshop', $preview)) {
35 print_error('invalidcoursemodule');
36 }
37 if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
38 print_error('coursemisconf');
39 }
40 if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
41 print_error('err_invalidworkshopid', 'workshop');
42 }
43 $submission = new stdClass();
44 $assessment = new stdClass();
45} else {
46 $mode = 'assessment';
47 $assessmentid = required_param('asid', PARAM_INT); // assessment id
48 if (!$assessment = $DB->get_record('workshop_assessments', array('id' => $assessmentid))) {
49 print_error('err_unknownassessment', 'workshop');
50 }
51 if (!$submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid))) {
52 print_error('err_unknownsubmission', 'workshop');
53 }
54 if (!$workshop = $DB->get_record('workshop', array('id' => $submission->workshopid))) {
55 print_error('err_invalidworkshopid', 'workshop');
56 }
57 if (!$cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course)) {
58 print_error('invalidcoursemodule');
53fad4b9 59 }
0968b1a3
DM
60 if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
61 print_error('coursemisconf');
53fad4b9 62 }
0968b1a3
DM
63}
64
65require_login($course, false, $cm);
66
a7c5b918 67$workshop = new workshop_api($workshop, $cm, $course);
6e309973
DM
68
69$context = $PAGE->context;
0968b1a3
DM
70
71if (isguestuser()) {
72 print_error('err_noguests', 'workshop', "$CFG->wwwroot/mod/workshop/view.php?id=$cmid");
73}
74
75// where should the user be sent after closing the assessment form
76$returnurl = "{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}";
77// the URL of this handler
78if ($mode == 'preview') {
79 $selfurl = "{$CFG->wwwroot}/mod/workshop/assessment.php?preview={$cm->id}";
80} elseif ($mode == 'assessment') {
81 $selfurl = "{$CFG->wwwroot}/mod/workshop/assessment.php?asid={$assessment->id}";
82}
83// the URL to edit this assessment form
84$editurl = "{$CFG->wwwroot}/mod/workshop/editform.php?cmid={$cm->id}";
85
86// load the grading strategy logic
6e309973 87$strategy = $workshop->grading_strategy_instance();
0968b1a3
DM
88
89// load the assessment form definition from the database
90// this must be called before get_assessment_form() where we have to know
91// the number of repeating fieldsets
92
93//todo $formdata = $strategy->load_assessment($assessment);
94
0968b1a3
DM
95// load the form to edit the grading strategy dimensions
96$mform = $strategy->get_assessment_form($selfurl, $mode);
97
98// initialize form data
99//todo $mform->set_data($formdata);
100
101if ($mform->is_cancelled()) {
102 redirect($returnurl);
103} elseif ($data = $mform->get_data()) {
104 if (isset($data->backtoeditform)) {
105 redirect($editurl);
106 }
107 $strategy->save_assessment($data);
108 if (isset($data->saveandclose)) {
109 redirect($returnurl);
110 } else {
111 // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
112 redirect($selfurl);
113 }
114}
115
116// build the navigation and the header
117$navlinks = array();
53fad4b9
DM
118$navlinks[] = array('name' => get_string('modulenameplural', 'workshop'),
119 'link' => "index.php?id=$course->id",
0968b1a3 120 'type' => 'activity');
53fad4b9 121$navlinks[] = array('name' => format_string($workshop->name),
0968b1a3
DM
122 'link' => "view.php?id=$cm->id",
123 'type' => 'activityinstance');
124if ($mode == 'preview') {
53fad4b9 125 $navlinks[] = array('name' => get_string('editingassessmentform', 'workshop'),
0968b1a3
DM
126 'link' => $editurl,
127 'type' => 'title');
53fad4b9 128 $navlinks[] = array('name' => get_string('previewassessmentform', 'workshop'),
0968b1a3
DM
129 'link' => '',
130 'type' => 'title');
131} elseif ($mode == 'assessment') {
53fad4b9 132 $navlinks[] = array('name' => get_string('assessingsubmission', 'workshop'),
0968b1a3
DM
133 'link' => '',
134 'type' => 'title');
135}
136$navigation = build_navigation($navlinks);
137
138// OUTPUT STARTS HERE
139
140print_header_simple(format_string($workshop->name), '', $navigation, '', '', true, '', navmenu($course, $cm));
141
142print_heading(get_string('assessmentform', 'workshop'));
143
144$mform->display();
145
146/// Finish the page
147print_footer($course);