MDL-27508 common pagination and sorting interface across all phases in view.php
[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
193 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
194
195 $submissions = $workshop->get_submissions('all', $groupid);
196
197 print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('allsubmissions', 'workshop', count($submissions)));
198
55fc1e59 199 echo $output->box_start('generalbox allsubmissions');
1c0c3ef5 200 if (empty($submissions)) {
55fc1e59 201 echo $output->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
ddb59c77 202 }
1c0c3ef5 203 $shownames = has_capability('mod/workshop:viewauthornames', $workshop->context);
3dc78e5b 204 foreach ($submissions as $submission) {
81b22887 205 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
e9b0f0ab 206 }
55fc1e59 207 echo $output->box_end();
ef96efe0 208 print_collapsible_region_end();
e9b0f0ab 209 }
cbf87967 210
e9b0f0ab 211 break;
cbf87967 212
b761e6d9 213case workshop::PHASE_ASSESSMENT:
2f289d36
DM
214
215 $ownsubmissionexists = null;
216 if (has_capability('mod/workshop:submit', $PAGE->context)) {
217 if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) {
218 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), false, true);
219 echo $output->box_start('generalbox ownsubmission');
81b22887 220 echo $output->render($workshop->prepare_submission_summary($ownsubmission, true));
2f289d36
DM
221 $ownsubmissionexists = true;
222 } else {
223 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
224 echo $output->box_start('generalbox ownsubmission');
225 echo $output->container(get_string('noyoursubmission', 'workshop'));
226 $ownsubmissionexists = false;
9ddff589 227 if ($workshop->creating_submission_allowed($USER->id)) {
2f289d36
DM
228 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
229 $btntxt = get_string('createsubmission', 'workshop');
230 }
231 }
232 if (!empty($btnurl)) {
233 echo $output->single_button($btnurl, $btntxt, 'get');
234 }
235 echo $output->box_end();
236 print_collapsible_region_end();
237 }
238
d183140d 239 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
d183140d
DM
240 $perpage = 10; // todo let the user modify this
241 $groups = ''; // todo let the user choose the group
a6855934 242 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
c2a35266 243 $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
d183140d
DM
244 if ($data) {
245 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
246 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
247
248 // prepare paging bar
929d7a83 249 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
d183140d
DM
250
251 // grading report display options
7a789aa8 252 $reportopts = new stdclass();
d183140d
DM
253 $reportopts->showauthornames = $showauthornames;
254 $reportopts->showreviewernames = $showreviewernames;
255 $reportopts->sortby = $sortby;
256 $reportopts->sorthow = $sorthow;
257 $reportopts->showsubmissiongrade = false;
258 $reportopts->showgradinggrade = false;
d183140d 259
55fc1e59 260 echo $output->render($pagingbar);
c2a35266 261 echo $output->render(new workshop_grading_report($data, $reportopts));
55fc1e59 262 echo $output->render($pagingbar);
d183140d
DM
263 }
264 }
bfbca63d 265 if (trim($workshop->instructreviewers)) {
15d12b54 266 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
64f93798 267 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 268 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
367a75fa 269 echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
ef96efe0 270 print_collapsible_region_end();
15d12b54 271 }
2f289d36
DM
272
273 // does the user have to assess examples before assessing other's work?
274 $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT);
275
276 // is the assessment of example submissions considered finished?
277 $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
278
279 // can the examples be assessed?
280 $examplesavailable = true;
281
282 if (!$examplesdone and $examplesmust and ($ownsubmissionexists === false)) {
283 print_collapsible_region_start('', 'workshop-viewlet-examplesfail', get_string('exampleassessments', 'workshop'));
284 echo $output->box(get_string('exampleneedsubmission', 'workshop'));
285 print_collapsible_region_end();
286 $examplesavailable = false;
287 }
288
cff28ef0
DM
289 if ($workshop->assessing_examples_allowed()
290 and has_capability('mod/workshop:submit', $workshop->context)
2f289d36
DM
291 and ! has_capability('mod/workshop:manageexamples', $workshop->context)
292 and $examplesavailable) {
cff28ef0
DM
293 $examples = $userplan->get_examples();
294 $total = count($examples);
295 $left = 0;
296 // make sure the current user has all examples allocated
297 foreach ($examples as $exampleid => $example) {
298 if (is_null($example->assessmentid)) {
299 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
ddb59c77 300 }
cff28ef0
DM
301 if (is_null($example->grade)) {
302 $left++;
303 }
304 }
305 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
306 $examplesdone = false;
307 } else {
308 $examplesdone = true;
309 }
310 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
311 echo $output->box_start('generalbox exampleassessments');
312 if ($total == 0) {
313 echo $output->heading(get_string('noexamples', 'workshop'), 3);
314 } else {
315 foreach ($examples as $example) {
316 $summary = $workshop->prepare_example_summary($example);
81b22887 317 echo $output->render($summary);
cff28ef0
DM
318 }
319 }
320 echo $output->box_end();
321 print_collapsible_region_end();
322 }
2f289d36 323 if (!$examplesmust or $examplesdone) {
cff28ef0
DM
324 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
325 if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
326 echo $output->box_start('generalbox assessment-none');
327 echo $output->heading(get_string('assignedassessmentsnone', 'workshop'), 3);
55fc1e59 328 echo $output->box_end();
cff28ef0
DM
329 } else {
330 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
331 foreach ($assessments as $assessment) {
81b22887 332 $submission = new stdClass();
cff28ef0
DM
333 $submission->id = $assessment->submissionid;
334 $submission->title = $assessment->submissiontitle;
335 $submission->timecreated = $assessment->submissioncreated;
336 $submission->timemodified = $assessment->submissionmodified;
337 $submission->authorid = $assessment->authorid;
338 $submission->authorfirstname = $assessment->authorfirstname;
339 $submission->authorlastname = $assessment->authorlastname;
340 $submission->authorpicture = $assessment->authorpicture;
341 $submission->authorimagealt = $assessment->authorimagealt;
3a11c09f 342 $submission->authoremail = $assessment->authoremail;
81b22887
DM
343
344 // transform the submission object into renderable component
345 $submission = $workshop->prepare_submission_summary($submission, $shownames);
346
cff28ef0 347 if (is_null($assessment->grade)) {
4d63c194 348 $submission->status = 'notgraded';
81b22887 349 $class = ' notgraded';
cff28ef0
DM
350 $buttontext = get_string('assess', 'workshop');
351 } else {
4d63c194 352 $submission->status = 'graded';
81b22887 353 $class = ' graded';
cff28ef0
DM
354 $buttontext = get_string('reassess', 'workshop');
355 }
4d63c194 356
cff28ef0 357 echo $output->box_start('generalbox assessment-summary' . $class);
81b22887 358 echo $output->render($submission);
cff28ef0
DM
359 $aurl = $workshop->assess_url($assessment->id);
360 echo $output->single_button($aurl, $buttontext, 'get');
361 echo $output->box_end();
362 }
ddb59c77 363 }
cff28ef0 364 print_collapsible_region_end();
ddb59c77 365 }
00aca3c1 366 break;
b761e6d9 367case workshop::PHASE_EVALUATION:
d183140d 368 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
1fed6ce3
DM
369 $perpage = 10; // todo let the user modify this
370 $groups = ''; // todo let the user choose the group
a6855934 371 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
c2a35266 372 $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
1fed6ce3 373 if ($data) {
f55650e6
DM
374 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
375 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
376
d183140d
DM
377 if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
378 // load the grading evaluator
379 $evaluator = $workshop->grading_evaluation_instance();
380 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
381 compact('sortby', 'sorthow', 'page')));
382 $form->display();
383 }
1fed6ce3
DM
384
385 // prepare paging bar
929d7a83 386 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
1fed6ce3 387
d183140d 388 // grading report display options
7a789aa8 389 $reportopts = new stdclass();
d183140d
DM
390 $reportopts->showauthornames = $showauthornames;
391 $reportopts->showreviewernames = $showreviewernames;
392 $reportopts->sortby = $sortby;
393 $reportopts->sorthow = $sorthow;
394 $reportopts->showsubmissiongrade = true;
395 $reportopts->showgradinggrade = true;
d183140d 396
55fc1e59 397 echo $output->render($pagingbar);
c2a35266 398 echo $output->render(new workshop_grading_report($data, $reportopts));
55fc1e59 399 echo $output->render($pagingbar);
e807e9a3 400 }
1fed6ce3 401 }
32c78bc3 402 if (has_capability('mod/workshop:overridegrades', $workshop->context)) {
e706b9c3 403 print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop'), false, true);
32c78bc3 404 echo $output->box_start('generalbox toolbox');
e706b9c3 405
32c78bc3 406 // Clear aggregated grades
e706b9c3 407 $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades'));
32c78bc3
DM
408 $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post');
409 $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop'));
e706b9c3 410 echo $output->container_start('toolboxaction');
32c78bc3
DM
411 echo $output->render($btn);
412 echo $output->help_icon('clearaggregatedgrades', 'workshop');
e706b9c3
DM
413 echo $output->container_end();
414 // Clear assessments
415 $url = new moodle_url($workshop->toolbox_url('clearassessments'));
416 $btn = new single_button($url, get_string('clearassessments', 'workshop'), 'post');
417 $btn->add_confirm_action(get_string('clearassessmentsconfirm', 'workshop'));
418 echo $output->container_start('toolboxaction');
419 echo $output->render($btn);
420 echo $output->help_icon('clearassessments', 'workshop');
421 echo html_writer::empty_tag('img', array('src' => $output->pix_url('i/risk_dataloss'),
422 'title' => get_string('riskdatalossshort', 'admin'),
423 'alt' => get_string('riskdatalossshort', 'admin')));
424 echo $output->container_end();
32c78bc3
DM
425
426 echo $output->box_end();
427 print_collapsible_region_end();
428 }
4d63c194
DM
429 if (has_capability('mod/workshop:submit', $PAGE->context)) {
430 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
431 echo $output->box_start('generalbox ownsubmission');
432 if ($submission = $workshop->get_submission_by_author($USER->id)) {
757bade1 433 echo $output->render($workshop->prepare_submission_summary($submission, true));
4d63c194
DM
434 } else {
435 echo $output->container(get_string('noyoursubmission', 'workshop'));
436 }
437 echo $output->box_end();
438 print_collapsible_region_end();
439 }
440 if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
441 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
442 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
443 foreach ($assessments as $assessment) {
444 $submission = new stdclass();
445 $submission->id = $assessment->submissionid;
446 $submission->title = $assessment->submissiontitle;
447 $submission->timecreated = $assessment->submissioncreated;
448 $submission->timemodified = $assessment->submissionmodified;
449 $submission->authorid = $assessment->authorid;
450 $submission->authorfirstname = $assessment->authorfirstname;
451 $submission->authorlastname = $assessment->authorlastname;
452 $submission->authorpicture = $assessment->authorpicture;
453 $submission->authorimagealt = $assessment->authorimagealt;
3a11c09f 454 $submission->authoremail = $assessment->authoremail;
4d63c194
DM
455
456 if (is_null($assessment->grade)) {
457 $class = ' notgraded';
458 $submission->status = 'notgraded';
459 $buttontext = get_string('assess', 'workshop');
460 } else {
461 $class = ' graded';
462 $submission->status = 'graded';
463 $buttontext = get_string('reassess', 'workshop');
464 }
465 echo $output->box_start('generalbox assessment-summary' . $class);
81b22887 466 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
4d63c194
DM
467 echo $output->box_end();
468 }
469 print_collapsible_region_end();
470 }
1fed6ce3
DM
471 break;
472case workshop::PHASE_CLOSED:
5a372494 473 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
5a372494
DM
474 $perpage = 10; // todo let the user modify this
475 $groups = ''; // todo let the user choose the group
476 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
c2a35266 477 $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
5a372494
DM
478 if ($data) {
479 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
480 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
481
482 // prepare paging bar
483 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
484
485 // grading report display options
486 $reportopts = new stdclass();
487 $reportopts->showauthornames = $showauthornames;
488 $reportopts->showreviewernames = $showreviewernames;
489 $reportopts->sortby = $sortby;
490 $reportopts->sorthow = $sorthow;
491 $reportopts->showsubmissiongrade = true;
492 $reportopts->showgradinggrade = true;
493
494 print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
495 echo $output->render($pagingbar);
c2a35266 496 echo $output->render(new workshop_grading_report($data, $reportopts));
5a372494
DM
497 echo $output->render($pagingbar);
498 print_collapsible_region_end();
499 }
500 }
0aed4a55
DM
501 if (has_capability('mod/workshop:submit', $PAGE->context)) {
502 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
503 echo $output->box_start('generalbox ownsubmission');
504 if ($submission = $workshop->get_submission_by_author($USER->id)) {
81b22887 505 echo $output->render($workshop->prepare_submission_summary($submission, true));
0aed4a55
DM
506 } else {
507 echo $output->container(get_string('noyoursubmission', 'workshop'));
508 }
509 echo $output->box_end();
0dfb4bad
DM
510
511 if (!empty($submission->gradeoverby) and strlen(trim($submission->feedbackauthor)) > 0) {
512 echo $output->render(new workshop_feedback_author($submission));
513 }
514
0aed4a55
DM
515 print_collapsible_region_end();
516 }
00bc77ee 517 if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) {
e13d02f5 518 $shownames = has_capability('mod/workshop:viewauthorpublished', $workshop->context);
00bc77ee
DM
519 if ($submissions = $workshop->get_published_submissions()) {
520 print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions', get_string('publishedsubmissions', 'workshop'));
521 foreach ($submissions as $submission) {
522 echo $output->box_start('generalbox submission-summary');
e13d02f5 523 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
00bc77ee
DM
524 echo $output->box_end();
525 }
526 print_collapsible_region_end();
527 }
528 }
d67c20b8
DM
529 if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
530 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
531 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
532 foreach ($assessments as $assessment) {
533 $submission = new stdclass();
534 $submission->id = $assessment->submissionid;
535 $submission->title = $assessment->submissiontitle;
536 $submission->timecreated = $assessment->submissioncreated;
537 $submission->timemodified = $assessment->submissionmodified;
538 $submission->authorid = $assessment->authorid;
539 $submission->authorfirstname = $assessment->authorfirstname;
540 $submission->authorlastname = $assessment->authorlastname;
541 $submission->authorpicture = $assessment->authorpicture;
542 $submission->authorimagealt = $assessment->authorimagealt;
543 $submission->authoremail = $assessment->authoremail;
544
545 if (is_null($assessment->grade)) {
546 $class = ' notgraded';
547 $submission->status = 'notgraded';
548 $buttontext = get_string('assess', 'workshop');
549 } else {
550 $class = ' graded';
551 $submission->status = 'graded';
552 $buttontext = get_string('reassess', 'workshop');
553 }
554 echo $output->box_start('generalbox assessment-summary' . $class);
555 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
556 echo $output->box_end();
f68648e9
DM
557
558 if (strlen(trim($assessment->feedbackreviewer)) > 0) {
559 echo $output->render(new workshop_feedback_reviewer($assessment));
560 }
d67c20b8
DM
561 }
562 print_collapsible_region_end();
563 }
29dc43e7 564 break;
b761e6d9
DM
565default:
566}
567
55fc1e59 568echo $output->footer();