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  // 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   * This page allows the teacher to enter a manual grade for a particular question.
  19   * This page is expected to only be used in a popup window.
  20   *
  21   * @package   mod_quiz
  22   * @copyright gustav delius 2006
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once('../../config.php');
  27  require_once ('locallib.php');
  28  
  29  $attemptid = required_param('attempt', PARAM_INT);
  30  $slot = required_param('slot', PARAM_INT); // The question number in the attempt.
  31  $cmid = optional_param('cmid', null, PARAM_INT);
  32  
  33  $PAGE->set_url('/mod/quiz/comment.php', ['attempt' => $attemptid, 'slot' => $slot]);
  34  
  35  $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
  36  $attemptobj->preload_all_attempt_step_users();
  37  $student = $DB->get_record('user', ['id' => $attemptobj->get_userid()]);
  38  
  39  // Can only grade finished attempts.
  40  if (!$attemptobj->is_finished()) {
  41      throw new \moodle_exception('attemptclosed', 'quiz');
  42  }
  43  
  44  // Check login and permissions.
  45  require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
  46  $attemptobj->require_capability('mod/quiz:grade');
  47  
  48  // Print the page header.
  49  $PAGE->set_pagelayout('popup');
  50  $PAGE->set_title(get_string('manualgradequestion', 'quiz', [
  51          'question' => format_string($attemptobj->get_question_name($slot)),
  52          'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student)]));
  53  $PAGE->set_heading($attemptobj->get_course()->fullname);
  54  $output = $PAGE->get_renderer('mod_quiz');
  55  echo $output->header();
  56  
  57  // Prepare summary information about this question attempt.
  58  $summarydata = [];
  59  
  60  // Student name.
  61  $userpicture = new user_picture($student);
  62  $userpicture->courseid = $attemptobj->get_courseid();
  63  $summarydata['user'] = [
  64      'title'   => $userpicture,
  65      'content' => new action_link(new moodle_url('/user/view.php', [
  66              'id' => $student->id, 'course' => $attemptobj->get_courseid()]),
  67              fullname($student, true)),
  68  ];
  69  
  70  // Quiz name.
  71  $summarydata['quizname'] = [
  72      'title'   => get_string('modulename', 'quiz'),
  73      'content' => format_string($attemptobj->get_quiz_name()),
  74  ];
  75  
  76  // Question name.
  77  $summarydata['questionname'] = [
  78      'title'   => get_string('question', 'quiz'),
  79      'content' => $attemptobj->get_question_name($slot),
  80  ];
  81  
  82  // Process any data that was submitted.
  83  if (data_submitted() && confirm_sesskey()) {
  84      if (optional_param('submit', false, PARAM_BOOL) && question_engine::is_manual_grade_in_range($attemptobj->get_uniqueid(), $slot)) {
  85          $transaction = $DB->start_delegated_transaction();
  86          $attemptobj->process_submitted_actions(time());
  87          $transaction->allow_commit();
  88  
  89          // Log this action.
  90          $params = [
  91              'objectid' => $attemptobj->get_question_attempt($slot)->get_question_id(),
  92              'courseid' => $attemptobj->get_courseid(),
  93              'context' => $attemptobj->get_quizobj()->get_context(),
  94              'other' => [
  95                  'quizid' => $attemptobj->get_quizid(),
  96                  'attemptid' => $attemptobj->get_attemptid(),
  97                  'slot' => $slot
  98              ]
  99          ];
 100          $event = \mod_quiz\event\question_manually_graded::create($params);
 101          $event->trigger();
 102  
 103          echo $output->notification(get_string('changessaved'), 'notifysuccess');
 104          close_window(2, true);
 105          die;
 106      }
 107  }
 108  
 109  // Print quiz information.
 110  echo $output->review_summary_table($summarydata, 0);
 111  
 112  // Print the comment form.
 113  echo '<form method="post" class="mform" id="manualgradingform" action="' .
 114          $CFG->wwwroot . '/mod/quiz/comment.php">';
 115  echo $attemptobj->render_question_for_commenting($slot);
 116  ?>
 117  <div>
 118      <input type="hidden" name="attempt" value="<?php echo $attemptobj->get_attemptid(); ?>" />
 119      <input type="hidden" name="slot" value="<?php echo $slot; ?>" />
 120      <input type="hidden" name="slots" value="<?php echo $slot; ?>" />
 121      <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
 122  </div>
 123  <fieldset class="hidden">
 124      <div>
 125          <div class="fitem fitem_actionbuttons fitem_fsubmit mt-3">
 126              <fieldset class="felement fsubmit">
 127                  <input id="id_submitbutton" type="submit" name="submit" class="btn btn-primary" value="<?php
 128                          print_string('save', 'quiz'); ?>"/>
 129              </fieldset>
 130          </div>
 131      </div>
 132  </fieldset>
 133  <?php
 134  echo '</form>';
 135  $PAGE->requires->js_init_call('M.mod_quiz.init_comment_popup', null, false, quiz_get_js_module());
 136  
 137  // End of the page.
 138  echo $output->footer();