MDL-74741 javascript: A11y fix for dialogues visible from beginning
[moodle.git] / mod / workshop / view.php
blob7465481641f4b48049d42e8443f43167f1ea6fa5
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
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/>.
18 /**
19 * Prints a particular instance of workshop
21 * You can have a rather longer description of the file as well,
22 * if you like, and it can span multiple lines.
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
29 require(__DIR__.'/../../config.php');
30 require_once(__DIR__.'/locallib.php');
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);
35 $page = optional_param('page', 0, PARAM_INT);
36 $perpage = optional_param('perpage', null, PARAM_INT);
37 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
38 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
39 $eval = optional_param('eval', null, PARAM_PLUGIN);
41 if ($id) {
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 $workshoprecord = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
45 } else {
46 $workshoprecord = $DB->get_record('workshop', array('id' => $w), '*', MUST_EXIST);
47 $course = $DB->get_record('course', array('id' => $workshoprecord->course), '*', MUST_EXIST);
48 $cm = get_coursemodule_from_instance('workshop', $workshoprecord->id, $course->id, false, MUST_EXIST);
51 require_login($course, true, $cm);
52 require_capability('mod/workshop:view', $PAGE->context);
54 $workshop = new workshop($workshoprecord, $cm, $course);
56 $PAGE->set_url($workshop->view_url());
58 // Mark viewed.
59 $workshop->set_module_viewed();
61 // If the phase is to be switched, do it asap. This just has to happen after triggering
62 // the event so that the scheduled allocator had a chance to allocate submissions.
63 if ($workshop->phase == workshop::PHASE_SUBMISSION and $workshop->phaseswitchassessment
64 and $workshop->submissionend > 0 and $workshop->submissionend < time()) {
65 $workshop->switch_phase(workshop::PHASE_ASSESSMENT);
66 // Disable the automatic switching now so that it is not executed again by accident
67 // if the teacher changes the phase back to the submission one.
68 $DB->set_field('workshop', 'phaseswitchassessment', 0, array('id' => $workshop->id));
69 $workshop->phaseswitchassessment = 0;
72 if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
73 $USER->editing = $editmode;
76 $userplan = new workshop_user_plan($workshop, $USER->id);
78 foreach ($userplan->phases as $phase) {
79 if ($phase->active) {
80 $currentphasetitle = $phase->title;
84 $PAGE->set_title($workshop->name . " (" . $currentphasetitle . ")");
85 $PAGE->set_heading($course->fullname);
87 if ($perpage and $perpage > 0 and $perpage <= 1000) {
88 require_sesskey();
89 set_user_preference('workshop_perpage', $perpage);
90 redirect($PAGE->url);
93 if ($eval) {
94 require_sesskey();
95 require_capability('mod/workshop:overridegrades', $workshop->context);
96 $workshop->set_grading_evaluation_method($eval);
97 redirect($PAGE->url);
100 $output = $PAGE->get_renderer('mod_workshop');
102 /// Output starts here
104 echo $output->header();
105 echo $output->heading_with_help(format_string($workshop->name), 'userplan', 'workshop');
107 // Display any activity information (eg completion requirements / dates).
108 $cminfo = cm_info::create($cm);
109 $completiondetails = \core_completion\cm_completion_details::get_instance($cminfo, $USER->id);
110 $activitydates = \core\activity_dates::get_dates_for_module($cminfo, $USER->id);
111 echo $output->activity_information($cminfo, $completiondetails, $activitydates);
113 echo $output->heading(format_string($currentphasetitle), 3, null, 'mod_workshop-userplanheading');
114 echo $output->render($userplan);
116 switch ($workshop->phase) {
117 case workshop::PHASE_SETUP:
118 if (trim($workshop->intro)) {
119 print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'),
120 'workshop-viewlet-intro-collapsed');
121 echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox');
122 print_collapsible_region_end();
124 if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) {
125 print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'),
126 'workshop-viewlet-allexamples-collapsed');
127 echo $output->box_start('generalbox examples');
128 if ($workshop->grading_strategy_instance()->form_ready()) {
129 if (! $examples = $workshop->get_examples_for_manager()) {
130 echo $output->container(get_string('noexamples', 'workshop'), 'noexamples');
132 foreach ($examples as $example) {
133 $summary = $workshop->prepare_example_summary($example);
134 $summary->editable = true;
135 echo $output->render($summary);
137 $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
138 echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
139 } else {
140 echo $output->container(get_string('noexamplesformready', 'workshop'));
142 echo $output->box_end();
143 print_collapsible_region_end();
145 break;
146 case workshop::PHASE_SUBMISSION:
147 if (trim($workshop->instructauthors)) {
148 $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
149 'mod_workshop', 'instructauthors', null, workshop::instruction_editors_options($PAGE->context));
150 print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'),
151 'workshop-viewlet-instructauthors-collapsed');
152 echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
153 print_collapsible_region_end();
156 // does the user have to assess examples before submitting their own work?
157 $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION);
159 // is the assessment of example submissions considered finished?
160 $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
161 if ($workshop->assessing_examples_allowed()
162 and has_capability('mod/workshop:submit', $workshop->context)
163 and ! has_capability('mod/workshop:manageexamples', $workshop->context)) {
164 $examples = $userplan->get_examples();
165 $total = count($examples);
166 $left = 0;
167 // make sure the current user has all examples allocated
168 foreach ($examples as $exampleid => $example) {
169 if (is_null($example->assessmentid)) {
170 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
172 if (is_null($example->grade)) {
173 $left++;
176 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
177 $examplesdone = false;
178 } else {
179 $examplesdone = true;
181 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'),
182 'workshop-viewlet-examples-collapsed', $examplesdone);
183 echo $output->box_start('generalbox exampleassessments');
184 if ($total == 0) {
185 echo $output->heading(get_string('noexamples', 'workshop'), 3);
186 } else {
187 foreach ($examples as $example) {
188 $summary = $workshop->prepare_example_summary($example);
189 echo $output->render($summary);
192 echo $output->box_end();
193 print_collapsible_region_end();
196 if (has_capability('mod/workshop:submit', $PAGE->context) and (!$examplesmust or $examplesdone)) {
197 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'),
198 'workshop-viewlet-ownsubmission-collapsed');
199 echo $output->box_start('generalbox ownsubmission');
200 if ($submission = $workshop->get_submission_by_author($USER->id)) {
201 echo $output->render($workshop->prepare_submission_summary($submission, true));
202 if ($workshop->modifying_submission_allowed($USER->id)) {
203 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
204 $btntxt = get_string('editsubmission', 'workshop');
206 } else {
207 echo $output->container(get_string('noyoursubmission', 'workshop'));
208 if ($workshop->creating_submission_allowed($USER->id)) {
209 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
210 $btntxt = get_string('createsubmission', 'workshop');
213 if (!empty($btnurl)) {
214 echo $output->single_button($btnurl, $btntxt, 'get');
216 echo $output->box_end();
217 print_collapsible_region_end();
220 if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
221 $groupmode = groups_get_activity_groupmode($workshop->cm);
222 $groupid = groups_get_activity_group($workshop->cm, true);
224 if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $workshop->context)) {
225 $allowedgroups = groups_get_activity_allowed_groups($workshop->cm);
226 if (empty($allowedgroups)) {
227 echo $output->container(get_string('groupnoallowed', 'mod_workshop'), 'groupwidget error');
228 break;
230 if (! in_array($groupid, array_keys($allowedgroups))) {
231 echo $output->container(get_string('groupnotamember', 'core_group'), 'groupwidget error');
232 break;
236 print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('submissionsreport', 'workshop'),
237 'workshop-viewlet-allsubmissions-collapsed');
239 $perpage = get_user_preferences('workshop_perpage', 10);
240 $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
241 if ($data) {
242 $countparticipants = $workshop->count_participants();
243 $countsubmissions = $workshop->count_submissions(array_keys($data->grades), $groupid);
244 $a = new stdClass();
245 $a->submitted = $countsubmissions;
246 $a->notsubmitted = $data->totalcount - $countsubmissions;
248 echo html_writer::tag('div', get_string('submittednotsubmitted', 'workshop', $a));
250 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
252 // Prepare the paging bar.
253 $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
254 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
256 // Populate the display options for the submissions report.
257 $reportopts = new stdclass();
258 $reportopts->showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
259 $reportopts->showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
260 $reportopts->sortby = $sortby;
261 $reportopts->sorthow = $sorthow;
262 $reportopts->showsubmissiongrade = false;
263 $reportopts->showgradinggrade = false;
264 $reportopts->workshopphase = $workshop->phase;
266 echo $output->render($pagingbar);
267 echo $output->render(new workshop_grading_report($data, $reportopts));
268 echo $output->render($pagingbar);
269 echo $output->perpage_selector($perpage);
270 } else {
271 echo html_writer::tag('div', get_string('nothingfound', 'workshop'), array('class' => 'nothingfound'));
273 print_collapsible_region_end();
275 break;
277 case workshop::PHASE_ASSESSMENT:
279 $ownsubmissionexists = null;
280 if (has_capability('mod/workshop:submit', $PAGE->context)) {
281 if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) {
282 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'),
283 'workshop-viewlet-ownsubmission-collapsed', true);
284 echo $output->box_start('generalbox ownsubmission');
285 echo $output->render($workshop->prepare_submission_summary($ownsubmission, true));
286 $ownsubmissionexists = true;
287 } else {
288 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'),
289 'workshop-viewlet-ownsubmission-collapsed');
290 echo $output->box_start('generalbox ownsubmission');
291 echo $output->container(get_string('noyoursubmission', 'workshop'));
292 $ownsubmissionexists = false;
293 if ($workshop->creating_submission_allowed($USER->id)) {
294 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
295 $btntxt = get_string('createsubmission', 'workshop');
298 if (!empty($btnurl)) {
299 echo $output->single_button($btnurl, $btntxt, 'get');
301 echo $output->box_end();
302 print_collapsible_region_end();
305 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
306 $perpage = get_user_preferences('workshop_perpage', 10);
307 $groupid = groups_get_activity_group($workshop->cm, true);
308 $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
309 if ($data) {
310 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
311 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
313 // prepare paging bar
314 $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
315 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
317 // grading report display options
318 $reportopts = new stdclass();
319 $reportopts->showauthornames = $showauthornames;
320 $reportopts->showreviewernames = $showreviewernames;
321 $reportopts->sortby = $sortby;
322 $reportopts->sorthow = $sorthow;
323 $reportopts->showsubmissiongrade = false;
324 $reportopts->showgradinggrade = false;
325 $reportopts->workshopphase = $workshop->phase;
327 print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'),
328 'workshop-viewlet-gradereport-collapsed');
329 echo $output->box_start('generalbox gradesreport');
330 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
331 echo $output->render($pagingbar);
332 echo $output->render(new workshop_grading_report($data, $reportopts));
333 echo $output->render($pagingbar);
334 echo $output->perpage_selector($perpage);
335 echo $output->box_end();
336 print_collapsible_region_end();
339 if (trim($workshop->instructreviewers)) {
340 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
341 'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context));
342 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'),
343 'workshop-viewlet-instructreviewers-collapsed');
344 echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
345 print_collapsible_region_end();
348 // does the user have to assess examples before assessing other's work?
349 $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT);
351 // is the assessment of example submissions considered finished?
352 $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
354 // can the examples be assessed?
355 $examplesavailable = true;
357 if (!$examplesdone and $examplesmust and ($ownsubmissionexists === false)) {
358 print_collapsible_region_start('', 'workshop-viewlet-examplesfail', get_string('exampleassessments', 'workshop'),
359 'workshop-viewlet-examplesfail-collapsed');
360 echo $output->box(get_string('exampleneedsubmission', 'workshop'));
361 print_collapsible_region_end();
362 $examplesavailable = false;
365 if ($workshop->assessing_examples_allowed()
366 and has_capability('mod/workshop:submit', $workshop->context)
367 and ! has_capability('mod/workshop:manageexamples', $workshop->context)
368 and $examplesavailable) {
369 $examples = $userplan->get_examples();
370 $total = count($examples);
371 $left = 0;
372 // make sure the current user has all examples allocated
373 foreach ($examples as $exampleid => $example) {
374 if (is_null($example->assessmentid)) {
375 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
377 if (is_null($example->grade)) {
378 $left++;
381 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
382 $examplesdone = false;
383 } else {
384 $examplesdone = true;
386 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'),
387 'workshop-viewlet-examples-collapsed', $examplesdone);
388 echo $output->box_start('generalbox exampleassessments');
389 if ($total == 0) {
390 echo $output->heading(get_string('noexamples', 'workshop'), 3);
391 } else {
392 foreach ($examples as $example) {
393 $summary = $workshop->prepare_example_summary($example);
394 echo $output->render($summary);
397 echo $output->box_end();
398 print_collapsible_region_end();
400 if (!$examplesmust or $examplesdone) {
401 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'),
402 'workshop-viewlet-assignedassessments-collapsed');
403 if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
404 echo $output->box_start('generalbox assessment-none');
405 echo $output->notification(get_string('assignedassessmentsnone', 'workshop'));
406 echo $output->box_end();
407 } else {
408 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
409 foreach ($assessments as $assessment) {
410 $submission = new stdClass();
411 $submission->id = $assessment->submissionid;
412 $submission->title = $assessment->submissiontitle;
413 $submission->timecreated = $assessment->submissioncreated;
414 $submission->timemodified = $assessment->submissionmodified;
415 $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
416 foreach ($userpicturefields as $userpicturefield) {
417 $prefixedusernamefield = 'author' . $userpicturefield;
418 $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
421 // transform the submission object into renderable component
422 $submission = $workshop->prepare_submission_summary($submission, $shownames);
424 if (is_null($assessment->grade)) {
425 $submission->status = 'notgraded';
426 $class = ' notgraded';
427 $buttontext = get_string('assess', 'workshop');
428 } else {
429 $submission->status = 'graded';
430 $class = ' graded';
431 $buttontext = get_string('reassess', 'workshop');
434 echo $output->box_start('generalbox assessment-summary' . $class);
435 echo $output->render($submission);
436 $aurl = $workshop->assess_url($assessment->id);
437 echo $output->single_button($aurl, $buttontext, 'get');
438 echo $output->box_end();
441 print_collapsible_region_end();
443 break;
444 case workshop::PHASE_EVALUATION:
445 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
446 $perpage = get_user_preferences('workshop_perpage', 10);
447 $groupid = groups_get_activity_group($workshop->cm, true);
448 $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
449 if ($data) {
450 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
451 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
453 if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
454 // Print a drop-down selector to change the current evaluation method.
455 $selector = new single_select($PAGE->url, 'eval', workshop::available_evaluators_list(),
456 $workshop->evaluation, false, 'evaluationmethodchooser');
457 $selector->set_label(get_string('evaluationmethod', 'mod_workshop'));
458 $selector->set_help_icon('evaluationmethod', 'mod_workshop');
459 $selector->method = 'post';
460 echo $output->render($selector);
461 // load the grading evaluator
462 $evaluator = $workshop->grading_evaluation_instance();
463 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
464 compact('sortby', 'sorthow', 'page')));
465 $form->display();
468 // prepare paging bar
469 $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
470 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
472 // grading report display options
473 $reportopts = new stdclass();
474 $reportopts->showauthornames = $showauthornames;
475 $reportopts->showreviewernames = $showreviewernames;
476 $reportopts->sortby = $sortby;
477 $reportopts->sorthow = $sorthow;
478 $reportopts->showsubmissiongrade = true;
479 $reportopts->showgradinggrade = true;
480 $reportopts->workshopphase = $workshop->phase;
482 print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'),
483 'workshop-viewlet-gradereport-collapsed');
484 echo $output->box_start('generalbox gradesreport');
485 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
486 echo $output->render($pagingbar);
487 echo $output->render(new workshop_grading_report($data, $reportopts));
488 echo $output->render($pagingbar);
489 echo $output->perpage_selector($perpage);
490 echo $output->box_end();
491 print_collapsible_region_end();
494 if (has_capability('mod/workshop:overridegrades', $workshop->context)) {
495 print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop'),
496 'workshop-viewlet-cleargrades-collapsed', true);
497 echo $output->box_start('generalbox toolbox');
499 // Clear aggregated grades
500 $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades'));
501 $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post');
502 $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop'));
503 echo $output->container_start('toolboxaction');
504 echo $output->render($btn);
505 echo $output->help_icon('clearaggregatedgrades', 'workshop');
506 echo $output->container_end();
507 // Clear assessments
508 $url = new moodle_url($workshop->toolbox_url('clearassessments'));
509 $btn = new single_button($url, get_string('clearassessments', 'workshop'), 'post');
510 $btn->add_confirm_action(get_string('clearassessmentsconfirm', 'workshop'));
511 echo $output->container_start('toolboxaction');
512 echo $output->render($btn);
513 echo $output->help_icon('clearassessments', 'workshop');
515 echo $OUTPUT->pix_icon('i/risk_dataloss', get_string('riskdatalossshort', 'admin'));
516 echo $output->container_end();
518 echo $output->box_end();
519 print_collapsible_region_end();
521 if (has_capability('mod/workshop:submit', $PAGE->context)) {
522 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'),
523 'workshop-viewlet-ownsubmission-collapsed');
524 echo $output->box_start('generalbox ownsubmission');
525 if ($submission = $workshop->get_submission_by_author($USER->id)) {
526 echo $output->render($workshop->prepare_submission_summary($submission, true));
527 } else {
528 echo $output->container(get_string('noyoursubmission', 'workshop'));
530 echo $output->box_end();
531 print_collapsible_region_end();
533 if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
534 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'),
535 'workshop-viewlet-assignedassessments-collapsed');
536 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
537 foreach ($assessments as $assessment) {
538 $submission = new stdclass();
539 $submission->id = $assessment->submissionid;
540 $submission->title = $assessment->submissiontitle;
541 $submission->timecreated = $assessment->submissioncreated;
542 $submission->timemodified = $assessment->submissionmodified;
543 $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
544 foreach ($userpicturefields as $userpicturefield) {
545 $prefixedusernamefield = 'author' . $userpicturefield;
546 $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
549 if (is_null($assessment->grade)) {
550 $class = ' notgraded';
551 $submission->status = 'notgraded';
552 $buttontext = get_string('assess', 'workshop');
553 } else {
554 $class = ' graded';
555 $submission->status = 'graded';
556 $buttontext = get_string('reassess', 'workshop');
558 echo $output->box_start('generalbox assessment-summary' . $class);
559 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
560 echo $output->box_end();
562 print_collapsible_region_end();
564 break;
565 case workshop::PHASE_CLOSED:
566 if (trim($workshop->conclusion)) {
567 $conclusion = file_rewrite_pluginfile_urls($workshop->conclusion, 'pluginfile.php', $workshop->context->id,
568 'mod_workshop', 'conclusion', null, workshop::instruction_editors_options($workshop->context));
569 print_collapsible_region_start('', 'workshop-viewlet-conclusion', get_string('conclusion', 'workshop'),
570 'workshop-viewlet-conclusion-collapsed');
571 echo $output->box(format_text($conclusion, $workshop->conclusionformat, array('overflowdiv'=>true)), array('generalbox', 'conclusion'));
572 print_collapsible_region_end();
574 $finalgrades = $workshop->get_gradebook_grades($USER->id);
575 if (!empty($finalgrades)) {
576 print_collapsible_region_start('', 'workshop-viewlet-yourgrades', get_string('yourgrades', 'workshop'),
577 'workshop-viewlet-yourgrades-collapsed');
578 echo $output->box_start('generalbox grades-yourgrades');
579 echo $output->render($finalgrades);
580 echo $output->box_end();
581 print_collapsible_region_end();
583 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
584 $perpage = get_user_preferences('workshop_perpage', 10);
585 $groupid = groups_get_activity_group($workshop->cm, true);
586 $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
587 if ($data) {
588 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
589 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
591 // prepare paging bar
592 $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
593 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
595 // grading report display options
596 $reportopts = new stdclass();
597 $reportopts->showauthornames = $showauthornames;
598 $reportopts->showreviewernames = $showreviewernames;
599 $reportopts->sortby = $sortby;
600 $reportopts->sorthow = $sorthow;
601 $reportopts->showsubmissiongrade = true;
602 $reportopts->showgradinggrade = true;
603 $reportopts->workshopphase = $workshop->phase;
605 print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'),
606 'workshop-viewlet-gradereport-collapsed');
607 echo $output->box_start('generalbox gradesreport');
608 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
609 echo $output->render($pagingbar);
610 echo $output->render(new workshop_grading_report($data, $reportopts));
611 echo $output->render($pagingbar);
612 echo $output->perpage_selector($perpage);
613 echo $output->box_end();
614 print_collapsible_region_end();
617 if (has_capability('mod/workshop:submit', $PAGE->context)) {
618 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission',
619 get_string('yoursubmissionwithassessments', 'workshop'), 'workshop-viewlet-ownsubmission-collapsed');
620 echo $output->box_start('generalbox ownsubmission');
621 if ($submission = $workshop->get_submission_by_author($USER->id)) {
622 echo $output->render($workshop->prepare_submission_summary($submission, true));
623 } else {
624 echo $output->container(get_string('noyoursubmission', 'workshop'));
626 echo $output->box_end();
628 if (!empty($submission->gradeoverby) and strlen(trim($submission->feedbackauthor)) > 0) {
629 echo $output->render(new workshop_feedback_author($submission));
632 print_collapsible_region_end();
634 if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) {
635 $shownames = has_capability('mod/workshop:viewauthorpublished', $workshop->context);
636 if ($submissions = $workshop->get_published_submissions()) {
637 print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions', get_string('publishedsubmissions', 'workshop'),
638 'workshop-viewlet-publicsubmissions-collapsed');
639 foreach ($submissions as $submission) {
640 echo $output->box_start('generalbox submission-summary');
641 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
642 echo $output->box_end();
644 print_collapsible_region_end();
647 if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
648 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'),
649 'workshop-viewlet-assignedassessments-collapsed');
650 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
651 foreach ($assessments as $assessment) {
652 $submission = new stdclass();
653 $submission->id = $assessment->submissionid;
654 $submission->title = $assessment->submissiontitle;
655 $submission->timecreated = $assessment->submissioncreated;
656 $submission->timemodified = $assessment->submissionmodified;
657 $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
658 foreach ($userpicturefields as $userpicturefield) {
659 $prefixedusernamefield = 'author' . $userpicturefield;
660 $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
663 if (is_null($assessment->grade)) {
664 $class = ' notgraded';
665 $submission->status = 'notgraded';
666 $buttontext = get_string('assess', 'workshop');
667 } else {
668 $class = ' graded';
669 $submission->status = 'graded';
670 $buttontext = get_string('reassess', 'workshop');
672 echo $output->box_start('generalbox assessment-summary' . $class);
673 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
674 echo $output->box_end();
676 if (strlen(trim($assessment->feedbackreviewer)) > 0) {
677 echo $output->render(new workshop_feedback_reviewer($assessment));
680 print_collapsible_region_end();
682 break;
683 default:
685 $PAGE->requires->js_call_amd('mod_workshop/workshopview', 'init');
686 echo $output->footer();