quiz MDL-24727 column missed from install.xml
[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 *
65601f04
DM
21 * @package mod
22 * @subpackage workshop
23 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
becec954
DM
25 */
26
27require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
28require_once(dirname(__FILE__).'/locallib.php');
29
30$asid = required_param('asid', PARAM_INT); // assessment id
31$assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
32$example = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST);
33$workshop = $DB->get_record('workshop', array('id' => $example->workshopid), '*', MUST_EXIST);
34$course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
35$cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
36
37require_login($course, false, $cm);
38if (isguestuser()) {
39 print_error('guestsarenotallowed');
40}
41$workshop = new workshop($workshop, $cm, $course);
42
43$PAGE->set_url($workshop->exassess_url($assessment->id));
44$PAGE->set_title($workshop->name);
45$PAGE->set_heading($course->fullname);
46$PAGE->navbar->add(get_string('assessingexample', 'workshop'));
47$currenttab = 'assessment';
48
49$canmanage = has_capability('mod/workshop:manageexamples', $workshop->context);
50$isreviewer = ($USER->id == $assessment->reviewerid);
51
52if ($isreviewer or $canmanage) {
53 // such a user can continue
54} else {
60719642 55 print_error('nopermissions', 'error', $workshop->view_url(), 'assess example submission');
becec954
DM
56}
57
58// only the reviewer is allowed to modify the assessment
59if ($canmanage or ($isreviewer and $workshop->assessing_examples_allowed())) {
60 $assessmenteditable = true;
61} else {
62 $assessmenteditable = false;
63}
64
65// load the grading strategy logic
66$strategy = $workshop->grading_strategy_instance();
67
68// load the assessment form and process the submitted data eventually
69$mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
70if ($mform->is_cancelled()) {
71 redirect($workshop->view_url());
72} elseif ($assessmenteditable and ($data = $mform->get_data())) {
73 $rawgrade = $strategy->save_assessment($assessment, $data);
cbf87967
DM
74 if ($canmanage) {
75 // remember the last one who edited the reference assessment
76 $DB->set_field('workshop_assessments', 'reviewerid', $USER->id, array('id' => $assessment->id));
77 }
becec954 78 if (!is_null($rawgrade) and isset($data->saveandclose)) {
cbf87967
DM
79 if ($canmanage) {
80 redirect($workshop->view_url());
81 } else {
82 redirect($workshop->excompare_url($example->id, $assessment->id));
83 }
becec954
DM
84 } else {
85 // either it is not possible to calculate the $rawgrade
86 // or the reviewer has chosen "Save and continue"
87 redirect($PAGE->url);
88 }
89}
90
91// output starts here
92echo $OUTPUT->header();
93echo $OUTPUT->heading(get_string('assessedexample', 'workshop'), 2);
94
0f6bf8c9 95$wsoutput = $PAGE->get_renderer('mod_workshop'); // workshop renderer
becec954
DM
96$example = $workshop->get_example_by_id($example->id); // reload so can be passed to the renderer
97echo $wsoutput->example_full($example);
98
e0142f7e
DM
99// show instructions for assessing as thay may contain important information
100// for evaluating the assessment
101if (trim($workshop->instructreviewers)) {
102 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
103 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
104 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
105 echo $OUTPUT->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
106 print_collapsible_region_end();
107}
108
becec954
DM
109if ($canmanage) {
110 echo $OUTPUT->heading(get_string('assessmentreference', 'workshop'), 2);
111} elseif ($isreviewer) {
112 echo $OUTPUT->heading(get_string('assessmentbyyourself', 'workshop'), 2);
113} else {
114 $assessment = $workshop->get_assessment_by_id($assessment->id); // extend the current record with user details
7a789aa8 115 $reviewer = new stdclass();
becec954
DM
116 $reviewer->firstname = $assessment->reviewerfirstname;
117 $reviewer->lastname = $assessment->reviewerlastname;
118 echo $OUTPUT->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
119}
120
121$mform->display();
122echo $OUTPUT->footer();