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