Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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   * Assess an example submission
  20   *
  21   * @package    mod_workshop
  22   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require(__DIR__.'/../../config.php');
  27  require_once (__DIR__.'/locallib.php');
  28  
  29  $asid       = required_param('asid', PARAM_INT);  // assessment id
  30  $assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
  31  $example    = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST);
  32  $workshop   = $DB->get_record('workshop', array('id' => $example->workshopid), '*', MUST_EXIST);
  33  $course     = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
  34  $cm         = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
  35  
  36  require_login($course, false, $cm);
  37  if (isguestuser()) {
  38      print_error('guestsarenotallowed');
  39  }
  40  $workshop = new workshop($workshop, $cm, $course);
  41  
  42  $PAGE->set_url($workshop->exassess_url($assessment->id));
  43  $PAGE->set_title($workshop->name);
  44  $PAGE->set_heading($course->fullname);
  45  $PAGE->navbar->add(get_string('assessingexample', 'workshop'));
  46  $currenttab = 'assessment';
  47  
  48  $canmanage  = has_capability('mod/workshop:manageexamples', $workshop->context);
  49  $isreviewer = ($USER->id == $assessment->reviewerid);
  50  
  51  if ($isreviewer or $canmanage) {
  52      // such a user can continue
  53  } else {
  54      print_error('nopermissions', 'error', $workshop->view_url(), 'assess example submission');
  55  }
  56  
  57  // only the reviewer is allowed to modify the assessment
  58  if (($canmanage and $assessment->weight == 1) or ($isreviewer and $workshop->assessing_examples_allowed())) {
  59      $assessmenteditable = true;
  60  } else {
  61      $assessmenteditable = false;
  62  }
  63  
  64  // load the grading strategy logic
  65  $strategy = $workshop->grading_strategy_instance();
  66  
  67  // load the assessment form and process the submitted data eventually
  68  $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
  69  
  70  // Set data managed by the workshop core, subplugins set their own data themselves.
  71  $currentdata = (object)array(
  72      'feedbackauthor' => $assessment->feedbackauthor,
  73      'feedbackauthorformat' => $assessment->feedbackauthorformat,
  74  );
  75  if ($assessmenteditable and $workshop->overallfeedbackmode) {
  76      $currentdata = file_prepare_standard_editor($currentdata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
  77          $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
  78      if ($workshop->overallfeedbackfiles) {
  79          $currentdata = file_prepare_standard_filemanager($currentdata, 'feedbackauthorattachment',
  80              $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
  81              $assessment->id);
  82      }
  83  }
  84  $mform->set_data($currentdata);
  85  
  86  if ($mform->is_cancelled()) {
  87      redirect($workshop->view_url());
  88  } elseif ($assessmenteditable and ($data = $mform->get_data())) {
  89  
  90      // Let the grading strategy subplugin save its data.
  91      $rawgrade = $strategy->save_assessment($assessment, $data);
  92  
  93      // Store the data managed by the workshop core.
  94      $coredata = (object)array('id' => $assessment->id);
  95      if (isset($data->feedbackauthor_editor)) {
  96          $coredata->feedbackauthor_editor = $data->feedbackauthor_editor;
  97          $coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
  98              $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
  99          unset($coredata->feedbackauthor_editor);
 100      }
 101      if (isset($data->feedbackauthorattachment_filemanager)) {
 102          $coredata->feedbackauthorattachment_filemanager = $data->feedbackauthorattachment_filemanager;
 103          $coredata = file_postupdate_standard_filemanager($coredata, 'feedbackauthorattachment',
 104              $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
 105              $assessment->id);
 106          unset($coredata->feedbackauthorattachment_filemanager);
 107          if (empty($coredata->feedbackauthorattachment)) {
 108              $coredata->feedbackauthorattachment = 0;
 109          }
 110      }
 111      if ($canmanage) {
 112          // Remember the last one who edited the reference assessment.
 113          $coredata->reviewerid = $USER->id;
 114      }
 115      // Update the assessment data if there is something other than just the 'id'.
 116      if (count((array)$coredata) > 1 ) {
 117          $DB->update_record('workshop_assessments', $coredata);
 118      }
 119  
 120      if (!is_null($rawgrade) and isset($data->saveandclose)) {
 121          if ($canmanage) {
 122              redirect($workshop->view_url());
 123          } else {
 124              redirect($workshop->excompare_url($example->id, $assessment->id));
 125          }
 126      } else {
 127          // either it is not possible to calculate the $rawgrade
 128          // or the reviewer has chosen "Save and continue"
 129          redirect($PAGE->url);
 130      }
 131  }
 132  
 133  // output starts here
 134  $output = $PAGE->get_renderer('mod_workshop');      // workshop renderer
 135  echo $output->header();
 136  echo $output->heading(format_string($workshop->name));
 137  echo $output->heading(get_string('assessedexample', 'workshop'), 3);
 138  
 139  $example = $workshop->get_example_by_id($example->id);     // reload so can be passed to the renderer
 140  echo $output->render($workshop->prepare_example_submission(($example)));
 141  
 142  // show instructions for assessing as thay may contain important information
 143  // for evaluating the assessment
 144  if (trim($workshop->instructreviewers)) {
 145      $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
 146          'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context));
 147      print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'),
 148              'workshop-viewlet-instructreviewers-collapsed');
 149      echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
 150      print_collapsible_region_end();
 151  }
 152  
 153  // extend the current assessment record with user details
 154  $assessment = $workshop->get_assessment_by_id($assessment->id);
 155  
 156  if ($canmanage and $assessment->weight == 1) {
 157      $options = array(
 158          'showreviewer'  => false,
 159          'showauthor'    => false,
 160          'showform'      => true,
 161      );
 162      $assessment = $workshop->prepare_example_reference_assessment($assessment, $mform, $options);
 163      $assessment->title = get_string('assessmentreference', 'workshop');
 164      echo $output->render($assessment);
 165  
 166  } else if ($isreviewer) {
 167      $options = array(
 168          'showreviewer'  => true,
 169          'showauthor'    => false,
 170          'showform'      => true,
 171      );
 172      $assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
 173      $assessment->title = get_string('assessmentbyyourself', 'workshop');
 174      echo $output->render($assessment);
 175  
 176  } else if ($canmanage) {
 177      $options = array(
 178          'showreviewer'  => true,
 179          'showauthor'    => false,
 180          'showform'      => true,
 181          'showweight'    => false,
 182      );
 183      $assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
 184      echo $output->render($assessment);
 185  }
 186  
 187  echo $output->footer();