MDL-22546 improved fatal error messages when something is wrong with dataroot or...
[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
f82567af
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$editmode = optional_param('editmode', 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);
b761e6d9 47require_capability('mod/workshop:view', $PAGE->context);
a3610b08 48add_to_log($course->id, 'workshop', 'view', 'view.php?id=' . $cm->id, $workshop->name, $cm->id);
6e309973 49
b761e6d9 50$workshop = new workshop($workshop, $cm, $course);
4eab2e7f 51
f82567af
DM
52if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
53 $USER->editing = $editmode;
a39d7d87
DM
54}
55
b8ead2e6 56$PAGE->set_url($workshop->view_url());
ffac17df 57$PAGE->set_title($workshop->name);
6e309973 58$PAGE->set_heading($course->fullname);
b761e6d9 59
55fc1e59 60$output = $PAGE->get_renderer('mod_workshop');
b761e6d9 61
b8ead2e6 62/// Output starts here
66c9894d 63
55fc1e59
DM
64echo $output->header();
65echo $output->heading_with_help(format_string($workshop->name), 'userplan', 'workshop');
66echo $output->render(new workshop_user_plan($workshop, $USER->id));
b761e6d9 67
b761e6d9
DM
68switch ($workshop->phase) {
69case workshop::PHASE_SETUP:
b761e6d9 70 if (trim(strip_tags($workshop->intro))) {
ef96efe0 71 print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'));
55fc1e59 72 echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox');
ef96efe0 73 print_collapsible_region_end();
b761e6d9 74 }
81eccf0a 75 if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) {
ef96efe0 76 print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'));
55fc1e59 77 echo $output->box_start('generalbox examples');
cbf87967
DM
78 if ($workshop->grading_strategy_instance()->form_ready()) {
79 if (! $examples = $workshop->get_examples_for_manager()) {
55fc1e59 80 echo $output->container(get_string('noexamples', 'workshop'), 'noexamples');
cbf87967
DM
81 }
82 foreach ($examples as $example) {
83 $summary = $workshop->prepare_example_summary($example);
55fc1e59 84 echo $output->example_summary($summary);
cbf87967 85 }
3ba60ee1 86 $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
55fc1e59 87 echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
cbf87967 88 } else {
55fc1e59 89 echo $output->container(get_string('noexamplesformready', 'workshop'));
81eccf0a 90 }
55fc1e59 91 echo $output->box_end();
4437929e 92 print_collapsible_region_end();
81eccf0a 93 }
b761e6d9
DM
94 break;
95case workshop::PHASE_SUBMISSION:
6516b9e9
DM
96 if (trim(strip_tags($workshop->instructauthors))) {
97 $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
98 'workshop_instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 99 print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
55fc1e59 100 echo $output->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions'));
ef96efe0
DM
101 print_collapsible_region_end();
102 }
ef96efe0 103
514d8c22 104 $examplesdone = !$workshop->useexamples;
cbf87967
DM
105 if ($workshop->assessing_examples_allowed()
106 and has_capability('mod/workshop:submit', $workshop->context)
107 and ! has_capability('mod/workshop:manageexamples', $workshop->context)) {
108 $examples = $workshop->get_examples_for_reviewer($USER->id);
109 $total = count($examples);
514d8c22 110 $left = 0;
cbf87967
DM
111 // make sure the current user has all examples allocated
112 foreach ($examples as $exampleid => $example) {
113 if (is_null($example->assessmentid)) {
67ae13d9 114 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
cbf87967
DM
115 }
116 if (is_null($example->grade)) {
514d8c22 117 $left++;
ef96efe0
DM
118 }
119 }
514d8c22 120 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
cbf87967 121 $examplesdone = false;
514d8c22
DM
122 } else {
123 $examplesdone = true;
ef96efe0 124 }
cbf87967 125 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'));
55fc1e59 126 echo $output->box_start('generalbox exampleassessments');
cbf87967 127 if ($total == 0) {
55fc1e59 128 echo $output->heading(get_string('noexamples', 'workshop'), 3);
cbf87967
DM
129 } else {
130 foreach ($examples as $example) {
131 $summary = $workshop->prepare_example_summary($example);
55fc1e59 132 echo $output->example_summary($summary);
cbf87967 133 }
ef96efe0 134 }
55fc1e59 135 echo $output->box_end();
cbf87967 136 print_collapsible_region_end();
6516b9e9 137 }
cbf87967
DM
138
139 if ($workshop->submitting_allowed()
140 and has_capability('mod/workshop:submit', $PAGE->context)
141 and $examplesdone) {
ef96efe0 142 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
55fc1e59 143 echo $output->box_start('generalbox ownsubmission');
e9b0f0ab 144 if ($submission = $workshop->get_submission_by_author($USER->id)) {
55fc1e59 145 echo $output->submission_summary($submission, true);
81eccf0a 146 } else {
55fc1e59 147 echo $output->container(get_string('noyoursubmission', 'workshop'));
81eccf0a
DM
148 }
149 if ($workshop->submitting_allowed()) {
3ba60ee1 150 $aurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
55fc1e59 151 echo $output->single_button($aurl, get_string('editsubmission', 'workshop'), 'get');
e9b0f0ab 152 }
55fc1e59 153 echo $output->box_end();
ef96efe0 154 print_collapsible_region_end();
e9b0f0ab 155 }
cbf87967 156
e9b0f0ab
DM
157 if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
158 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
ef96efe0 159 print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('allsubmissions', 'workshop'));
55fc1e59 160 echo $output->box_start('generalbox allsubmissions');
29dc43e7 161 if (! $submissions = $workshop->get_submissions('all')) {
55fc1e59 162 echo $output->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
ddb59c77 163 }
3dc78e5b 164 foreach ($submissions as $submission) {
55fc1e59 165 echo $output->submission_summary($submission, $shownames);
e9b0f0ab 166 }
55fc1e59 167 echo $output->box_end();
ef96efe0 168 print_collapsible_region_end();
e9b0f0ab 169 }
cbf87967 170
e9b0f0ab 171 break;
cbf87967 172
b761e6d9 173case workshop::PHASE_ASSESSMENT:
d183140d
DM
174 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
175 $page = optional_param('page', 0, PARAM_INT);
176 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
177 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
178 $perpage = 10; // todo let the user modify this
179 $groups = ''; // todo let the user choose the group
a6855934 180 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
d183140d
DM
181 $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
182 if ($data) {
183 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
184 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
185
186 // prepare paging bar
929d7a83 187 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
d183140d
DM
188
189 // grading report display options
7a789aa8 190 $reportopts = new stdclass();
d183140d
DM
191 $reportopts->showauthornames = $showauthornames;
192 $reportopts->showreviewernames = $showreviewernames;
193 $reportopts->sortby = $sortby;
194 $reportopts->sorthow = $sorthow;
195 $reportopts->showsubmissiongrade = false;
196 $reportopts->showgradinggrade = false;
d183140d 197
55fc1e59
DM
198 echo $output->render($pagingbar);
199 echo $output->grading_report($data, $reportopts);
200 echo $output->render($pagingbar);
d183140d
DM
201 }
202 }
15d12b54
DM
203 if (trim(strip_tags($workshop->instructreviewers))) {
204 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
205 'workshop_instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 206 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
55fc1e59 207 echo $output->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
ef96efe0 208 print_collapsible_region_end();
15d12b54 209 }
ef96efe0 210 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
ddb59c77 211 if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
55fc1e59
DM
212 echo $output->box_start('generalbox assessment-none');
213 echo $output->heading(get_string('assignedassessmentsnone', 'workshop'), 3);
214 echo $output->box_end();
ddb59c77 215 } else {
ddb59c77
DM
216 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
217 foreach ($assessments as $assessment) {
7a789aa8 218 $submission = new stdclass();
8d57ce64
DM
219 $submission->id = $assessment->submissionid;
220 $submission->title = $assessment->submissiontitle;
221 $submission->timecreated = $assessment->submissioncreated;
222 $submission->timemodified = $assessment->submissionmodified;
223 $submission->authorid = $assessment->authorid;
224 $submission->authorfirstname = $assessment->authorfirstname;
225 $submission->authorlastname = $assessment->authorlastname;
226 $submission->authorpicture = $assessment->authorpicture;
227 $submission->authorimagealt = $assessment->authorimagealt;
228
ddb59c77
DM
229 if (is_null($assessment->grade)) {
230 $class = ' notgraded';
8d57ce64 231 $status = get_string('nogradeyet', 'workshop');
ddb59c77
DM
232 $buttontext = get_string('assess', 'workshop');
233 } else {
234 $class = ' graded';
8d57ce64 235 $status = get_string('alreadygraded', 'workshop');
ddb59c77
DM
236 $buttontext = get_string('reassess', 'workshop');
237 }
55fc1e59
DM
238 echo $output->box_start('generalbox assessment-summary' . $class);
239 echo $output->submission_summary($submission, $shownames);
3ba60ee1 240 $aurl = $workshop->assess_url($assessment->id);
55fc1e59
DM
241 echo $output->single_button($aurl, $buttontext, 'get');
242 echo $output->box_end();
ddb59c77
DM
243 }
244 }
ef96efe0 245 print_collapsible_region_end();
00aca3c1 246 break;
b761e6d9 247case workshop::PHASE_EVALUATION:
d183140d 248 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
1fed6ce3
DM
249 $page = optional_param('page', 0, PARAM_INT);
250 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
251 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
252 $perpage = 10; // todo let the user modify this
253 $groups = ''; // todo let the user choose the group
a6855934 254 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
1fed6ce3
DM
255 $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
256 if ($data) {
f55650e6
DM
257 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
258 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
259
d183140d
DM
260 if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
261 // load the grading evaluator
262 $evaluator = $workshop->grading_evaluation_instance();
263 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
264 compact('sortby', 'sorthow', 'page')));
265 $form->display();
266 }
1fed6ce3
DM
267
268 // prepare paging bar
929d7a83 269 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
1fed6ce3 270
d183140d 271 // grading report display options
7a789aa8 272 $reportopts = new stdclass();
d183140d
DM
273 $reportopts->showauthornames = $showauthornames;
274 $reportopts->showreviewernames = $showreviewernames;
275 $reportopts->sortby = $sortby;
276 $reportopts->sorthow = $sorthow;
277 $reportopts->showsubmissiongrade = true;
278 $reportopts->showgradinggrade = true;
d183140d 279
55fc1e59
DM
280 echo $output->render($pagingbar);
281 echo $output->grading_report($data, $reportopts);
282 echo $output->render($pagingbar);
e807e9a3 283 }
1fed6ce3
DM
284 }
285 break;
286case workshop::PHASE_CLOSED:
29dc43e7 287 break;
b761e6d9
DM
288default:
289}
290
55fc1e59 291echo $output->footer();