Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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', array('attempt' => $attemptid, 'slot' => $slot));
  34  
  35  $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
  36  $student = $DB->get_record('user', array('id' => $attemptobj->get_userid()));
  37  
  38  // Can only grade finished attempts.
  39  if (!$attemptobj->is_finished()) {
  40      print_error('attemptclosed', 'quiz');
  41  }
  42  
  43  // Check login and permissions.
  44  require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
  45  $attemptobj->require_capability('mod/quiz:grade');
  46  
  47  // Print the page header.
  48  $PAGE->set_pagelayout('popup');
  49  $PAGE->set_title(get_string('manualgradequestion', 'quiz', array(
  50          'question' => format_string($attemptobj->get_question_name($slot)),
  51          'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student))));
  52  $PAGE->set_heading($attemptobj->get_course()->fullname);
  53  $output = $PAGE->get_renderer('mod_quiz');
  54  echo $output->header();
  55  
  56  // Prepare summary information about this question attempt.
  57  $summarydata = array();
  58  
  59  // Student name.
  60  $userpicture = new user_picture($student);
  61  $userpicture->courseid = $attemptobj->get_courseid();
  62  $summarydata['user'] = array(
  63      'title'   => $userpicture,
  64      'content' => new action_link(new moodle_url('/user/view.php', array(
  65              'id' => $student->id, 'course' => $attemptobj->get_courseid())),
  66              fullname($student, true)),
  67  );
  68  
  69  // Quiz name.
  70  $summarydata['quizname'] = array(
  71      'title'   => get_string('modulename', 'quiz'),
  72      'content' => format_string($attemptobj->get_quiz_name()),
  73  );
  74  
  75  // Question name.
  76  $summarydata['questionname'] = array(
  77      'title'   => get_string('question', 'quiz'),
  78      'content' => $attemptobj->get_question_name($slot),
  79  );
  80  
  81  // Process any data that was submitted.
  82  if (data_submitted() && confirm_sesskey()) {
  83      if (optional_param('submit', false, PARAM_BOOL) && question_engine::is_manual_grade_in_range($attemptobj->get_uniqueid(), $slot)) {
  84          $transaction = $DB->start_delegated_transaction();
  85          $attemptobj->process_submitted_actions(time());
  86          $transaction->allow_commit();
  87  
  88          // Log this action.
  89          $params = array(
  90              'objectid' => $attemptobj->get_question_attempt($slot)->get_question_id(),
  91              'courseid' => $attemptobj->get_courseid(),
  92              'context' => context_module::instance($attemptobj->get_cmid()),
  93              'other' => array(
  94                  'quizid' => $attemptobj->get_quizid(),
  95                  'attemptid' => $attemptobj->get_attemptid(),
  96                  'slot' => $slot
  97              )
  98          );
  99          $event = \mod_quiz\event\question_manually_graded::create($params);
 100          $event->trigger();
 101  
 102          echo $output->notification(get_string('changessaved'), 'notifysuccess');
 103          close_window(2, true);
 104          die;
 105      }
 106  }
 107  
 108  // Print quiz information.
 109  echo $output->review_summary_table($summarydata, 0);
 110  
 111  // Print the comment form.
 112  echo '<form method="post" class="mform" id="manualgradingform" action="' .
 113          $CFG->wwwroot . '/mod/quiz/comment.php">';
 114  echo $attemptobj->render_question_for_commenting($slot);
 115  ?>
 116  <div>
 117      <input type="hidden" name="attempt" value="<?php echo $attemptobj->get_attemptid(); ?>" />
 118      <input type="hidden" name="slot" value="<?php echo $slot; ?>" />
 119      <input type="hidden" name="slots" value="<?php echo $slot; ?>" />
 120      <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
 121  </div>
 122  <fieldset class="hidden">
 123      <div>
 124          <div class="fitem fitem_actionbuttons fitem_fsubmit">
 125              <fieldset class="felement fsubmit">
 126                  <input id="id_submitbutton" type="submit" name="submit" class="btn btn-primary" value="<?php
 127                          print_string('save', 'quiz'); ?>"/>
 128              </fieldset>
 129          </div>
 130      </div>
 131  </fieldset>
 132  <?php
 133  echo '</form>';
 134  $PAGE->requires->js_init_call('M.mod_quiz.init_comment_popup', null, false, quiz_get_js_module());
 135  
 136  // End of the page.
 137  echo $output->footer();