b5e4211a6a43718b55787230349dbd6b0aa34d26
[moodle.git] / mod / workshop / view.php
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.
14 //
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
20  *
21  * You can have a rather longer description of the file as well,
22  * if you like, and it can span multiple lines.
23  *
24  * @package    mod_workshop
25  * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
26  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27  */
29 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
30 require_once(dirname(__FILE__).'/locallib.php');
31 require_once($CFG->libdir.'/completionlib.php');
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);
36 $page       = optional_param('page', 0, PARAM_INT);
37 $perpage    = optional_param('perpage', null, PARAM_INT);
38 $sortby     = optional_param('sortby', 'lastname', PARAM_ALPHA);
39 $sorthow    = optional_param('sorthow', 'ASC', PARAM_ALPHA);
40 $eval       = optional_param('eval', null, PARAM_PLUGIN);
42 if ($id) {
43     $cm             = get_coursemodule_from_id('workshop', $id, 0, false, MUST_EXIST);
44     $course         = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
45     $workshoprecord = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
46 } else {
47     $workshoprecord = $DB->get_record('workshop', array('id' => $w), '*', MUST_EXIST);
48     $course         = $DB->get_record('course', array('id' => $workshoprecord->course), '*', MUST_EXIST);
49     $cm             = get_coursemodule_from_instance('workshop', $workshoprecord->id, $course->id, false, MUST_EXIST);
50 }
52 require_login($course, true, $cm);
53 require_capability('mod/workshop:view', $PAGE->context);
55 $workshop = new workshop($workshoprecord, $cm, $course);
57 // Mark viewed
58 $completion = new completion_info($course);
59 $completion->set_module_viewed($cm);
61 $eventdata = array();
62 $eventdata['objectid']         = $workshop->id;
63 $eventdata['context']          = $workshop->context;
65 $PAGE->set_url($workshop->view_url());
66 $event = \mod_workshop\event\course_module_viewed::create($eventdata);
67 $event->add_record_snapshot('course', $course);
68 $event->add_record_snapshot('workshop', $workshoprecord);
69 $event->add_record_snapshot('course_modules', $cm);
70 $event->trigger();
72 // If the phase is to be switched, do it asap. This just has to happen after triggering
73 // the event so that the scheduled allocator had a chance to allocate submissions.
74 if ($workshop->phase == workshop::PHASE_SUBMISSION and $workshop->phaseswitchassessment
75         and $workshop->submissionend > 0 and $workshop->submissionend < time()) {
76     $workshop->switch_phase(workshop::PHASE_ASSESSMENT);
77     // Disable the automatic switching now so that it is not executed again by accident
78     // if the teacher changes the phase back to the submission one.
79     $DB->set_field('workshop', 'phaseswitchassessment', 0, array('id' => $workshop->id));
80     $workshop->phaseswitchassessment = 0;
81 }
83 if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
84     $USER->editing = $editmode;
85 }
87 $PAGE->set_title($workshop->name);
88 $PAGE->set_heading($course->fullname);
90 if ($perpage and $perpage > 0 and $perpage <= 1000) {
91     require_sesskey();
92     set_user_preference('workshop_perpage', $perpage);
93     redirect($PAGE->url);
94 }
96 if ($eval) {
97     require_sesskey();
98     require_capability('mod/workshop:overridegrades', $workshop->context);
99     $workshop->set_grading_evaluation_method($eval);
100     redirect($PAGE->url);
103 $output = $PAGE->get_renderer('mod_workshop');
104 $userplan = new workshop_user_plan($workshop, $USER->id);
106 /// Output starts here
108 echo $output->header();
109 echo $output->heading_with_help(format_string($workshop->name), 'userplan', 'workshop');
110 echo $output->render($userplan);
112 switch ($workshop->phase) {
113 case workshop::PHASE_SETUP:
114     if (trim($workshop->intro)) {
115         print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'));
116         echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox');
117         print_collapsible_region_end();
118     }
119     if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) {
120         print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'));
121         echo $output->box_start('generalbox examples');
122         if ($workshop->grading_strategy_instance()->form_ready()) {
123             if (! $examples = $workshop->get_examples_for_manager()) {
124                 echo $output->container(get_string('noexamples', 'workshop'), 'noexamples');
125             }
126             foreach ($examples as $example) {
127                 $summary = $workshop->prepare_example_summary($example);
128                 $summary->editable = true;
129                 echo $output->render($summary);
130             }
131             $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
132             echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
133         } else {
134             echo $output->container(get_string('noexamplesformready', 'workshop'));
135         }
136         echo $output->box_end();
137         print_collapsible_region_end();
138     }
139     break;
140 case workshop::PHASE_SUBMISSION:
141     if (trim($workshop->instructauthors)) {
142         $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
143             'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
144         print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
145         echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
146         print_collapsible_region_end();
147     }
149     // does the user have to assess examples before submitting their own work?
150     $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION);
152     // is the assessment of example submissions considered finished?
153     $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
154     if ($workshop->assessing_examples_allowed()
155             and has_capability('mod/workshop:submit', $workshop->context)
156                     and ! has_capability('mod/workshop:manageexamples', $workshop->context)) {
157         $examples = $userplan->get_examples();
158         $total = count($examples);
159         $left = 0;
160         // make sure the current user has all examples allocated
161         foreach ($examples as $exampleid => $example) {
162             if (is_null($example->assessmentid)) {
163                 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
164             }
165             if (is_null($example->grade)) {
166                 $left++;
167             }
168         }
169         if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
170             $examplesdone = false;
171         } else {
172             $examplesdone = true;
173         }
174         print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
175         echo $output->box_start('generalbox exampleassessments');
176         if ($total == 0) {
177             echo $output->heading(get_string('noexamples', 'workshop'), 3);
178         } else {
179             foreach ($examples as $example) {
180                 $summary = $workshop->prepare_example_summary($example);
181                 echo $output->render($summary);
182             }
183         }
184         echo $output->box_end();
185         print_collapsible_region_end();
186     }
188     if (has_capability('mod/workshop:submit', $PAGE->context) and (!$examplesmust or $examplesdone)) {
189         print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
190         echo $output->box_start('generalbox ownsubmission');
191         if ($submission = $workshop->get_submission_by_author($USER->id)) {
192             echo $output->render($workshop->prepare_submission_summary($submission, true));
193             if ($workshop->modifying_submission_allowed($USER->id)) {
194                 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
195                 $btntxt = get_string('editsubmission', 'workshop');
196             }
197         } else {
198             echo $output->container(get_string('noyoursubmission', 'workshop'));
199             if ($workshop->creating_submission_allowed($USER->id)) {
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     }
211     if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
212         $groupmode = groups_get_activity_groupmode($workshop->cm);
213         $groupid = groups_get_activity_group($workshop->cm, true);
215         if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $workshop->context)) {
216             $allowedgroups = groups_get_activity_allowed_groups($workshop->cm);
217             if (empty($allowedgroups)) {
218                 echo $output->container(get_string('groupnoallowed', 'mod_workshop'), 'groupwidget error');
219                 break;
220             }
221             if (! in_array($groupid, array_keys($allowedgroups))) {
222                 echo $output->container(get_string('groupnotamember', 'core_group'), 'groupwidget error');
223                 break;
224             }
225         }
227         print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('submissionsreport', 'workshop'));
229         $perpage = get_user_preferences('workshop_perpage', 10);
230         $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
231         if ($data) {
232             $countparticipants = $workshop->count_participants();
233             $countsubmissions = $workshop->count_submissions(array_keys($data->grades), $groupid);
234             $a = new stdClass();
235             $a->submitted = $countsubmissions;
236             $a->notsubmitted = $data->totalcount - $countsubmissions;
238             echo html_writer::tag('div', get_string('submittednotsubmitted', 'workshop', $a));
240             echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
242             // prepare paging bar
243             $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
244             $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
246             // submissions report display options
247             $reportopts                     = new stdclass();
248             $reportopts->showauthornames     = has_capability('mod/workshop:viewauthornames', $workshop->context);
249             $reportopts->showreviewernames   = has_capability('mod/workshop:viewreviewernames', $workshop->context);
250             $reportopts->sortby              = $sortby;
251             $reportopts->sorthow             = $sorthow;
252             $reportopts->showsubmissiongrade = false;
253             $reportopts->showgradinggrade    = false;
254             $reportopts->workshopphase       = $workshop->phase;
256             echo $output->render($pagingbar);
257             echo $output->render(new workshop_grading_report($data, $reportopts));
258             echo $output->render($pagingbar);
259             echo $output->perpage_selector($perpage);
260         } else {
261             echo html_writer::tag('div', get_string('nothingfound', 'workshop'), array('class' => 'nothingfound'));
262         }
263         print_collapsible_region_end();
264     }
265     break;
267 case workshop::PHASE_ASSESSMENT:
269     $ownsubmissionexists = null;
270     if (has_capability('mod/workshop:submit', $PAGE->context)) {
271         if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) {
272             print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), false, true);
273             echo $output->box_start('generalbox ownsubmission');
274             echo $output->render($workshop->prepare_submission_summary($ownsubmission, true));
275             $ownsubmissionexists = true;
276         } else {
277             print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
278             echo $output->box_start('generalbox ownsubmission');
279             echo $output->container(get_string('noyoursubmission', 'workshop'));
280             $ownsubmissionexists = false;
281             if ($workshop->creating_submission_allowed($USER->id)) {
282                 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
283                 $btntxt = get_string('createsubmission', 'workshop');
284             }
285         }
286         if (!empty($btnurl)) {
287             echo $output->single_button($btnurl, $btntxt, 'get');
288         }
289         echo $output->box_end();
290         print_collapsible_region_end();
291     }
293     if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
294         $perpage = get_user_preferences('workshop_perpage', 10);
295         $groupid = groups_get_activity_group($workshop->cm, true);
296         $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
297         if ($data) {
298             $showauthornames    = has_capability('mod/workshop:viewauthornames', $workshop->context);
299             $showreviewernames  = has_capability('mod/workshop:viewreviewernames', $workshop->context);
301             // prepare paging bar
302             $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
303             $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
305             // grading report display options
306             $reportopts                         = new stdclass();
307             $reportopts->showauthornames        = $showauthornames;
308             $reportopts->showreviewernames      = $showreviewernames;
309             $reportopts->sortby                 = $sortby;
310             $reportopts->sorthow                = $sorthow;
311             $reportopts->showsubmissiongrade    = false;
312             $reportopts->showgradinggrade       = false;
313             $reportopts->workshopphase          = $workshop->phase;
315             print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
316             echo $output->box_start('generalbox gradesreport');
317             echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
318             echo $output->render($pagingbar);
319             echo $output->render(new workshop_grading_report($data, $reportopts));
320             echo $output->render($pagingbar);
321             echo $output->perpage_selector($perpage);
322             echo $output->box_end();
323             print_collapsible_region_end();
324         }
325     }
326     if (trim($workshop->instructreviewers)) {
327         $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
328             'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
329         print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
330         echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
331         print_collapsible_region_end();
332     }
334     // does the user have to assess examples before assessing other's work?
335     $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT);
337     // is the assessment of example submissions considered finished?
338     $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
340     // can the examples be assessed?
341     $examplesavailable = true;
343     if (!$examplesdone and $examplesmust and ($ownsubmissionexists === false)) {
344         print_collapsible_region_start('', 'workshop-viewlet-examplesfail', get_string('exampleassessments', 'workshop'));
345         echo $output->box(get_string('exampleneedsubmission', 'workshop'));
346         print_collapsible_region_end();
347         $examplesavailable = false;
348     }
350     if ($workshop->assessing_examples_allowed()
351             and has_capability('mod/workshop:submit', $workshop->context)
352                 and ! has_capability('mod/workshop:manageexamples', $workshop->context)
353                     and $examplesavailable) {
354         $examples = $userplan->get_examples();
355         $total = count($examples);
356         $left = 0;
357         // make sure the current user has all examples allocated
358         foreach ($examples as $exampleid => $example) {
359             if (is_null($example->assessmentid)) {
360                 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
361             }
362             if (is_null($example->grade)) {
363                 $left++;
364             }
365         }
366         if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
367             $examplesdone = false;
368         } else {
369             $examplesdone = true;
370         }
371         print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
372         echo $output->box_start('generalbox exampleassessments');
373         if ($total == 0) {
374             echo $output->heading(get_string('noexamples', 'workshop'), 3);
375         } else {
376             foreach ($examples as $example) {
377                 $summary = $workshop->prepare_example_summary($example);
378                 echo $output->render($summary);
379             }
380         }
381         echo $output->box_end();
382         print_collapsible_region_end();
383     }
384     if (!$examplesmust or $examplesdone) {
385         print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
386         if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
387             echo $output->box_start('generalbox assessment-none');
388             echo $output->notification(get_string('assignedassessmentsnone', 'workshop'));
389             echo $output->box_end();
390         } else {
391             $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
392             foreach ($assessments as $assessment) {
393                 $submission                     = new stdClass();
394                 $submission->id                 = $assessment->submissionid;
395                 $submission->title              = $assessment->submissiontitle;
396                 $submission->timecreated        = $assessment->submissioncreated;
397                 $submission->timemodified       = $assessment->submissionmodified;
398                 $userpicturefields = explode(',', user_picture::fields());
399                 foreach ($userpicturefields as $userpicturefield) {
400                     $prefixedusernamefield = 'author' . $userpicturefield;
401                     $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
402                 }
404                 // transform the submission object into renderable component
405                 $submission = $workshop->prepare_submission_summary($submission, $shownames);
407                 if (is_null($assessment->grade)) {
408                     $submission->status = 'notgraded';
409                     $class = ' notgraded';
410                     $buttontext = get_string('assess', 'workshop');
411                 } else {
412                     $submission->status = 'graded';
413                     $class = ' graded';
414                     $buttontext = get_string('reassess', 'workshop');
415                 }
417                 echo $output->box_start('generalbox assessment-summary' . $class);
418                 echo $output->render($submission);
419                 $aurl = $workshop->assess_url($assessment->id);
420                 echo $output->single_button($aurl, $buttontext, 'get');
421                 echo $output->box_end();
422             }
423         }
424         print_collapsible_region_end();
425     }
426     break;
427 case workshop::PHASE_EVALUATION:
428     if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
429         $perpage = get_user_preferences('workshop_perpage', 10);
430         $groupid = groups_get_activity_group($workshop->cm, true);
431         $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
432         if ($data) {
433             $showauthornames    = has_capability('mod/workshop:viewauthornames', $workshop->context);
434             $showreviewernames  = has_capability('mod/workshop:viewreviewernames', $workshop->context);
436             if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
437                 // Print a drop-down selector to change the current evaluation method.
438                 $selector = new single_select($PAGE->url, 'eval', workshop::available_evaluators_list(),
439                     $workshop->evaluation, false, 'evaluationmethodchooser');
440                 $selector->set_label(get_string('evaluationmethod', 'mod_workshop'));
441                 $selector->set_help_icon('evaluationmethod', 'mod_workshop');
442                 $selector->method = 'post';
443                 echo $output->render($selector);
444                 // load the grading evaluator
445                 $evaluator = $workshop->grading_evaluation_instance();
446                 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
447                         compact('sortby', 'sorthow', 'page')));
448                 $form->display();
449             }
451             // prepare paging bar
452             $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
453             $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
455             // grading report display options
456             $reportopts                         = new stdclass();
457             $reportopts->showauthornames        = $showauthornames;
458             $reportopts->showreviewernames      = $showreviewernames;
459             $reportopts->sortby                 = $sortby;
460             $reportopts->sorthow                = $sorthow;
461             $reportopts->showsubmissiongrade    = true;
462             $reportopts->showgradinggrade       = true;
463             $reportopts->workshopphase          = $workshop->phase;
465             print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
466             echo $output->box_start('generalbox gradesreport');
467             echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
468             echo $output->render($pagingbar);
469             echo $output->render(new workshop_grading_report($data, $reportopts));
470             echo $output->render($pagingbar);
471             echo $output->perpage_selector($perpage);
472             echo $output->box_end();
473             print_collapsible_region_end();
474         }
475     }
476     if (has_capability('mod/workshop:overridegrades', $workshop->context)) {
477         print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop'), false, true);
478         echo $output->box_start('generalbox toolbox');
480         // Clear aggregated grades
481         $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades'));
482         $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post');
483         $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop'));
484         echo $output->container_start('toolboxaction');
485         echo $output->render($btn);
486         echo $output->help_icon('clearaggregatedgrades', 'workshop');
487         echo $output->container_end();
488         // Clear assessments
489         $url = new moodle_url($workshop->toolbox_url('clearassessments'));
490         $btn = new single_button($url, get_string('clearassessments', 'workshop'), 'post');
491         $btn->add_confirm_action(get_string('clearassessmentsconfirm', 'workshop'));
492         echo $output->container_start('toolboxaction');
493         echo $output->render($btn);
494         echo $output->help_icon('clearassessments', 'workshop');
495         echo html_writer::empty_tag('img', array('src' => $output->pix_url('i/risk_dataloss'),
496                                                  'title' => get_string('riskdatalossshort', 'admin'),
497                                                  'alt' => get_string('riskdatalossshort', 'admin'),
498                                                  'class' => 'workshop-risk-dataloss'));
499         echo $output->container_end();
501         echo $output->box_end();
502         print_collapsible_region_end();
503     }
504     if (has_capability('mod/workshop:submit', $PAGE->context)) {
505         print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
506         echo $output->box_start('generalbox ownsubmission');
507         if ($submission = $workshop->get_submission_by_author($USER->id)) {
508             echo $output->render($workshop->prepare_submission_summary($submission, true));
509         } else {
510             echo $output->container(get_string('noyoursubmission', 'workshop'));
511         }
512         echo $output->box_end();
513         print_collapsible_region_end();
514     }
515     if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
516         print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
517         $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
518         foreach ($assessments as $assessment) {
519             $submission                     = new stdclass();
520             $submission->id                 = $assessment->submissionid;
521             $submission->title              = $assessment->submissiontitle;
522             $submission->timecreated        = $assessment->submissioncreated;
523             $submission->timemodified       = $assessment->submissionmodified;
524             $userpicturefields = explode(',', user_picture::fields());
525             foreach ($userpicturefields as $userpicturefield) {
526                 $prefixedusernamefield = 'author' . $userpicturefield;
527                 $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
528             }
530             if (is_null($assessment->grade)) {
531                 $class = ' notgraded';
532                 $submission->status = 'notgraded';
533                 $buttontext = get_string('assess', 'workshop');
534             } else {
535                 $class = ' graded';
536                 $submission->status = 'graded';
537                 $buttontext = get_string('reassess', 'workshop');
538             }
539             echo $output->box_start('generalbox assessment-summary' . $class);
540             echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
541             echo $output->box_end();
542         }
543         print_collapsible_region_end();
544     }
545     break;
546 case workshop::PHASE_CLOSED:
547     if (trim($workshop->conclusion)) {
548         $conclusion = file_rewrite_pluginfile_urls($workshop->conclusion, 'pluginfile.php', $workshop->context->id,
549             'mod_workshop', 'conclusion', 0, workshop::instruction_editors_options($workshop->context));
550         print_collapsible_region_start('', 'workshop-viewlet-conclusion', get_string('conclusion', 'workshop'));
551         echo $output->box(format_text($conclusion, $workshop->conclusionformat, array('overflowdiv'=>true)), array('generalbox', 'conclusion'));
552         print_collapsible_region_end();
553     }
554     $finalgrades = $workshop->get_gradebook_grades($USER->id);
555     if (!empty($finalgrades)) {
556         print_collapsible_region_start('', 'workshop-viewlet-yourgrades', get_string('yourgrades', 'workshop'));
557         echo $output->box_start('generalbox grades-yourgrades');
558         echo $output->render($finalgrades);
559         echo $output->box_end();
560         print_collapsible_region_end();
561     }
562     if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
563         $perpage = get_user_preferences('workshop_perpage', 10);
564         $groupid = groups_get_activity_group($workshop->cm, true);
565         $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
566         if ($data) {
567             $showauthornames    = has_capability('mod/workshop:viewauthornames', $workshop->context);
568             $showreviewernames  = has_capability('mod/workshop:viewreviewernames', $workshop->context);
570             // prepare paging bar
571             $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
572             $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
574             // grading report display options
575             $reportopts                         = new stdclass();
576             $reportopts->showauthornames        = $showauthornames;
577             $reportopts->showreviewernames      = $showreviewernames;
578             $reportopts->sortby                 = $sortby;
579             $reportopts->sorthow                = $sorthow;
580             $reportopts->showsubmissiongrade    = true;
581             $reportopts->showgradinggrade       = true;
582             $reportopts->workshopphase          = $workshop->phase;
584             print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
585             echo $output->box_start('generalbox gradesreport');
586             echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
587             echo $output->render($pagingbar);
588             echo $output->render(new workshop_grading_report($data, $reportopts));
589             echo $output->render($pagingbar);
590             echo $output->perpage_selector($perpage);
591             echo $output->box_end();
592             print_collapsible_region_end();
593         }
594     }
595     if (has_capability('mod/workshop:submit', $PAGE->context)) {
596         print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
597         echo $output->box_start('generalbox ownsubmission');
598         if ($submission = $workshop->get_submission_by_author($USER->id)) {
599             echo $output->render($workshop->prepare_submission_summary($submission, true));
600         } else {
601             echo $output->container(get_string('noyoursubmission', 'workshop'));
602         }
603         echo $output->box_end();
605         if (!empty($submission->gradeoverby) and strlen(trim($submission->feedbackauthor)) > 0) {
606             echo $output->render(new workshop_feedback_author($submission));
607         }
609         print_collapsible_region_end();
610     }
611     if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) {
612         $shownames = has_capability('mod/workshop:viewauthorpublished', $workshop->context);
613         if ($submissions = $workshop->get_published_submissions()) {
614             print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions', get_string('publishedsubmissions', 'workshop'));
615             foreach ($submissions as $submission) {
616                 echo $output->box_start('generalbox submission-summary');
617                 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
618                 echo $output->box_end();
619             }
620             print_collapsible_region_end();
621         }
622     }
623     if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
624         print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
625         $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
626         foreach ($assessments as $assessment) {
627             $submission                     = new stdclass();
628             $submission->id                 = $assessment->submissionid;
629             $submission->title              = $assessment->submissiontitle;
630             $submission->timecreated        = $assessment->submissioncreated;
631             $submission->timemodified       = $assessment->submissionmodified;
632             $userpicturefields = explode(',', user_picture::fields());
633             foreach ($userpicturefields as $userpicturefield) {
634                 $prefixedusernamefield = 'author' . $userpicturefield;
635                 $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
636             }
638             if (is_null($assessment->grade)) {
639                 $class = ' notgraded';
640                 $submission->status = 'notgraded';
641                 $buttontext = get_string('assess', 'workshop');
642             } else {
643                 $class = ' graded';
644                 $submission->status = 'graded';
645                 $buttontext = get_string('reassess', 'workshop');
646             }
647             echo $output->box_start('generalbox assessment-summary' . $class);
648             echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
649             echo $output->box_end();
651             if (strlen(trim($assessment->feedbackreviewer)) > 0) {
652                 echo $output->render(new workshop_feedback_reviewer($assessment));
653             }
654         }
655         print_collapsible_region_end();
656     }
657     break;
658 default:
661 echo $output->footer();