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