MDL-27550 workshop: assessments are now displayed via proper rendering subsystem
[moodle.git] / mod / workshop / excompare.php
1 <?php
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/>.
18 /**
19  * Display example submission followed by its reference assessment and the user's assessment to compare them
20  *
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
25  */
27 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
28 require_once(dirname(__FILE__).'/locallib.php');
30 $cmid   = required_param('cmid', PARAM_INT);    // course module id
31 $sid    = required_param('sid', PARAM_INT);     // example submission id
32 $aid    = required_param('aid', PARAM_INT);     // the user's assessment id
34 $cm     = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
35 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
37 require_login($course, false, $cm);
38 if (isguestuser()) {
39     print_error('guestsarenotallowed');
40 }
42 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
43 $workshop = new workshop($workshop, $cm, $course);
44 $strategy = $workshop->grading_strategy_instance();
46 $PAGE->set_url($workshop->excompare_url($sid, $aid));
48 $example    = $workshop->get_example_by_id($sid);
49 $assessment = $workshop->get_assessment_by_id($aid);
50 if ($assessment->submissionid != $example->id) {
51    print_error('invalidarguments');
52 }
53 $mformassessment = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, false);
54 if ($refasid = $DB->get_field('workshop_assessments', 'id', array('submissionid' => $example->id, 'weight' => 1))) {
55     $reference = $workshop->get_assessment_by_id($refasid);
56     $mformreference = $strategy->get_assessment_form($PAGE->url, 'assessment', $reference, false);
57 }
59 $canmanage  = has_capability('mod/workshop:manageexamples', $workshop->context);
60 $isreviewer = ($USER->id == $assessment->reviewerid);
62 if ($canmanage) {
63     // ok you can go
64 } elseif ($isreviewer and $workshop->assessing_examples_allowed()) {
65     // ok you can go
66 } else {
67     print_error('nopermissions', 'error', $workshop->view_url(), 'compare example assessment');
68 }
70 $PAGE->set_title($workshop->name);
71 $PAGE->set_heading($course->fullname);
72 $PAGE->navbar->add(get_string('examplecomparing', 'workshop'));
74 // Output starts here
75 $output = $PAGE->get_renderer('mod_workshop');
76 echo $output->header();
77 echo $output->heading(get_string('assessedexample', 'workshop'), 2);
79 echo $output->render($workshop->prepare_example_submission($example));
81 // if the reference assessment is available, display it
82 if (!empty($mformreference)) {
83     $options = array(
84         'showreviewer'  => false,
85         'showauthor'    => false,
86         'showform'      => true,
87         'showweight'    => false,
88     );
89     $reference = $workshop->prepare_assessment($reference, $mformreference, $options);
90     $reference->title = get_string('assessmentreference', 'workshop');
91     echo $output->render($reference);
92 }
94 if ($isreviewer) {
95     $options = array(
96         'showreviewer'  => true,
97         'showauthor'    => false,
98         'showform'      => true,
99         'showweight'    => false,
100     );
101     $assessment = $workshop->prepare_assessment($assessment, $mformassessment, $options);
102     $assessment->title = get_string('assessmentbyyourself', 'workshop');
103     if ($workshop->assessing_examples_allowed()) {
104         $assessment->add_action(
105             new moodle_url($workshop->exsubmission_url($example->id), array('assess' => 'on', 'sesskey' => sesskey())),
106             get_string('reassess', 'workshop')
107         );
108     }
109     echo $output->render($assessment);
111 } elseif ($canmanage) {
112     $options = array(
113         'showreviewer'  => true,
114         'showauthor'    => false,
115         'showform'      => true,
116         'showweight'    => false,
117     );
118     $assessment = $workshop->prepare_assessment($assessment, $mformassessment, $options);
119     echo $output->render($assessment);
122 echo $output->footer();