Uses workshop renderer to display assessment page
[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);
a7c5b918 51$workshop = new workshop_api($workshop, $cm, $course);
6e309973 52
b8ead2e6
DM
53if ('preview' == $mode) {
54 require_capability('mod/workshop:editdimensions', $PAGE->context);
55 // TODO logging add_to_log($course->id, "workshop", "view", "view.php?id=$cm->id", "$workshop->id");
56 $PAGE->set_url($workshop->previewform_url());
57 $PAGE->set_title($workshop->name);
58 $PAGE->set_heading($course->fullname);
0968b1a3 59
b8ead2e6
DM
60} elseif ('assessment' == $mode) {
61 if (!(has_capability('mod/workshop:peerassess', $PAGE->context) || has_capability('mod/workshop:peerassess', $PAGE->context))) {
62 print_error('nopermissions', '', $workshop->view_url());
63 }
64 // TODO logging add_to_log($course->id, "workshop", "view", "view.php?id=$cm->id", "$workshop->id");
65 $PAGE->set_url($workshop->assess_url($assessment->id));
66 $PAGE->set_title($workshop->name);
67 $PAGE->set_heading($course->fullname);
0968b1a3 68}
0968b1a3
DM
69
70// load the grading strategy logic
6e309973 71$strategy = $workshop->grading_strategy_instance();
0968b1a3
DM
72
73// load the assessment form definition from the database
74// this must be called before get_assessment_form() where we have to know
75// the number of repeating fieldsets
76
77//todo $formdata = $strategy->load_assessment($assessment);
78
0968b1a3 79// load the form to edit the grading strategy dimensions
b8ead2e6 80$mform = $strategy->get_assessment_form($PAGE->url, $mode);
0968b1a3
DM
81
82// initialize form data
83//todo $mform->set_data($formdata);
84
85if ($mform->is_cancelled()) {
86 redirect($returnurl);
b8ead2e6 87
0968b1a3
DM
88} elseif ($data = $mform->get_data()) {
89 if (isset($data->backtoeditform)) {
b8ead2e6 90 redirect($workshop->editform_url());
0968b1a3
DM
91 }
92 $strategy->save_assessment($data);
93 if (isset($data->saveandclose)) {
b8ead2e6 94 redirect($workshop->view_url());
0968b1a3
DM
95 } else {
96 // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
b8ead2e6 97 redirect($PAGE->url->out());
0968b1a3
DM
98 }
99}
100
101// build the navigation and the header
102$navlinks = array();
53fad4b9
DM
103$navlinks[] = array('name' => get_string('modulenameplural', 'workshop'),
104 'link' => "index.php?id=$course->id",
0968b1a3 105 'type' => 'activity');
53fad4b9 106$navlinks[] = array('name' => format_string($workshop->name),
0968b1a3
DM
107 'link' => "view.php?id=$cm->id",
108 'type' => 'activityinstance');
109if ($mode == 'preview') {
53fad4b9 110 $navlinks[] = array('name' => get_string('editingassessmentform', 'workshop'),
b8ead2e6 111 'link' => $workshop->editform_url(),
0968b1a3 112 'type' => 'title');
53fad4b9 113 $navlinks[] = array('name' => get_string('previewassessmentform', 'workshop'),
0968b1a3
DM
114 'link' => '',
115 'type' => 'title');
116} elseif ($mode == 'assessment') {
53fad4b9 117 $navlinks[] = array('name' => get_string('assessingsubmission', 'workshop'),
0968b1a3
DM
118 'link' => '',
119 'type' => 'title');
120}
121$navigation = build_navigation($navlinks);
122
b8ead2e6 123// Output starts here
0968b1a3 124
b8ead2e6
DM
125$wsoutput = $THEME->get_renderer('mod_workshop', $PAGE); // workshop renderer
126echo $OUTPUT->header($navigation);
127echo $OUTPUT->heading(get_string('assessmentform', 'workshop'), 2);
128if (has_capability('mod/workshop:viewauthornames', $PAGE->context)) {
129 $showname = true;
130 $author = $workshop->user_info($submission->userid);
131} else {
132 $showname = false;
133 $author = null;
134}
135echo $wsoutput->submission_full($submission, $showname, $author);
0968b1a3 136$mform->display();
b8ead2e6 137echo $OUTPUT->footer();