Added new feature, the time enforced delay on attempting quizzes
This commit is contained in:
@@ -157,6 +157,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ($quiz->delay1 or $quiz->delay2) {
|
||||
//quiz enforced time delay
|
||||
if ($attempts = quiz_get_user_attempts($quiz->id, $USER->id)) {
|
||||
$numattempts = count($attempts);
|
||||
} else {
|
||||
$numattempts = 0;
|
||||
}
|
||||
$timenow = time();
|
||||
$lastattempt_obj = get_record_select('quiz_attempts', "quiz = $quiz->id AND attempt = $numattempts AND userid = $USER->id", 'timefinish');
|
||||
if ($lastattempt_obj) {
|
||||
$lastattempt = $lastattempt_obj->timefinish;
|
||||
}
|
||||
if ($numattempts == 1 && $quiz->delay1) {
|
||||
if ($timenow - $quiz->delay1 < $lastattempt) {
|
||||
error(get_string('timedelay', 'quiz'), 'view.php?q='.$quiz->id);
|
||||
}
|
||||
} else if($numattempts > 1 && $quiz->delay2) {
|
||||
if ($timenow - $quiz->delay2 < $lastattempt) {
|
||||
error(get_string('timedelay', 'quiz'), 'view.php?q='.$quiz->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Load attempt or create a new attempt if there is no unfinished one
|
||||
|
||||
if ($isteacher and $forcenew) { // teacher wants a new preview
|
||||
|
||||
@@ -35,7 +35,8 @@
|
||||
'quiz_fix_timelimit' => 0,
|
||||
'quiz_fix_adaptive' => 0,
|
||||
'quiz_fix_penaltyscheme' => 0,
|
||||
|
||||
'quiz_fix_delay1' => 0,
|
||||
'quiz_fix_delay2' => 0,
|
||||
'attemptuniqueid' => 0
|
||||
);
|
||||
|
||||
|
||||
+73
-1
@@ -67,6 +67,15 @@
|
||||
if (empty($form->timedue)) {
|
||||
$form->timedue = "";
|
||||
}
|
||||
//enforced time delay between quiz attempts add-on
|
||||
//delay1: time delay between first and second attempt
|
||||
//delay2: time delay between second and additional quiz attempt
|
||||
if(!isset($form->delay1)) {
|
||||
$form->delay1 = 0;
|
||||
}
|
||||
if(!isset($form->delay2)) {
|
||||
$form->delay2 = 0;
|
||||
}
|
||||
|
||||
$fix = 0; // This will later be set to 1 if some of the variables have been fixed by the admin.
|
||||
|
||||
@@ -75,7 +84,7 @@
|
||||
$yesnooptions = array();
|
||||
$yesnooptions[0] = get_string("no");
|
||||
$yesnooptions[1] = get_string("yes");
|
||||
|
||||
|
||||
$attemptoptions = array();
|
||||
$attemptoptions[0] = get_string("attemptsunlimited", "quiz");
|
||||
$attemptoptions[1] = "1 ".strtolower(get_string("attempt", "quiz"));
|
||||
@@ -83,6 +92,21 @@
|
||||
$attemptoptions[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
|
||||
}
|
||||
|
||||
//enforced time delay between quiz attempts add-on
|
||||
$timedelayoptions = array();
|
||||
$timedelayoptions[0] = get_string('none');
|
||||
$timedelayoptions[1800] = get_string('numminutes', '', 30);
|
||||
$timedelayoptions[3600] = get_string('numminutes', '', 60);
|
||||
for($i=2; $i<=23; $i++) {
|
||||
$seconds = $i*3600;
|
||||
$timedelayoptions[$seconds] = get_string('numhours', '', $i);
|
||||
}
|
||||
$timedelayoptions[86400] = get_string('numhours', '', 24);
|
||||
for($i=2; $i<=7; $i++) {
|
||||
$seconds = $i*86400;
|
||||
$timedelayoptions[$seconds] = get_string('numdays', '', $i);
|
||||
}
|
||||
|
||||
?>
|
||||
<script type="text/javascript" language="javascript">
|
||||
var dueitems = ['dueday','duemonth','dueyear','duehour', 'dueminute'];
|
||||
@@ -315,6 +339,30 @@
|
||||
</tr>
|
||||
<?php } else $fix=1 ?>
|
||||
|
||||
<?php if (!$CFG->quiz_fix_delay1) { ?>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
|
||||
helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } else $fix=1 ?>
|
||||
|
||||
<?php if (!$CFG->quiz_fix_delay2) { ?>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
|
||||
helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } else $fix=1 ?>
|
||||
|
||||
<?php if (!$CFG->quiz_fix_password) { ?>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
|
||||
@@ -531,6 +579,30 @@
|
||||
echo '</tr>';
|
||||
} ?>
|
||||
|
||||
<?php if ($CFG->quiz_fix_delay1) { ?>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($timedelayoptions, "timedelay", "$form->delay1", "");
|
||||
helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($CFG->quiz_fix_delay2) { ?>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($timedelayoptions, "timedelay", "$form->delay2", "");
|
||||
helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($CFG->quiz_fix_popup) { ?>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
|
||||
|
||||
Reference in New Issue
Block a user