Refactored the Workshop API class
[moodle.git] / mod / workshop / view.php
CommitLineData
4eab2e7f 1<?php
53fad4b9
DM
2
3// This file is part of Moodle - http://moodle.org/
4//
4eab2e7f
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//
4eab2e7f
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
4eab2e7f
DM
18/**
19 * Prints a particular instance of workshop
20 *
21 * You can have a rather longer description of the file as well,
22 * if you like, and it can span multiple lines.
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
4eab2e7f 29require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
ffac17df 30require_once(dirname(__FILE__).'/locallib.php');
4eab2e7f 31
a39d7d87
DM
32$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
33$w = optional_param('w', 0, PARAM_INT); // workshop instance ID
34$edit = optional_param('edit', null, PARAM_BOOL);
4eab2e7f
DM
35
36if ($id) {
66c9894d
DM
37 $cm = get_coursemodule_from_id('workshop', $id, 0, false, MUST_EXIST);
38 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
39 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
4eab2e7f 40} else {
66c9894d
DM
41 $workshop = $DB->get_record('workshop', array('id' => $w), '*', MUST_EXIST);
42 $course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
43 $cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
4eab2e7f
DM
44}
45
46require_login($course, true, $cm);
a39d7d87 47$workshop = new workshop($workshop, $cm, $course);
6e309973 48
66c9894d
DM
49// todo has_capability() check using something like
50// if (!(($workshop->is_open() && has_capability('mod/workshop:view')) || has_capability(...) || has_capability(...))) {
51// unable to view this page
52//
6e309973 53
b8ead2e6 54// todo logging add_to_log($course->id, "workshop", "view", "view.php?id=$cm->id", "$workshop->id");
4eab2e7f 55
a39d7d87
DM
56if (!is_null($edit) && $PAGE->user_allowed_editing()) {
57 $USER->editing = $edit;
58}
59
b8ead2e6 60$PAGE->set_url($workshop->view_url());
ffac17df 61$PAGE->set_title($workshop->name);
6e309973 62$PAGE->set_heading($course->fullname);
a39d7d87
DM
63$buttons = array();
64if ($PAGE->user_allowed_editing()) {
65 $editblocks = new html_form();
66 $editblocks->method = 'get';
67 $editblocks->button->text = get_string($PAGE->user_is_editing() ? 'blockseditoff' : 'blocksediton');
68 $editblocks->url = new moodle_url($PAGE->url, array('edit' => $PAGE->user_is_editing() ? 'off' : 'on'));
69 $buttons[] = $OUTPUT->button($editblocks);
70}
088e75ca 71$buttons[] = $OUTPUT->update_module_button($cm->id, 'workshop');
a39d7d87 72$PAGE->set_button(implode('', $buttons));
ffac17df 73
b8ead2e6 74/// Output starts here
66c9894d 75
39861053 76echo $OUTPUT->header();
4eab2e7f 77
ffac17df 78/// Print the main part of the page - todo these are just links to help during development
ffac17df 79echo $OUTPUT->box_start();
a39d7d87
DM
80echo $OUTPUT->heading('Workshop testing', 1);
81echo "<ol>\n";
ed597c77 82echo '<li><a href="' . $workshop->editform_url()->out() . '">Edit grading form (' . get_string('pluginname', 'workshopgrading_' . $workshop->strategy) . ')</a></li>' . "\n";
a39d7d87
DM
83echo "<li><a href=\"submission.php?cmid={$cm->id}\">View/edit your own submission</a></li>\n";
84echo "<li><a href=\"develtools.php?tool=mksubmissions&amp;cmid={$cm->id}\">Fake others' submissions</a></li>\n";
85echo "<li><a href=\"allocation.php?cmid={$cm->id}\">Allocate submissions</a></li>\n";
86
87$assessments = $workshop->get_assessments($USER->id);
88echo "<li>Assess submissions\n";
89echo "<ol>\n";
90foreach ($assessments as $assessment) {
91 echo "<li><a href=\"assessment.php?asid={$assessment->id}\">Assessment of '{$assessment->title}' by {$assessment->authorid}</a></li>" . "\n";
ffac17df 92}
a39d7d87
DM
93echo "</ol></li>" . "\n";
94echo "</ol>\n";
088e75ca 95echo "<p><a href=\"develtools.php?cmid={$cm->id}\">Workshop development tools</a></p>\n";
ffac17df 96echo $OUTPUT->box_end();
4eab2e7f 97
ffac17df 98echo $OUTPUT->footer();