Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   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/>.
  17  
  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   */
  28  
  29  require(__DIR__.'/../../config.php');
  30  require_once (__DIR__.'/locallib.php');
  31  
  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);
  40  
  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);
  49  }
  50  
  51  require_login($course, true, $cm);
  52  require_capability('mod/workshop:view', $PAGE->context);
  53  
  54  $workshop = new workshop($workshoprecord, $cm, $course);
  55  
  56  $PAGE->set_url($workshop->view_url());
  57  
  58  // Mark viewed.
  59  $workshop->set_module_viewed();
  60  
  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;
  70  }
  71  
  72  if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
  73      $USER->editing = $editmode;
  74  }
  75  $workshop->init_initial_bar();
  76  $userplan = new workshop_user_plan($workshop, $USER->id);
  77  
  78  foreach ($userplan->phases as $phase) {
  79      if ($phase->active) {
  80          $currentphasetitle = $phase->title;
  81      }
  82  }
  83  
  84  $PAGE->set_title($workshop->name . " (" . $currentphasetitle . ")");
  85  $PAGE->set_heading($course->fullname);
  86  
  87  if ($perpage and $perpage > 0 and $perpage <= 1000) {
  88      require_sesskey();
  89      set_user_preference('workshop_perpage', $perpage);
  90      redirect($PAGE->url);
  91  }
  92  
  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);
  98  }
  99  
 100  $heading = $OUTPUT->heading_with_help(format_string($workshop->name), 'userplan', 'workshop');
 101  $heading = preg_replace('/<h2[^>]*>([.\s\S]*)<\/h2>/', '$1', $heading);
 102  $PAGE->activityheader->set_attrs([
 103      'title' => $PAGE->activityheader->is_title_allowed() ? $heading : "",
 104      'description' => ''
 105  ]);
 106  
 107  $output = $PAGE->get_renderer('mod_workshop');
 108  
 109  /// Output starts here
 110  
 111  echo $output->header();
 112  
 113  // Output action buttons here.
 114  switch ($workshop->phase) {
 115      case workshop::PHASE_SUBMISSION:
 116          // Does the user have to assess examples before submitting their own work?
 117          $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION);
 118  
 119          // Is the assessment of example submissions considered finished?
 120          $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
 121  
 122          if ($workshop->assessing_examples_allowed() && has_capability('mod/workshop:submit', $workshop->context) &&
 123                  !has_capability('mod/workshop:manageexamples', $workshop->context)) {
 124              $examples = $userplan->get_examples();
 125              $left = 0;
 126              // Make sure the current user has all examples allocated.
 127              foreach ($examples as $exampleid => $example) {
 128                  if (is_null($example->grade)) {
 129                      $left++;
 130                      break;
 131                  }
 132              }
 133              if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
 134                  $examplesdone = false;
 135              } else {
 136                  $examplesdone = true;
 137              }
 138          }
 139  
 140          if (has_capability('mod/workshop:submit', $PAGE->context) and (!$examplesmust or $examplesdone)) {
 141              if (!$workshop->get_submission_by_author($USER->id)) {
 142                  $btnurl = new moodle_url($workshop->submission_url(), ['edit' => 'on']);
 143                  $btntxt = get_string('createsubmission', 'workshop');
 144                  echo $output->single_button($btnurl, $btntxt, 'get', ['primary' => true]);
 145              }
 146          }
 147          break;
 148  
 149      case workshop::PHASE_ASSESSMENT:
 150          if (has_capability('mod/workshop:submit', $PAGE->context)) {
 151              if (!$workshop->get_submission_by_author($USER->id)) {
 152                  if ($workshop->creating_submission_allowed($USER->id)) {
 153                      $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
 154                      $btntxt = get_string('createsubmission', 'workshop');
 155                      echo $output->single_button($btnurl, $btntxt, 'get', ['primary' => true]);
 156                  }
 157              }
 158          }
 159  }
 160  
 161  echo $output->heading(format_string($currentphasetitle), 3, null, 'mod_workshop-userplanheading');
 162  echo $output->render($userplan);
 163  
 164  switch ($workshop->phase) {
 165      case workshop::PHASE_SETUP:
 166          if (trim($workshop->intro)) {
 167              print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'),
 168                  'workshop-viewlet-intro-collapsed');
 169              echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox');
 170              print_collapsible_region_end();
 171          }
 172          if ($workshop->useexamples && has_capability('mod/workshop:manageexamples', $PAGE->context)) {
 173              print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'),
 174                  'workshop-viewlet-allexamples-collapsed');
 175              echo $output->box_start('generalbox examples');
 176              if ($workshop->grading_strategy_instance()->form_ready()) {
 177                  if (!$examples = $workshop->get_examples_for_manager()) {
 178                      echo $output->container(get_string('noexamples', 'workshop'), 'noexamples');
 179                  }
 180                  foreach ($examples as $example) {
 181                      $summary = $workshop->prepare_example_summary($example);
 182                      $summary->editable = true;
 183                      echo $output->render($summary);
 184                  }
 185                  $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
 186                  echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
 187              } else {
 188                  echo $output->container(get_string('noexamplesformready', 'workshop'));
 189              }
 190              echo $output->box_end();
 191              print_collapsible_region_end();
 192          }
 193          break;
 194      case workshop::PHASE_SUBMISSION:
 195          if (trim($workshop->instructauthors)) {
 196              $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
 197                  'mod_workshop', 'instructauthors', null, workshop::instruction_editors_options($PAGE->context));
 198              print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'),
 199                  'workshop-viewlet-instructauthors-collapsed');
 200              echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv' => true)),
 201                  array('generalbox', 'instructions'));
 202              print_collapsible_region_end();
 203          }
 204  
 205          if ($workshop->assessing_examples_allowed()
 206              && has_capability('mod/workshop:submit', $workshop->context)
 207              && !has_capability('mod/workshop:manageexamples', $workshop->context)) {
 208              $examples = $userplan->get_examples();
 209              $total = count($examples);
 210              print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'),
 211                  'workshop-viewlet-examples-collapsed', $examplesdone);
 212              echo $output->box_start('generalbox exampleassessments');
 213              if ($total == 0) {
 214                  echo $output->heading(get_string('noexamples', 'workshop'), 3);
 215              } else {
 216                  foreach ($examples as $example) {
 217                      $summary = $workshop->prepare_example_summary($example);
 218                      echo $output->render($summary);
 219                  }
 220              }
 221              echo $output->box_end();
 222              print_collapsible_region_end();
 223          }
 224  
 225          if (has_capability('mod/workshop:submit', $PAGE->context) && (!$examplesmust || $examplesdone)) {
 226              print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'),
 227                  'workshop-viewlet-ownsubmission-collapsed');
 228              echo $output->box_start('generalbox ownsubmission');
 229              if ($submission = $workshop->get_submission_by_author($USER->id)) {
 230                  echo $output->render($workshop->prepare_submission_summary($submission, true));
 231              } else {
 232                  echo $output->container(get_string('noyoursubmission', 'workshop'));
 233              }
 234  
 235              echo $output->box_end();
 236              print_collapsible_region_end();
 237          }
 238  
 239          if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
 240              $groupmode = groups_get_activity_groupmode($workshop->cm);
 241              $groupid = groups_get_activity_group($workshop->cm, true);
 242  
 243              if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $workshop->context)) {
 244                  $allowedgroups = groups_get_activity_allowed_groups($workshop->cm);
 245                  if (empty($allowedgroups)) {
 246                      echo $output->container(get_string('groupnoallowed', 'mod_workshop'), 'groupwidget error');
 247                      break;
 248                  }
 249                  if (!in_array($groupid, array_keys($allowedgroups))) {
 250                      echo $output->container(get_string('groupnotamember', 'core_group'), 'groupwidget error');
 251                      break;
 252                  }
 253              }
 254  
 255              print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('submissionsreport', 'workshop'),
 256                  'workshop-viewlet-allsubmissions-collapsed');
 257  
 258              $perpage = get_user_preferences('workshop_perpage', 10);
 259              $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
 260              if ($data) {
 261                  $countparticipants = $workshop->count_participants();
 262                  $countsubmissions = $workshop->count_submissions(array_keys($data->grades), $groupid);
 263                  $a = new stdClass();
 264                  $a->submitted = $countsubmissions;
 265                  $a->notsubmitted = $data->totalcount - $countsubmissions;
 266  
 267                  echo html_writer::tag('div', get_string('submittednotsubmitted', 'workshop', $a));
 268  
 269                  echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
 270  
 271                  // Prepare the paging bar.
 272                  $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
 273                  $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
 274  
 275                  // Populate the display options for the submissions report.
 276                  $reportopts = new stdclass();
 277                  $reportopts->showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
 278                  $reportopts->showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
 279                  $reportopts->sortby = $sortby;
 280                  $reportopts->sorthow = $sorthow;
 281                  $reportopts->showsubmissiongrade = false;
 282                  $reportopts->showgradinggrade = false;
 283                  $reportopts->workshopphase = $workshop->phase;
 284                  echo $output->initials_bars($workshop, $baseurl);
 285                  echo $output->render($pagingbar);
 286                  echo $output->render(new workshop_grading_report($data, $reportopts));
 287                  echo $output->render($pagingbar);
 288                  echo $output->perpage_selector($perpage);
 289              } else {
 290                  echo html_writer::tag('div', get_string('nothingfound', 'workshop'), array('class' => 'nothingfound'));
 291              }
 292              print_collapsible_region_end();
 293          }
 294          break;
 295  
 296      case workshop::PHASE_ASSESSMENT:
 297  
 298          $ownsubmissionexists = null;
 299          if (has_capability('mod/workshop:submit', $PAGE->context)) {
 300              if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) {
 301                  print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'),
 302                      'workshop-viewlet-ownsubmission-collapsed', true);
 303                  echo $output->box_start('generalbox ownsubmission');
 304                  echo $output->render($workshop->prepare_submission_summary($ownsubmission, true));
 305                  $ownsubmissionexists = true;
 306              } else {
 307                  print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'),
 308                      'workshop-viewlet-ownsubmission-collapsed');
 309                  echo $output->box_start('generalbox ownsubmission');
 310                  echo $output->container(get_string('noyoursubmission', 'workshop'));
 311                  $ownsubmissionexists = false;
 312              }
 313  
 314              echo $output->box_end();
 315              print_collapsible_region_end();
 316          }
 317  
 318          if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
 319              $perpage = get_user_preferences('workshop_perpage', 10);
 320              $groupid = groups_get_activity_group($workshop->cm, true);
 321              $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
 322              if ($data) {
 323                  $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
 324                  $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
 325  
 326                  // Prepare paging bar.
 327                  $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
 328                  $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
 329  
 330                  // Grading report display options.
 331                  $reportopts = new stdclass();
 332                  $reportopts->showauthornames = $showauthornames;
 333                  $reportopts->showreviewernames = $showreviewernames;
 334                  $reportopts->sortby = $sortby;
 335                  $reportopts->sorthow = $sorthow;
 336                  $reportopts->showsubmissiongrade = false;
 337                  $reportopts->showgradinggrade = false;
 338                  $reportopts->workshopphase = $workshop->phase;
 339  
 340                  print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'),
 341                      'workshop-viewlet-gradereport-collapsed');
 342                  echo $output->box_start('generalbox gradesreport');
 343                  echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
 344                  echo $output->initials_bars($workshop, $baseurl);
 345                  echo $output->render($pagingbar);
 346                  echo $output->render(new workshop_grading_report($data, $reportopts));
 347                  echo $output->render($pagingbar);
 348                  echo $output->perpage_selector($perpage);
 349                  echo $output->box_end();
 350                  print_collapsible_region_end();
 351              }
 352          }
 353          if (trim($workshop->instructreviewers)) {
 354              $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
 355                  'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context));
 356              print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'),
 357                  'workshop-viewlet-instructreviewers-collapsed');
 358              echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv' => true)),
 359                  array('generalbox', 'instructions'));
 360              print_collapsible_region_end();
 361          }
 362  
 363          // Does the user have to assess examples before assessing other's work?
 364          $examplesmust = ($workshop->useexamples && $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT);
 365  
 366          // Is the assessment of example submissions considered finished?
 367          $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
 368  
 369          // Can the examples be assessed?
 370          $examplesavailable = true;
 371  
 372          if (!$examplesdone && $examplesmust && ($ownsubmissionexists === false)) {
 373              print_collapsible_region_start('', 'workshop-viewlet-examplesfail', get_string('exampleassessments', 'workshop'),
 374                  'workshop-viewlet-examplesfail-collapsed');
 375              echo $output->box(get_string('exampleneedsubmission', 'workshop'));
 376              print_collapsible_region_end();
 377              $examplesavailable = false;
 378          }
 379  
 380          if ($workshop->assessing_examples_allowed()
 381              && has_capability('mod/workshop:submit', $workshop->context)
 382              && !has_capability('mod/workshop:manageexamples', $workshop->context)
 383              && $examplesavailable) {
 384              $examples = $userplan->get_examples();
 385              $total = count($examples);
 386              $left = 0;
 387              // Make sure the current user has all examples allocated.
 388              foreach ($examples as $exampleid => $example) {
 389                  if (is_null($example->assessmentid)) {
 390                      $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
 391                  }
 392                  if (is_null($example->grade)) {
 393                      $left++;
 394                  }
 395              }
 396              if ($left > 0 && $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
 397                  $examplesdone = false;
 398              } else {
 399                  $examplesdone = true;
 400              }
 401              print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'),
 402                  'workshop-viewlet-examples-collapsed', $examplesdone);
 403              echo $output->box_start('generalbox exampleassessments');
 404              if ($total == 0) {
 405                  echo $output->heading(get_string('noexamples', 'workshop'), 3);
 406              } else {
 407                  foreach ($examples as $example) {
 408                      $summary = $workshop->prepare_example_summary($example);
 409                      echo $output->render($summary);
 410                  }
 411              }
 412              echo $output->box_end();
 413              print_collapsible_region_end();
 414          }
 415          if (!$examplesmust || $examplesdone) {
 416              print_collapsible_region_start('', 'workshop-viewlet-assignedassessments',
 417                  get_string('assignedassessments', 'workshop'),
 418                  'workshop-viewlet-assignedassessments-collapsed');
 419              if (!$assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
 420                  echo $output->box_start('generalbox assessment-none');
 421                  echo $output->notification(get_string('assignedassessmentsnone', 'workshop'));
 422                  echo $output->box_end();
 423              } else {
 424                  $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
 425                  foreach ($assessments as $assessment) {
 426                      $submission = new stdClass();
 427                      $submission->id = $assessment->submissionid;
 428                      $submission->title = $assessment->submissiontitle;
 429                      $submission->timecreated = $assessment->submissioncreated;
 430                      $submission->timemodified = $assessment->submissionmodified;
 431                      $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
 432                      foreach ($userpicturefields as $userpicturefield) {
 433                          $prefixedusernamefield = 'author' . $userpicturefield;
 434                          $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
 435                      }
 436  
 437                      // Transform the submission object into renderable component.
 438                      $submission = $workshop->prepare_submission_summary($submission, $shownames);
 439  
 440                      if (is_null($assessment->grade)) {
 441                          $submission->status = 'notgraded';
 442                          $class = ' notgraded';
 443                          $buttontext = get_string('assess', 'workshop');
 444                      } else {
 445                          $submission->status = 'graded';
 446                          $class = ' graded';
 447                          $buttontext = get_string('reassess', 'workshop');
 448                      }
 449  
 450                      echo $output->box_start('generalbox assessment-summary' . $class);
 451                      echo $output->render($submission);
 452                      $aurl = $workshop->assess_url($assessment->id);
 453                      echo $output->single_button($aurl, $buttontext, 'get');
 454                      echo $output->box_end();
 455                  }
 456              }
 457              print_collapsible_region_end();
 458          }
 459          break;
 460      case workshop::PHASE_EVALUATION:
 461          if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
 462              $perpage = get_user_preferences('workshop_perpage', 10);
 463              $groupid = groups_get_activity_group($workshop->cm, true);
 464              $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
 465              if ($data) {
 466                  $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
 467                  $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
 468  
 469                  if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
 470                      // Print a drop-down selector to change the current evaluation method.
 471                      $selector = new single_select($PAGE->url, 'eval', workshop::available_evaluators_list(),
 472                          $workshop->evaluation, false, 'evaluationmethodchooser');
 473                      $selector->set_label(get_string('evaluationmethod', 'mod_workshop'));
 474                      $selector->set_help_icon('evaluationmethod', 'mod_workshop');
 475                      $selector->method = 'post';
 476                      echo $output->render($selector);
 477                      // Load the grading evaluator.
 478                      $evaluator = $workshop->grading_evaluation_instance();
 479                      $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
 480                          compact('sortby', 'sorthow', 'page')));
 481                      $form->display();
 482                  }
 483  
 484                  // Prepare paging bar.
 485                  $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
 486                  $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
 487  
 488                  // Grading report display options.
 489                  $reportopts = new stdclass();
 490                  $reportopts->showauthornames = $showauthornames;
 491                  $reportopts->showreviewernames = $showreviewernames;
 492                  $reportopts->sortby = $sortby;
 493                  $reportopts->sorthow = $sorthow;
 494                  $reportopts->showsubmissiongrade = true;
 495                  $reportopts->showgradinggrade = true;
 496                  $reportopts->workshopphase = $workshop->phase;
 497  
 498                  print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'),
 499                      'workshop-viewlet-gradereport-collapsed');
 500                  echo $output->box_start('generalbox gradesreport');
 501                  echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
 502                  echo $output->initials_bars($workshop, $baseurl);
 503                  echo $output->render($pagingbar);
 504                  echo $output->render(new workshop_grading_report($data, $reportopts));
 505                  echo $output->render($pagingbar);
 506                  echo $output->perpage_selector($perpage);
 507                  echo $output->box_end();
 508                  print_collapsible_region_end();
 509              }
 510          }
 511          if (has_capability('mod/workshop:overridegrades', $workshop->context)) {
 512              print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop'),
 513                  'workshop-viewlet-cleargrades-collapsed', true);
 514              echo $output->box_start('generalbox toolbox');
 515  
 516              // Clear aggregated grades.
 517              $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades'));
 518              $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post');
 519              $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop'));
 520              echo $output->container_start('toolboxaction');
 521              echo $output->render($btn);
 522              echo $output->help_icon('clearaggregatedgrades', 'workshop');
 523              echo $output->container_end();
 524              // Clear assessments.
 525              $url = new moodle_url($workshop->toolbox_url('clearassessments'));
 526              $btn = new single_button($url, get_string('clearassessments', 'workshop'), 'post');
 527              $btn->add_confirm_action(get_string('clearassessmentsconfirm', 'workshop'));
 528              echo $output->container_start('toolboxaction');
 529              echo $output->render($btn);
 530              echo $output->help_icon('clearassessments', 'workshop');
 531  
 532              echo $OUTPUT->pix_icon('i/risk_dataloss', get_string('riskdatalossshort', 'admin'));
 533              echo $output->container_end();
 534  
 535              echo $output->box_end();
 536              print_collapsible_region_end();
 537          }
 538          if (has_capability('mod/workshop:submit', $PAGE->context)) {
 539              print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'),
 540                  'workshop-viewlet-ownsubmission-collapsed');
 541              echo $output->box_start('generalbox ownsubmission');
 542              if ($submission = $workshop->get_submission_by_author($USER->id)) {
 543                  echo $output->render($workshop->prepare_submission_summary($submission, true));
 544              } else {
 545                  echo $output->container(get_string('noyoursubmission', 'workshop'));
 546              }
 547              echo $output->box_end();
 548              print_collapsible_region_end();
 549          }
 550          if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
 551              print_collapsible_region_start('', 'workshop-viewlet-assignedassessments',
 552                  get_string('assignedassessments', 'workshop'),
 553                  'workshop-viewlet-assignedassessments-collapsed');
 554              $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
 555              foreach ($assessments as $assessment) {
 556                  $submission = new stdclass();
 557                  $submission->id = $assessment->submissionid;
 558                  $submission->title = $assessment->submissiontitle;
 559                  $submission->timecreated = $assessment->submissioncreated;
 560                  $submission->timemodified = $assessment->submissionmodified;
 561                  $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
 562                  foreach ($userpicturefields as $userpicturefield) {
 563                      $prefixedusernamefield = 'author' . $userpicturefield;
 564                      $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
 565                  }
 566  
 567                  if (is_null($assessment->grade)) {
 568                      $class = ' notgraded';
 569                      $submission->status = 'notgraded';
 570                      $buttontext = get_string('assess', 'workshop');
 571                  } else {
 572                      $class = ' graded';
 573                      $submission->status = 'graded';
 574                      $buttontext = get_string('reassess', 'workshop');
 575                  }
 576                  echo $output->box_start('generalbox assessment-summary' . $class);
 577                  echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
 578                  echo $output->box_end();
 579              }
 580              print_collapsible_region_end();
 581          }
 582          break;
 583      case workshop::PHASE_CLOSED:
 584          if (trim($workshop->conclusion)) {
 585              $conclusion = file_rewrite_pluginfile_urls($workshop->conclusion, 'pluginfile.php', $workshop->context->id,
 586                  'mod_workshop', 'conclusion', null, workshop::instruction_editors_options($workshop->context));
 587              print_collapsible_region_start('', 'workshop-viewlet-conclusion', get_string('conclusion', 'workshop'),
 588                  'workshop-viewlet-conclusion-collapsed');
 589              echo $output->box(format_text($conclusion, $workshop->conclusionformat, array('overflowdiv' => true)),
 590                  array('generalbox', 'conclusion'));
 591              print_collapsible_region_end();
 592          }
 593          $finalgrades = $workshop->get_gradebook_grades($USER->id);
 594          if (!empty($finalgrades)) {
 595              print_collapsible_region_start('', 'workshop-viewlet-yourgrades', get_string('yourgrades', 'workshop'),
 596                  'workshop-viewlet-yourgrades-collapsed');
 597              echo $output->box_start('generalbox grades-yourgrades');
 598              echo $output->render($finalgrades);
 599              echo $output->box_end();
 600              print_collapsible_region_end();
 601          }
 602          if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
 603              $perpage = get_user_preferences('workshop_perpage', 10);
 604              $groupid = groups_get_activity_group($workshop->cm, true);
 605              $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
 606              if ($data) {
 607                  $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
 608                  $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
 609  
 610                  // Prepare paging bar.
 611                  $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
 612                  $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
 613  
 614                  // Grading report display options.
 615                  $reportopts = new stdclass();
 616                  $reportopts->showauthornames = $showauthornames;
 617                  $reportopts->showreviewernames = $showreviewernames;
 618                  $reportopts->sortby = $sortby;
 619                  $reportopts->sorthow = $sorthow;
 620                  $reportopts->showsubmissiongrade = true;
 621                  $reportopts->showgradinggrade = true;
 622                  $reportopts->workshopphase = $workshop->phase;
 623  
 624                  print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'),
 625                      'workshop-viewlet-gradereport-collapsed');
 626                  echo $output->box_start('generalbox gradesreport');
 627                  echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
 628                  echo $output->initials_bars($workshop, $baseurl);
 629                  echo $output->render($pagingbar);
 630                  echo $output->render(new workshop_grading_report($data, $reportopts));
 631                  echo $output->render($pagingbar);
 632                  echo $output->perpage_selector($perpage);
 633                  echo $output->box_end();
 634                  print_collapsible_region_end();
 635              }
 636          }
 637          if (has_capability('mod/workshop:submit', $PAGE->context)) {
 638              print_collapsible_region_start('', 'workshop-viewlet-ownsubmission',
 639                  get_string('yoursubmissionwithassessments', 'workshop'), 'workshop-viewlet-ownsubmission-collapsed');
 640              echo $output->box_start('generalbox ownsubmission');
 641              if ($submission = $workshop->get_submission_by_author($USER->id)) {
 642                  echo $output->render($workshop->prepare_submission_summary($submission, true));
 643              } else {
 644                  echo $output->container(get_string('noyoursubmission', 'workshop'));
 645              }
 646              echo $output->box_end();
 647  
 648              if (!empty($submission->gradeoverby) && strlen(trim($submission->feedbackauthor)) > 0) {
 649                  echo $output->render(new workshop_feedback_author($submission));
 650              }
 651  
 652              print_collapsible_region_end();
 653          }
 654          if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) {
 655              $shownames = has_capability('mod/workshop:viewauthorpublished', $workshop->context);
 656              if ($submissions = $workshop->get_published_submissions()) {
 657                  print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions',
 658                      get_string('publishedsubmissions', 'workshop'),
 659                      'workshop-viewlet-publicsubmissions-collapsed');
 660                  foreach ($submissions as $submission) {
 661                      echo $output->box_start('generalbox submission-summary');
 662                      echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
 663                      echo $output->box_end();
 664                  }
 665                  print_collapsible_region_end();
 666              }
 667          }
 668          if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
 669              print_collapsible_region_start('', 'workshop-viewlet-assignedassessments',
 670                  get_string('assignedassessments', 'workshop'),
 671                  'workshop-viewlet-assignedassessments-collapsed');
 672              $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
 673              foreach ($assessments as $assessment) {
 674                  $submission = new stdclass();
 675                  $submission->id = $assessment->submissionid;
 676                  $submission->title = $assessment->submissiontitle;
 677                  $submission->timecreated = $assessment->submissioncreated;
 678                  $submission->timemodified = $assessment->submissionmodified;
 679                  $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
 680                  foreach ($userpicturefields as $userpicturefield) {
 681                      $prefixedusernamefield = 'author' . $userpicturefield;
 682                      $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
 683                  }
 684  
 685                  if (is_null($assessment->grade)) {
 686                      $class = ' notgraded';
 687                      $submission->status = 'notgraded';
 688                      $buttontext = get_string('assess', 'workshop');
 689                  } else {
 690                      $class = ' graded';
 691                      $submission->status = 'graded';
 692                      $buttontext = get_string('reassess', 'workshop');
 693                  }
 694                  echo $output->box_start('generalbox assessment-summary' . $class);
 695                  echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
 696                  echo $output->box_end();
 697  
 698                  if (!empty($assessment->feedbackreviewer) && strlen(trim($assessment->feedbackreviewer)) > 0) {
 699                      echo $output->render(new workshop_feedback_reviewer($assessment));
 700                  }
 701              }
 702              print_collapsible_region_end();
 703          }
 704          break;
 705      default:
 706  }
 707  $PAGE->requires->js_call_amd('mod_workshop/workshopview', 'init');
 708  echo $output->footer();