[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/quiz/ -> processattempt.php (source)

   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 deals with processing responses during an attempt at a quiz.
  19   *
  20   * People will normally arrive here from a form submission on attempt.php or
  21   * summary.php, and once the responses are processed, they will be redirected to
  22   * attempt.php or summary.php.
  23   *
  24   * This code used to be near the top of attempt.php, if you are looking for CVS history.
  25   *
  26   * @package   mod_quiz
  27   * @copyright 2009 Tim Hunt
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  
  31  require_once(__DIR__ . '/../../config.php');
  32  require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  33  
  34  // Remember the current time as the time any responses were submitted
  35  // (so as to make sure students don't get penalized for slow processing on this page).
  36  $timenow = time();
  37  
  38  // Get submitted parameters.
  39  $attemptid     = required_param('attempt',  PARAM_INT);
  40  $thispage      = optional_param('thispage', 0, PARAM_INT);
  41  $nextpage      = optional_param('nextpage', 0, PARAM_INT);
  42  $previous      = optional_param('previous',      false, PARAM_BOOL);
  43  $next          = optional_param('next',          false, PARAM_BOOL);
  44  $finishattempt = optional_param('finishattempt', false, PARAM_BOOL);
  45  $timeup        = optional_param('timeup',        0,      PARAM_BOOL); // True if form was submitted by timer.
  46  $scrollpos     = optional_param('scrollpos',     '',     PARAM_RAW);
  47  
  48  $attemptobj = quiz_attempt::create($attemptid);
  49  
  50  // Set $nexturl now.
  51  if ($next) {
  52      $page = $nextpage;
  53  } else if ($previous && $thispage > 0) {
  54      $page = $thispage - 1;
  55  } else {
  56      $page = $thispage;
  57  }
  58  if ($page == -1) {
  59      $nexturl = $attemptobj->summary_url();
  60  } else {
  61      $nexturl = $attemptobj->attempt_url(null, $page);
  62      if ($scrollpos !== '') {
  63          $nexturl->param('scrollpos', $scrollpos);
  64      }
  65  }
  66  
  67  // Check login.
  68  require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
  69  require_sesskey();
  70  
  71  // Check that this attempt belongs to this user.
  72  if ($attemptobj->get_userid() != $USER->id) {
  73      throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
  74  }
  75  
  76  // Check capabilities.
  77  if (!$attemptobj->is_preview_user()) {
  78      $attemptobj->require_capability('mod/quiz:attempt');
  79  }
  80  
  81  // If the attempt is already closed, send them to the review page.
  82  if ($attemptobj->is_finished()) {
  83      throw new moodle_quiz_exception($attemptobj->get_quizobj(),
  84              'attemptalreadyclosed', null, $attemptobj->review_url());
  85  }
  86  
  87  // Process the attempt, getting the new status for the attempt.
  88  $status = $attemptobj->process_attempt($timenow, $finishattempt, $timeup, $thispage);
  89  
  90  if ($status == quiz_attempt::OVERDUE) {
  91      redirect($attemptobj->summary_url());
  92  } else if ($status == quiz_attempt::IN_PROGRESS) {
  93      redirect($nexturl);
  94  } else {
  95      // Attempt abandoned or finished.
  96      redirect($attemptobj->review_url());
  97  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1