2009-11-04 11:58:30 +00:00
|
|
|
<?php
|
2011-02-08 15:02:23 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2008-07-15 16:46:24 +00:00
|
|
|
/**
|
|
|
|
* This page deals with processing responses during an attempt at a quiz.
|
|
|
|
*
|
|
|
|
* People will normally arrive here from a form submission on attempt.php or
|
|
|
|
* summary.php, and once the responses are processed, they will be redirected to
|
|
|
|
* attempt.php or summary.php.
|
|
|
|
*
|
|
|
|
* This code used to be near the top of attempt.php, if you are looking for CVS history.
|
|
|
|
*
|
2014-02-16 11:59:15 +13:00
|
|
|
* @package mod_quiz
|
|
|
|
* @copyright 2009 Tim Hunt
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-07-15 16:46:24 +00:00
|
|
|
*/
|
|
|
|
|
2022-12-19 21:14:51 +00:00
|
|
|
use mod_quiz\quiz_attempt;
|
|
|
|
|
2016-02-26 17:47:58 +11:00
|
|
|
require_once(__DIR__ . '/../../config.php');
|
2008-07-15 16:46:24 +00:00
|
|
|
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
|
|
|
|
2011-02-25 15:36:07 +00:00
|
|
|
// Remember the current time as the time any responses were submitted
|
2012-05-04 12:40:21 +01:00
|
|
|
// (so as to make sure students don't get penalized for slow processing on this page).
|
2008-07-15 16:46:24 +00:00
|
|
|
$timenow = time();
|
|
|
|
|
2011-02-25 15:36:07 +00:00
|
|
|
// Get submitted parameters.
|
2012-07-27 11:42:03 +01:00
|
|
|
$attemptid = required_param('attempt', PARAM_INT);
|
2012-08-01 09:05:32 +08:00
|
|
|
$thispage = optional_param('thispage', 0, PARAM_INT);
|
|
|
|
$nextpage = optional_param('nextpage', 0, PARAM_INT);
|
MDL-52738 quiz: Previous button during attempt review.
This is to be consistent with places like forum and book, where if we
have a next link, we also have a previous link.
At the same time I have amended the links/buttons from 'Previous'/'Next'
to 'Previous page'/'Next page' because I think that is clearer.
Also, on the last page of the quiz, I have changed 'Next' to 'Finish
attempt ...' for consistency with the link in the navigation block.
AMOS BEGIN
CPY [navigatenext,mod_assignment],[navigatenext,mod_quiz]
CPY [navigateprevious,mod_assignment],[navigateprevious,mod_quiz]
AMOS END
2016-01-12 17:08:32 +00:00
|
|
|
$previous = optional_param('previous', false, PARAM_BOOL);
|
2012-07-27 11:42:03 +01:00
|
|
|
$next = optional_param('next', false, PARAM_BOOL);
|
MDL-3030 quiz overdue handling: trigger automatic state transitions.
Here, we catch all the places where a student might be accessing their
own attempts, and make sure any automatic state transitions that
should happen, do happen, before the student sees the attempt.
The places where we need to check this are view.php, startattempt.php
and processattempt.php.
We do not really need to check attempt.php or summary.php, because if
the student is on one of those pages, the JavaScript timer will
auto-submit when time expires, taking them to processattempt.php,
which will do the acutal work.
We intentionally do not trigger state transition when a teacher is
looking at a student's quiz attemp. We will trigger state transitions
on cron, but that is still to do.
Also, the body of the process_... methods still needs to be written.
2012-04-18 19:18:55 +01:00
|
|
|
$finishattempt = optional_param('finishattempt', false, PARAM_BOOL);
|
2012-07-27 11:42:03 +01:00
|
|
|
$timeup = optional_param('timeup', 0, PARAM_BOOL); // True if form was submitted by timer.
|
2021-11-29 04:56:03 +07:00
|
|
|
$mdlscrollto = optional_param('mdlscrollto', '', PARAM_RAW);
|
2018-01-09 09:38:54 +07:00
|
|
|
$cmid = optional_param('cmid', null, PARAM_INT);
|
2008-07-15 16:46:24 +00:00
|
|
|
|
2018-01-09 09:38:54 +07:00
|
|
|
$attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
|
2008-07-15 16:46:24 +00:00
|
|
|
|
2011-02-25 15:36:07 +00:00
|
|
|
// Set $nexturl now.
|
2011-02-08 15:02:23 +00:00
|
|
|
if ($next) {
|
|
|
|
$page = $nextpage;
|
MDL-52738 quiz: Previous button during attempt review.
This is to be consistent with places like forum and book, where if we
have a next link, we also have a previous link.
At the same time I have amended the links/buttons from 'Previous'/'Next'
to 'Previous page'/'Next page' because I think that is clearer.
Also, on the last page of the quiz, I have changed 'Next' to 'Finish
attempt ...' for consistency with the link in the navigation block.
AMOS BEGIN
CPY [navigatenext,mod_assignment],[navigatenext,mod_quiz]
CPY [navigateprevious,mod_assignment],[navigateprevious,mod_quiz]
AMOS END
2016-01-12 17:08:32 +00:00
|
|
|
} else if ($previous && $thispage > 0) {
|
|
|
|
$page = $thispage - 1;
|
2011-02-08 15:02:23 +00:00
|
|
|
} else {
|
|
|
|
$page = $thispage;
|
|
|
|
}
|
|
|
|
if ($page == -1) {
|
2008-07-15 16:46:24 +00:00
|
|
|
$nexturl = $attemptobj->summary_url();
|
|
|
|
} else {
|
2011-08-17 14:40:05 +01:00
|
|
|
$nexturl = $attemptobj->attempt_url(null, $page);
|
2021-11-29 04:56:03 +07:00
|
|
|
if ($mdlscrollto !== '') {
|
|
|
|
$nexturl->param('mdlscrollto', $mdlscrollto);
|
2011-02-08 15:02:23 +00:00
|
|
|
}
|
2008-07-15 16:46:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 15:36:07 +00:00
|
|
|
// Check login.
|
2011-02-08 15:02:23 +00:00
|
|
|
require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
|
2009-11-02 17:10:31 +00:00
|
|
|
require_sesskey();
|
2008-07-15 16:46:24 +00:00
|
|
|
|
2011-02-25 15:36:07 +00:00
|
|
|
// Check that this attempt belongs to this user.
|
2008-07-15 16:46:24 +00:00
|
|
|
if ($attemptobj->get_userid() != $USER->id) {
|
2022-12-16 17:09:36 +00:00
|
|
|
throw new moodle_exception('notyourattempt', 'quiz', $attemptobj->view_url());
|
2008-07-15 16:46:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 15:36:07 +00:00
|
|
|
// Check capabilities.
|
2008-07-15 16:46:24 +00:00
|
|
|
if (!$attemptobj->is_preview_user()) {
|
|
|
|
$attemptobj->require_capability('mod/quiz:attempt');
|
|
|
|
}
|
|
|
|
|
2011-02-25 15:36:07 +00:00
|
|
|
// If the attempt is already closed, send them to the review page.
|
2008-07-15 16:46:24 +00:00
|
|
|
if ($attemptobj->is_finished()) {
|
2022-12-16 17:09:36 +00:00
|
|
|
throw new moodle_exception('attemptalreadyclosed', 'quiz', $attemptobj->view_url());
|
2008-07-15 16:46:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 19:03:48 +12:00
|
|
|
// If this page cannot be accessed, notify user and send them to the correct page.
|
|
|
|
if (!$finishattempt && !$attemptobj->check_page_access($thispage)) {
|
|
|
|
throw new moodle_exception('submissionoutofsequencefriendlymessage', 'question',
|
|
|
|
$attemptobj->attempt_url(null, $attemptobj->get_currentpage()));
|
|
|
|
}
|
|
|
|
|
2016-01-21 17:21:45 +01:00
|
|
|
// Process the attempt, getting the new status for the attempt.
|
|
|
|
$status = $attemptobj->process_attempt($timenow, $finishattempt, $timeup, $thispage);
|
2015-03-09 18:40:18 +00:00
|
|
|
|
2016-01-21 17:21:45 +01:00
|
|
|
if ($status == quiz_attempt::OVERDUE) {
|
|
|
|
redirect($attemptobj->summary_url());
|
|
|
|
} else if ($status == quiz_attempt::IN_PROGRESS) {
|
|
|
|
redirect($nexturl);
|
|
|
|
} else {
|
|
|
|
// Attempt abandoned or finished.
|
|
|
|
redirect($attemptobj->review_url());
|
2011-10-25 14:49:57 +01:00
|
|
|
}
|