本文整理汇总了PHP中quiz_access_manager::current_attempt_finished方法的典型用法代码示例。如果您正苦于以下问题:PHP quiz_access_manager::current_attempt_finished方法的具体用法?PHP quiz_access_manager::current_attempt_finished怎么用?PHP quiz_access_manager::current_attempt_finished使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quiz_access_manager
的用法示例。
在下文中一共展示了quiz_access_manager::current_attempt_finished方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quiz_validate_new_attempt
/**
* Validate permissions for creating a new attempt and start a new preview attempt if required.
*
* @param quiz $quizobj quiz object
* @param quiz_access_manager $accessmanager quiz access manager
* @param bool $forcenew whether was required to start a new preview attempt
* @param int $page page to jump to in the attempt
* @param bool $redirect whether to redirect or throw exceptions (for web or ws usage)
* @return array an array containing the attempt information, access error messages and the page to jump to in the attempt
* @throws moodle_quiz_exception
* @since Moodle 3.1
*/
function quiz_validate_new_attempt(quiz $quizobj, quiz_access_manager $accessmanager, $forcenew, $page, $redirect)
{
global $DB, $USER;
$timenow = time();
if ($quizobj->is_preview_user() && $forcenew) {
$accessmanager->current_attempt_finished();
}
// Check capabilities.
if (!$quizobj->is_preview_user()) {
$quizobj->require_capability('mod/quiz:attempt');
}
// Check to see if a new preview was requested.
if ($quizobj->is_preview_user() && $forcenew) {
// To force the creation of a new preview, we mark the current attempt (if any)
// as finished. It will then automatically be deleted below.
$DB->set_field('quiz_attempts', 'state', quiz_attempt::FINISHED, array('quiz' => $quizobj->get_quizid(), 'userid' => $USER->id));
}
// Look for an existing attempt.
$attempts = quiz_get_user_attempts($quizobj->get_quizid(), $USER->id, 'all', true);
$lastattempt = end($attempts);
$attemptnumber = null;
// If an in-progress attempt exists, check password then redirect to it.
if ($lastattempt && ($lastattempt->state == quiz_attempt::IN_PROGRESS || $lastattempt->state == quiz_attempt::OVERDUE)) {
$currentattemptid = $lastattempt->id;
$messages = $accessmanager->prevent_access();
// If the attempt is now overdue, deal with that.
$quizobj->create_attempt_object($lastattempt)->handle_if_time_expired($timenow, true);
// And, if the attempt is now no longer in progress, redirect to the appropriate place.
if ($lastattempt->state == quiz_attempt::ABANDONED || $lastattempt->state == quiz_attempt::FINISHED) {
if ($redirect) {
redirect($quizobj->review_url($lastattempt->id));
} else {
throw new moodle_quiz_exception($quizobj, 'attemptalreadyclosed');
}
}
// If the page number was not explicitly in the URL, go to the current page.
if ($page == -1) {
$page = $lastattempt->currentpage;
}
} else {
while ($lastattempt && $lastattempt->preview) {
$lastattempt = array_pop($attempts);
}
// Get number for the next or unfinished attempt.
if ($lastattempt) {
$attemptnumber = $lastattempt->attempt + 1;
} else {
$lastattempt = false;
$attemptnumber = 1;
}
$currentattemptid = null;
$messages = $accessmanager->prevent_access() + $accessmanager->prevent_new_attempt(count($attempts), $lastattempt);
if ($page == -1) {
$page = 0;
}
}
return array($currentattemptid, $attemptnumber, $lastattempt, $messages, $page);
}