First drafts of assessment support
[moodle.git] / mod / workshop / assessment.php
CommitLineData
0968b1a3
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/**
20 * Assess a submission or preview the assessment form
21 *
22 * Displays an assessment form and saves the grades given by current user (reviewer)
23 * for the dimensions.
24 *
25 * @package mod-workshop
26 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 */
29
30require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
31//require_once(dirname(__FILE__).'/lib.php');
32require_once(dirname(__FILE__).'/locallib.php');
33
34if ($preview = optional_param('preview', 0, PARAM_INT)) {
35 $mode = 'preview';
36 if (!$cm = get_coursemodule_from_id('workshop', $preview)) {
37 print_error('invalidcoursemodule');
38 }
39 if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
40 print_error('coursemisconf');
41 }
42 if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
43 print_error('err_invalidworkshopid', 'workshop');
44 }
45 $submission = new stdClass();
46 $assessment = new stdClass();
47} else {
48 $mode = 'assessment';
49 $assessmentid = required_param('asid', PARAM_INT); // assessment id
50 if (!$assessment = $DB->get_record('workshop_assessments', array('id' => $assessmentid))) {
51 print_error('err_unknownassessment', 'workshop');
52 }
53 if (!$submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid))) {
54 print_error('err_unknownsubmission', 'workshop');
55 }
56 if (!$workshop = $DB->get_record('workshop', array('id' => $submission->workshopid))) {
57 print_error('err_invalidworkshopid', 'workshop');
58 }
59 if (!$cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course)) {
60 print_error('invalidcoursemodule');
61 }
62 if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
63 print_error('coursemisconf');
64 }
65}
66
67require_login($course, false, $cm);
68
69$context = get_context_instance(CONTEXT_MODULE, $cm->id);
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
87$strategy = workshop_strategy_instance($workshop);
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
95
96
97// load the form to edit the grading strategy dimensions
98$mform = $strategy->get_assessment_form($selfurl, $mode);
99
100// initialize form data
101//todo $mform->set_data($formdata);
102
103if ($mform->is_cancelled()) {
104 redirect($returnurl);
105} elseif ($data = $mform->get_data()) {
106 if (isset($data->backtoeditform)) {
107 redirect($editurl);
108 }
109 $strategy->save_assessment($data);
110 if (isset($data->saveandclose)) {
111 redirect($returnurl);
112 } else {
113 // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
114 redirect($selfurl);
115 }
116}
117
118// build the navigation and the header
119$navlinks = array();
120$navlinks[] = array('name' => get_string('modulenameplural', 'workshop'),
121 'link' => "index.php?id=$course->id",
122 'type' => 'activity');
123$navlinks[] = array('name' => format_string($workshop->name),
124 'link' => "view.php?id=$cm->id",
125 'type' => 'activityinstance');
126if ($mode == 'preview') {
127 $navlinks[] = array('name' => get_string('editingassessmentform', 'workshop'),
128 'link' => $editurl,
129 'type' => 'title');
130 $navlinks[] = array('name' => get_string('previewassessmentform', 'workshop'),
131 'link' => '',
132 'type' => 'title');
133} elseif ($mode == 'assessment') {
134 $navlinks[] = array('name' => get_string('assessingsubmission', 'workshop'),
135 'link' => '',
136 'type' => 'title');
137}
138$navigation = build_navigation($navlinks);
139
140// OUTPUT STARTS HERE
141
142print_header_simple(format_string($workshop->name), '', $navigation, '', '', true, '', navmenu($course, $cm));
143
144print_heading(get_string('assessmentform', 'workshop'));
145
146$mform->display();
147
148/// Finish the page
149print_footer($course);