MDL-20652 workshop: more work on example submissions
[moodle.git] / mod / workshop / exassessment.php
CommitLineData
becec954
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 * Assess an example submission
20 *
21 * @package mod-workshop
22 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
27require_once(dirname(__FILE__).'/locallib.php');
28
29$asid = required_param('asid', PARAM_INT); // assessment id
30$assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
31$example = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST);
32$workshop = $DB->get_record('workshop', array('id' => $example->workshopid), '*', MUST_EXIST);
33$course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
34$cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
35
36require_login($course, false, $cm);
37if (isguestuser()) {
38 print_error('guestsarenotallowed');
39}
40$workshop = new workshop($workshop, $cm, $course);
41
42$PAGE->set_url($workshop->exassess_url($assessment->id));
43$PAGE->set_title($workshop->name);
44$PAGE->set_heading($course->fullname);
45$PAGE->navbar->add(get_string('assessingexample', 'workshop'));
46$currenttab = 'assessment';
47
48$canmanage = has_capability('mod/workshop:manageexamples', $workshop->context);
49$isreviewer = ($USER->id == $assessment->reviewerid);
50
51if ($isreviewer or $canmanage) {
52 // such a user can continue
53} else {
54 print_error('nopermissions', '', $workshop->view_url());
55}
56
57// only the reviewer is allowed to modify the assessment
58if ($canmanage or ($isreviewer and $workshop->assessing_examples_allowed())) {
59 $assessmenteditable = true;
60} else {
61 $assessmenteditable = false;
62}
63
64// load the grading strategy logic
65$strategy = $workshop->grading_strategy_instance();
66
67// load the assessment form and process the submitted data eventually
68$mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
69if ($mform->is_cancelled()) {
70 redirect($workshop->view_url());
71} elseif ($assessmenteditable and ($data = $mform->get_data())) {
72 $rawgrade = $strategy->save_assessment($assessment, $data);
73 $DB->set_field('workshop_assessments', 'reviewerid', $USER->id, array('id' => $assessment->id));
74 if (!is_null($rawgrade) and isset($data->saveandclose)) {
75 redirect($workshop->view_url());
76 } else {
77 // either it is not possible to calculate the $rawgrade
78 // or the reviewer has chosen "Save and continue"
79 redirect($PAGE->url);
80 }
81}
82
83// output starts here
84echo $OUTPUT->header();
85echo $OUTPUT->heading(get_string('assessedexample', 'workshop'), 2);
86
87$wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE); // workshop renderer
88$example = $workshop->get_example_by_id($example->id); // reload so can be passed to the renderer
89echo $wsoutput->example_full($example);
90
91if ($canmanage) {
92 echo $OUTPUT->heading(get_string('assessmentreference', 'workshop'), 2);
93} elseif ($isreviewer) {
94 echo $OUTPUT->heading(get_string('assessmentbyyourself', 'workshop'), 2);
95} else {
96 $assessment = $workshop->get_assessment_by_id($assessment->id); // extend the current record with user details
97 $reviewer = new stdClass();
98 $reviewer->firstname = $assessment->reviewerfirstname;
99 $reviewer->lastname = $assessment->reviewerlastname;
100 echo $OUTPUT->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
101}
102
103$mform->display();
104echo $OUTPUT->footer();