Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [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  echo $output->view_page($workshop, $userplan, $currentphasetitle, $page, $sortby, $sorthow);
 114  
 115  $PAGE->requires->js_call_amd('mod_workshop/workshopview', 'init');
 116  echo $output->footer();