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]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Display example submission followed by its reference assessment and the user's assessment to compare them
  19   *
  20   * @package    mod_workshop
  21   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require(__DIR__.'/../../config.php');
  26  require_once (__DIR__.'/locallib.php');
  27  
  28  $cmid   = required_param('cmid', PARAM_INT);    // course module id
  29  $sid    = required_param('sid', PARAM_INT);     // example submission id
  30  $aid    = required_param('aid', PARAM_INT);     // the user's assessment id
  31  
  32  $cm     = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
  33  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  34  
  35  require_login($course, false, $cm);
  36  if (isguestuser()) {
  37      throw new \moodle_exception('guestsarenotallowed');
  38  }
  39  
  40  $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
  41  $workshop = new workshop($workshop, $cm, $course);
  42  $strategy = $workshop->grading_strategy_instance();
  43  
  44  $PAGE->set_url($workshop->excompare_url($sid, $aid));
  45  
  46  $example    = $workshop->get_example_by_id($sid);
  47  $assessment = $workshop->get_assessment_by_id($aid);
  48  if ($assessment->submissionid != $example->id) {
  49      throw new \moodle_exception('invalidarguments');
  50  }
  51  $mformassessment = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, false);
  52  if ($refasid = $DB->get_field('workshop_assessments', 'id', array('submissionid' => $example->id, 'weight' => 1))) {
  53      $reference = $workshop->get_assessment_by_id($refasid);
  54      $mformreference = $strategy->get_assessment_form($PAGE->url, 'assessment', $reference, false);
  55  }
  56  
  57  $canmanage  = has_capability('mod/workshop:manageexamples', $workshop->context);
  58  $isreviewer = ($USER->id == $assessment->reviewerid);
  59  
  60  if ($canmanage) {
  61      // ok you can go
  62  } elseif ($isreviewer and $workshop->assessing_examples_allowed()) {
  63      // ok you can go
  64  } else {
  65      throw new \moodle_exception('nopermissions', 'error', $workshop->view_url(), 'compare example assessment');
  66  }
  67  
  68  $PAGE->set_title($workshop->name);
  69  $PAGE->set_heading($course->fullname);
  70  $PAGE->navbar->add(get_string('examplecomparing', 'workshop'));
  71  
  72  // Output starts here
  73  $output = $PAGE->get_renderer('mod_workshop');
  74  echo $output->header();
  75  // Output the back button.
  76  echo $output->single_button($workshop->view_url(), get_string('back'), 'get', ['class' => 'mb-3']);
  77  if (!$PAGE->has_secondary_navigation()) {
  78      echo $output->heading(format_string($workshop->name));
  79  }
  80  echo $output->heading(get_string('assessedexample', 'workshop'), 3);
  81  
  82  echo $output->render($workshop->prepare_example_submission($example));
  83  
  84  // if the reference assessment is available, display it
  85  if (!empty($mformreference)) {
  86      $options = array(
  87          'showreviewer'  => false,
  88          'showauthor'    => false,
  89          'showform'      => true,
  90      );
  91      $reference = $workshop->prepare_example_reference_assessment($reference, $mformreference, $options);
  92      $reference->title = get_string('assessmentreference', 'workshop');
  93      if ($canmanage) {
  94          $reference->url = $workshop->exassess_url($reference->id);
  95      }
  96      echo $output->render($reference);
  97  }
  98  
  99  if ($isreviewer) {
 100      $options = array(
 101          'showreviewer'  => true,
 102          'showauthor'    => false,
 103          'showform'      => true,
 104      );
 105      $assessment = $workshop->prepare_example_assessment($assessment, $mformassessment, $options);
 106      $assessment->title = get_string('assessmentbyyourself', 'workshop');
 107      if ($workshop->assessing_examples_allowed()) {
 108          $assessment->add_action(
 109              new moodle_url($workshop->exsubmission_url($example->id), array('assess' => 'on', 'sesskey' => sesskey())),
 110              get_string('reassess', 'workshop')
 111          );
 112      }
 113      echo $output->render($assessment);
 114  
 115  } elseif ($canmanage) {
 116      $options = array(
 117          'showreviewer'  => true,
 118          'showauthor'    => false,
 119          'showform'      => true,
 120      );
 121      $assessment = $workshop->prepare_example_assessment($assessment, $mformassessment, $options);
 122      echo $output->render($assessment);
 123  }
 124  
 125  echo $output->footer();