Fixed workshop view logging
[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 *
65601f04
DM
24 * @package mod
25 * @subpackage workshop
26 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4eab2e7f
DM
28 */
29
4eab2e7f 30require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
ffac17df 31require_once(dirname(__FILE__).'/locallib.php');
4eab2e7f 32
f82567af
DM
33$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
34$w = optional_param('w', 0, PARAM_INT); // workshop instance ID
35$editmode = optional_param('editmode', null, PARAM_BOOL);
4eab2e7f
DM
36
37if ($id) {
66c9894d
DM
38 $cm = get_coursemodule_from_id('workshop', $id, 0, false, MUST_EXIST);
39 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
40 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
4eab2e7f 41} else {
66c9894d
DM
42 $workshop = $DB->get_record('workshop', array('id' => $w), '*', MUST_EXIST);
43 $course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
44 $cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
4eab2e7f
DM
45}
46
47require_login($course, true, $cm);
b761e6d9 48require_capability('mod/workshop:view', $PAGE->context);
6e309973 49
b761e6d9 50$workshop = new workshop($workshop, $cm, $course);
e7ff48d2 51$workshop->log('view');
4eab2e7f 52
f82567af
DM
53if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
54 $USER->editing = $editmode;
a39d7d87
DM
55}
56
b8ead2e6 57$PAGE->set_url($workshop->view_url());
ffac17df 58$PAGE->set_title($workshop->name);
6e309973 59$PAGE->set_heading($course->fullname);
b761e6d9 60
55fc1e59 61$output = $PAGE->get_renderer('mod_workshop');
cff28ef0 62$userplan = new workshop_user_plan($workshop, $USER->id);
b761e6d9 63
b8ead2e6 64/// Output starts here
66c9894d 65
55fc1e59
DM
66echo $output->header();
67echo $output->heading_with_help(format_string($workshop->name), 'userplan', 'workshop');
cff28ef0 68echo $output->render($userplan);
b761e6d9 69
b761e6d9
DM
70switch ($workshop->phase) {
71case workshop::PHASE_SETUP:
bfbca63d 72 if (trim($workshop->intro)) {
ef96efe0 73 print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'));
55fc1e59 74 echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox');
ef96efe0 75 print_collapsible_region_end();
b761e6d9 76 }
81eccf0a 77 if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) {
ef96efe0 78 print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'));
55fc1e59 79 echo $output->box_start('generalbox examples');
cbf87967
DM
80 if ($workshop->grading_strategy_instance()->form_ready()) {
81 if (! $examples = $workshop->get_examples_for_manager()) {
55fc1e59 82 echo $output->container(get_string('noexamples', 'workshop'), 'noexamples');
cbf87967
DM
83 }
84 foreach ($examples as $example) {
85 $summary = $workshop->prepare_example_summary($example);
81b22887
DM
86 $summary->editable = true;
87 echo $output->render($summary);
cbf87967 88 }
3ba60ee1 89 $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
55fc1e59 90 echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
cbf87967 91 } else {
55fc1e59 92 echo $output->container(get_string('noexamplesformready', 'workshop'));
81eccf0a 93 }
55fc1e59 94 echo $output->box_end();
4437929e 95 print_collapsible_region_end();
81eccf0a 96 }
b761e6d9
DM
97 break;
98case workshop::PHASE_SUBMISSION:
bfbca63d 99 if (trim($workshop->instructauthors)) {
6516b9e9 100 $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
64f93798 101 'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 102 print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
367a75fa 103 echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
ef96efe0
DM
104 print_collapsible_region_end();
105 }
ef96efe0 106
2f289d36
DM
107 // does the user have to assess examples before submitting their own work?
108 $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION);
109
110 // is the assessment of example submissions considered finished?
111 $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
cbf87967
DM
112 if ($workshop->assessing_examples_allowed()
113 and has_capability('mod/workshop:submit', $workshop->context)
114 and ! has_capability('mod/workshop:manageexamples', $workshop->context)) {
cff28ef0 115 $examples = $userplan->get_examples();
cbf87967 116 $total = count($examples);
514d8c22 117 $left = 0;
cbf87967
DM
118 // make sure the current user has all examples allocated
119 foreach ($examples as $exampleid => $example) {
120 if (is_null($example->assessmentid)) {
67ae13d9 121 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
cbf87967
DM
122 }
123 if (is_null($example->grade)) {
514d8c22 124 $left++;
ef96efe0
DM
125 }
126 }
514d8c22 127 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
cbf87967 128 $examplesdone = false;
514d8c22
DM
129 } else {
130 $examplesdone = true;
ef96efe0 131 }
cff28ef0 132 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
55fc1e59 133 echo $output->box_start('generalbox exampleassessments');
cbf87967 134 if ($total == 0) {
55fc1e59 135 echo $output->heading(get_string('noexamples', 'workshop'), 3);
cbf87967
DM
136 } else {
137 foreach ($examples as $example) {
138 $summary = $workshop->prepare_example_summary($example);
81b22887 139 echo $output->render($summary);
cbf87967 140 }
ef96efe0 141 }
55fc1e59 142 echo $output->box_end();
cbf87967 143 print_collapsible_region_end();
6516b9e9 144 }
cbf87967 145
2f289d36 146 if (has_capability('mod/workshop:submit', $PAGE->context) and (!$examplesmust or $examplesdone)) {
ef96efe0 147 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
55fc1e59 148 echo $output->box_start('generalbox ownsubmission');
e9b0f0ab 149 if ($submission = $workshop->get_submission_by_author($USER->id)) {
81b22887 150 echo $output->render($workshop->prepare_submission_summary($submission, true));
2f289d36
DM
151 if ($workshop->modifying_submission_allowed()) {
152 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
153 $btntxt = get_string('editsubmission', 'workshop');
154 }
81eccf0a 155 } else {
55fc1e59 156 echo $output->container(get_string('noyoursubmission', 'workshop'));
2f289d36
DM
157 if ($workshop->creating_submission_allowed()) {
158 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
159 $btntxt = get_string('createsubmission', 'workshop');
160 }
81eccf0a 161 }
2f289d36
DM
162 if (!empty($btnurl)) {
163 echo $output->single_button($btnurl, $btntxt, 'get');
e9b0f0ab 164 }
55fc1e59 165 echo $output->box_end();
ef96efe0 166 print_collapsible_region_end();
e9b0f0ab 167 }
cbf87967 168
e9b0f0ab
DM
169 if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
170 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
ef96efe0 171 print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('allsubmissions', 'workshop'));
55fc1e59 172 echo $output->box_start('generalbox allsubmissions');
29dc43e7 173 if (! $submissions = $workshop->get_submissions('all')) {
55fc1e59 174 echo $output->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
ddb59c77 175 }
3dc78e5b 176 foreach ($submissions as $submission) {
81b22887 177 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
e9b0f0ab 178 }
55fc1e59 179 echo $output->box_end();
ef96efe0 180 print_collapsible_region_end();
e9b0f0ab 181 }
cbf87967 182
e9b0f0ab 183 break;
cbf87967 184
b761e6d9 185case workshop::PHASE_ASSESSMENT:
2f289d36
DM
186
187 $ownsubmissionexists = null;
188 if (has_capability('mod/workshop:submit', $PAGE->context)) {
189 if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) {
190 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), false, true);
191 echo $output->box_start('generalbox ownsubmission');
81b22887 192 echo $output->render($workshop->prepare_submission_summary($ownsubmission, true));
2f289d36
DM
193 $ownsubmissionexists = true;
194 } else {
195 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
196 echo $output->box_start('generalbox ownsubmission');
197 echo $output->container(get_string('noyoursubmission', 'workshop'));
198 $ownsubmissionexists = false;
199 if ($workshop->creating_submission_allowed()) {
200 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
201 $btntxt = get_string('createsubmission', 'workshop');
202 }
203 }
204 if (!empty($btnurl)) {
205 echo $output->single_button($btnurl, $btntxt, 'get');
206 }
207 echo $output->box_end();
208 print_collapsible_region_end();
209 }
210
d183140d
DM
211 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
212 $page = optional_param('page', 0, PARAM_INT);
213 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
214 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
215 $perpage = 10; // todo let the user modify this
216 $groups = ''; // todo let the user choose the group
a6855934 217 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
c2a35266 218 $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
d183140d
DM
219 if ($data) {
220 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
221 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
222
223 // prepare paging bar
929d7a83 224 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
d183140d
DM
225
226 // grading report display options
7a789aa8 227 $reportopts = new stdclass();
d183140d
DM
228 $reportopts->showauthornames = $showauthornames;
229 $reportopts->showreviewernames = $showreviewernames;
230 $reportopts->sortby = $sortby;
231 $reportopts->sorthow = $sorthow;
232 $reportopts->showsubmissiongrade = false;
233 $reportopts->showgradinggrade = false;
d183140d 234
55fc1e59 235 echo $output->render($pagingbar);
c2a35266 236 echo $output->render(new workshop_grading_report($data, $reportopts));
55fc1e59 237 echo $output->render($pagingbar);
d183140d
DM
238 }
239 }
bfbca63d 240 if (trim($workshop->instructreviewers)) {
15d12b54 241 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
64f93798 242 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 243 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
367a75fa 244 echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
ef96efe0 245 print_collapsible_region_end();
15d12b54 246 }
2f289d36
DM
247
248 // does the user have to assess examples before assessing other's work?
249 $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT);
250
251 // is the assessment of example submissions considered finished?
252 $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
253
254 // can the examples be assessed?
255 $examplesavailable = true;
256
257 if (!$examplesdone and $examplesmust and ($ownsubmissionexists === false)) {
258 print_collapsible_region_start('', 'workshop-viewlet-examplesfail', get_string('exampleassessments', 'workshop'));
259 echo $output->box(get_string('exampleneedsubmission', 'workshop'));
260 print_collapsible_region_end();
261 $examplesavailable = false;
262 }
263
cff28ef0
DM
264 if ($workshop->assessing_examples_allowed()
265 and has_capability('mod/workshop:submit', $workshop->context)
2f289d36
DM
266 and ! has_capability('mod/workshop:manageexamples', $workshop->context)
267 and $examplesavailable) {
cff28ef0
DM
268 $examples = $userplan->get_examples();
269 $total = count($examples);
270 $left = 0;
271 // make sure the current user has all examples allocated
272 foreach ($examples as $exampleid => $example) {
273 if (is_null($example->assessmentid)) {
274 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
ddb59c77 275 }
cff28ef0
DM
276 if (is_null($example->grade)) {
277 $left++;
278 }
279 }
280 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
281 $examplesdone = false;
282 } else {
283 $examplesdone = true;
284 }
285 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
286 echo $output->box_start('generalbox exampleassessments');
287 if ($total == 0) {
288 echo $output->heading(get_string('noexamples', 'workshop'), 3);
289 } else {
290 foreach ($examples as $example) {
291 $summary = $workshop->prepare_example_summary($example);
81b22887 292 echo $output->render($summary);
cff28ef0
DM
293 }
294 }
295 echo $output->box_end();
296 print_collapsible_region_end();
297 }
2f289d36 298 if (!$examplesmust or $examplesdone) {
cff28ef0
DM
299 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
300 if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
301 echo $output->box_start('generalbox assessment-none');
302 echo $output->heading(get_string('assignedassessmentsnone', 'workshop'), 3);
55fc1e59 303 echo $output->box_end();
cff28ef0
DM
304 } else {
305 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
306 foreach ($assessments as $assessment) {
81b22887 307 $submission = new stdClass();
cff28ef0
DM
308 $submission->id = $assessment->submissionid;
309 $submission->title = $assessment->submissiontitle;
310 $submission->timecreated = $assessment->submissioncreated;
311 $submission->timemodified = $assessment->submissionmodified;
312 $submission->authorid = $assessment->authorid;
313 $submission->authorfirstname = $assessment->authorfirstname;
314 $submission->authorlastname = $assessment->authorlastname;
315 $submission->authorpicture = $assessment->authorpicture;
316 $submission->authorimagealt = $assessment->authorimagealt;
3a11c09f 317 $submission->authoremail = $assessment->authoremail;
81b22887
DM
318
319 // transform the submission object into renderable component
320 $submission = $workshop->prepare_submission_summary($submission, $shownames);
321
cff28ef0 322 if (is_null($assessment->grade)) {
4d63c194 323 $submission->status = 'notgraded';
81b22887 324 $class = ' notgraded';
cff28ef0
DM
325 $buttontext = get_string('assess', 'workshop');
326 } else {
4d63c194 327 $submission->status = 'graded';
81b22887 328 $class = ' graded';
cff28ef0
DM
329 $buttontext = get_string('reassess', 'workshop');
330 }
4d63c194 331
cff28ef0 332 echo $output->box_start('generalbox assessment-summary' . $class);
81b22887 333 echo $output->render($submission);
cff28ef0
DM
334 $aurl = $workshop->assess_url($assessment->id);
335 echo $output->single_button($aurl, $buttontext, 'get');
336 echo $output->box_end();
337 }
ddb59c77 338 }
cff28ef0 339 print_collapsible_region_end();
ddb59c77 340 }
00aca3c1 341 break;
b761e6d9 342case workshop::PHASE_EVALUATION:
d183140d 343 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
1fed6ce3
DM
344 $page = optional_param('page', 0, PARAM_INT);
345 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
346 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
347 $perpage = 10; // todo let the user modify this
348 $groups = ''; // todo let the user choose the group
a6855934 349 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
c2a35266 350 $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
1fed6ce3 351 if ($data) {
f55650e6
DM
352 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
353 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
354
d183140d
DM
355 if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
356 // load the grading evaluator
357 $evaluator = $workshop->grading_evaluation_instance();
358 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
359 compact('sortby', 'sorthow', 'page')));
360 $form->display();
361 }
1fed6ce3
DM
362
363 // prepare paging bar
929d7a83 364 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
1fed6ce3 365
d183140d 366 // grading report display options
7a789aa8 367 $reportopts = new stdclass();
d183140d
DM
368 $reportopts->showauthornames = $showauthornames;
369 $reportopts->showreviewernames = $showreviewernames;
370 $reportopts->sortby = $sortby;
371 $reportopts->sorthow = $sorthow;
372 $reportopts->showsubmissiongrade = true;
373 $reportopts->showgradinggrade = true;
d183140d 374
55fc1e59 375 echo $output->render($pagingbar);
c2a35266 376 echo $output->render(new workshop_grading_report($data, $reportopts));
55fc1e59 377 echo $output->render($pagingbar);
e807e9a3 378 }
1fed6ce3 379 }
32c78bc3 380 if (has_capability('mod/workshop:overridegrades', $workshop->context)) {
e706b9c3 381 print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop'), false, true);
32c78bc3 382 echo $output->box_start('generalbox toolbox');
e706b9c3 383
32c78bc3 384 // Clear aggregated grades
e706b9c3 385 $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades'));
32c78bc3
DM
386 $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post');
387 $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop'));
e706b9c3 388 echo $output->container_start('toolboxaction');
32c78bc3
DM
389 echo $output->render($btn);
390 echo $output->help_icon('clearaggregatedgrades', 'workshop');
e706b9c3
DM
391 echo $output->container_end();
392 // Clear assessments
393 $url = new moodle_url($workshop->toolbox_url('clearassessments'));
394 $btn = new single_button($url, get_string('clearassessments', 'workshop'), 'post');
395 $btn->add_confirm_action(get_string('clearassessmentsconfirm', 'workshop'));
396 echo $output->container_start('toolboxaction');
397 echo $output->render($btn);
398 echo $output->help_icon('clearassessments', 'workshop');
399 echo html_writer::empty_tag('img', array('src' => $output->pix_url('i/risk_dataloss'),
400 'title' => get_string('riskdatalossshort', 'admin'),
401 'alt' => get_string('riskdatalossshort', 'admin')));
402 echo $output->container_end();
32c78bc3
DM
403
404 echo $output->box_end();
405 print_collapsible_region_end();
406 }
4d63c194
DM
407 if (has_capability('mod/workshop:submit', $PAGE->context)) {
408 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
409 echo $output->box_start('generalbox ownsubmission');
410 if ($submission = $workshop->get_submission_by_author($USER->id)) {
81b22887 411 echo $output->render(new workshop_submission_summary($submission, true));
4d63c194
DM
412 } else {
413 echo $output->container(get_string('noyoursubmission', 'workshop'));
414 }
415 echo $output->box_end();
416 print_collapsible_region_end();
417 }
418 if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
419 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
420 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
421 foreach ($assessments as $assessment) {
422 $submission = new stdclass();
423 $submission->id = $assessment->submissionid;
424 $submission->title = $assessment->submissiontitle;
425 $submission->timecreated = $assessment->submissioncreated;
426 $submission->timemodified = $assessment->submissionmodified;
427 $submission->authorid = $assessment->authorid;
428 $submission->authorfirstname = $assessment->authorfirstname;
429 $submission->authorlastname = $assessment->authorlastname;
430 $submission->authorpicture = $assessment->authorpicture;
431 $submission->authorimagealt = $assessment->authorimagealt;
3a11c09f 432 $submission->authoremail = $assessment->authoremail;
4d63c194
DM
433
434 if (is_null($assessment->grade)) {
435 $class = ' notgraded';
436 $submission->status = 'notgraded';
437 $buttontext = get_string('assess', 'workshop');
438 } else {
439 $class = ' graded';
440 $submission->status = 'graded';
441 $buttontext = get_string('reassess', 'workshop');
442 }
443 echo $output->box_start('generalbox assessment-summary' . $class);
81b22887 444 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
4d63c194
DM
445 echo $output->box_end();
446 }
447 print_collapsible_region_end();
448 }
1fed6ce3
DM
449 break;
450case workshop::PHASE_CLOSED:
5a372494
DM
451 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
452 $page = optional_param('page', 0, PARAM_INT);
453 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
454 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
455 $perpage = 10; // todo let the user modify this
456 $groups = ''; // todo let the user choose the group
457 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
c2a35266 458 $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
5a372494
DM
459 if ($data) {
460 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
461 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
462
463 // prepare paging bar
464 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
465
466 // grading report display options
467 $reportopts = new stdclass();
468 $reportopts->showauthornames = $showauthornames;
469 $reportopts->showreviewernames = $showreviewernames;
470 $reportopts->sortby = $sortby;
471 $reportopts->sorthow = $sorthow;
472 $reportopts->showsubmissiongrade = true;
473 $reportopts->showgradinggrade = true;
474
475 print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
476 echo $output->render($pagingbar);
c2a35266 477 echo $output->render(new workshop_grading_report($data, $reportopts));
5a372494
DM
478 echo $output->render($pagingbar);
479 print_collapsible_region_end();
480 }
481 }
0aed4a55
DM
482 if (has_capability('mod/workshop:submit', $PAGE->context)) {
483 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
484 echo $output->box_start('generalbox ownsubmission');
485 if ($submission = $workshop->get_submission_by_author($USER->id)) {
81b22887 486 echo $output->render($workshop->prepare_submission_summary($submission, true));
0aed4a55
DM
487 } else {
488 echo $output->container(get_string('noyoursubmission', 'workshop'));
489 }
490 echo $output->box_end();
491 print_collapsible_region_end();
492 }
00bc77ee
DM
493 if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) {
494 if ($submissions = $workshop->get_published_submissions()) {
495 print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions', get_string('publishedsubmissions', 'workshop'));
496 foreach ($submissions as $submission) {
497 echo $output->box_start('generalbox submission-summary');
81b22887 498 echo $output->render($workshop->prepare_submission_summary($submission, true));
00bc77ee
DM
499 echo $output->box_end();
500 }
501 print_collapsible_region_end();
502 }
503 }
29dc43e7 504 break;
b761e6d9
DM
505default:
506}
507
3a7507d0
SM
508$completion = new completion_info($course);
509$completion->set_module_viewed($cm);
510
55fc1e59 511echo $output->footer();