Skip to content

Commit

Permalink
Exercise submit: improve time tracking after pause, better nav buttons
Browse files Browse the repository at this point in the history
--HG--
branch : 3.11
  • Loading branch information
adia committed May 24, 2021
1 parent acf0ba7 commit 3051ada
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
9 changes: 7 additions & 2 deletions js/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ function exercise_init_countdown(params) {
var exerciseId = params.exerciseId,
eurid = params.eurid;

$('.clearSelect').click(function (e) {
e.preventDefault();
$(this).closest('.panel-body').find('input[type=radio]').prop('checked', false);
});

// Don't submit question on enter keypress in input field
$('.exercise input').keydown(function(event) {
if (event.which === 13) {
Expand Down Expand Up @@ -713,10 +718,10 @@ function unit_password_bootbox(e) {
title;

if (el.hasClass('paused_exercise')) {
title = lang.continueAttempt;
lang.submit = title = lang.continueAttempt;
notice = '<p>' + lang.temporarySaveNotice + '</p>';
} else if (el.hasClass('active_exercise')) {
title = lang.continueAttempt;
lang.submit = title = lang.continueAttempt;
notice = '<p>' + lang.continueAttemptNotice + '</p>';
}
if (el.hasClass('password_protected')) {
Expand Down
1 change: 1 addition & 0 deletions lang/el/messages.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,7 @@
$langQuestionPoolPurgeSuccess = "Η διαγραφή των αχρησιμοποίητων ερωτήσεων από την τράπεζα ερωτήσεων πραγματοποιήθηκε.";
$langShuffleQuestions = "Ανακάτεμα όλων των ερωτήσεων";
$langShuffleQuestions = "Ανακάτεμα όλων των ερωτήσεων";
$langClear = 'Εκκαθάριση';

// admin.php
$langExerciseManagement = "Διαχείριση Άσκησης";
Expand Down
1 change: 1 addition & 0 deletions lang/en/messages.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -5391,3 +5391,4 @@
$langUsersInOtherGroups = 'The following users were already members of other groups and cannot be added to this one';
$langUsersOverMaximum = 'The final count (%d) exceeds the maximum number of group members (%d).';
$langUsersAddedToGroup = 'The users were added to the group.';
$langClear = 'Clear';
8 changes: 5 additions & 3 deletions modules/exercise/exercise.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
function showQuestion(&$objQuestionTmp, $exerciseResult = array(), $question_number) {
global $tool_content, $picturePath, $langNoAnswer, $langQuestion,
$langColumnA, $langColumnB, $langMakeCorrespond, $langInfoGrades,
$exerciseType, $nbrQuestions, $langInfoGrade, $langHasAnswered;

$exerciseType, $nbrQuestions, $langInfoGrade, $langHasAnswered, $langClear;

$questionId = $objQuestionTmp->selectId();
$questionWeight = $objQuestionTmp->selectWeighting();
Expand Down Expand Up @@ -199,6 +198,9 @@ function showQuestion(&$objQuestionTmp, $exerciseResult = array(), $question_num
if (!$nbrAnswers && $answerType != FREE_TEXT) {
$tool_content .= "<div class='alert alert-danger'>$langNoAnswer</div>";
}
if (in_array($answerType, [TRUE_FALSE, UNIQUE_ANSWER])) {
$tool_content .= "<button class='pull-right clearSelect btn btn-default btn-sm'><span class='fa fa-times'></span> $langClear</button>";
}
$tool_content .= "
</div>
</div>";
Expand Down Expand Up @@ -459,4 +461,4 @@ function display_exercise($exercise_id) {
if (!$hasRandomQuestions) {
$tool_content .= "<div class='col-sm-12'><span class='pull-right'><strong>$langYourTotalScore: $totalWeighting</strong></span></div>";
}
}
}
68 changes: 34 additions & 34 deletions modules/exercise/exercise_submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,25 @@ function unset_exercise_var($exerciseId) {

$nbrQuestions = count($questionList);


// determine begin time:
// either from a previews attempt meaning that user hasn't submitted his answers permanently
// and exerciseTimeConstrain hasn't yet passed,
// either start a new attempt and count now() as begin time.

if (isset($_SESSION['exerciseUserRecordID'][$exerciseId][$attempt_value]) || isset($paused_attempt)) {
$eurid = isset($paused_attempt) ? $_SESSION['exerciseUserRecordID'][$exerciseId][$attempt_value] = $paused_attempt->eurid : $_SESSION['exerciseUserRecordID'][$exerciseId][$attempt_value];
$recordStartDate = Database::get()->querySingle("SELECT record_start_date FROM exercise_user_record WHERE eurid = ?d", $eurid)->record_start_date;
$recordStartDate = strtotime($recordStartDate);
// if exerciseTimeConstrain has not passed yet calculate the remaining time
if ($exerciseTimeConstraint > 0) {
$timeleft = isset($paused_attempt) ? $paused_attempt->secs_remaining : ($exerciseTimeConstraint * 60) - ($temp_CurrentDate - $recordStartDate);
$record = Database::get()->querySingle("SELECT record_start_date, record_end_date, secs_remaining FROM exercise_user_record WHERE eurid = ?d", $eurid);
$recordStartDate = strtotime($record->record_start_date);
if (isset($paused_attempt) and $paused_attempt->secs_remaining) {
// resume paused attempt with same time left
$timeleft = $paused_attempt->secs_remaining;
} elseif ($record->record_end_date and $record->secs_remaining) {
// navigation within exercise: subtract time from last submission timestamp
$recordEndDate = strtotime($record->record_end_date);
$timeleft = $record->secs_remaining - ($temp_CurrentDate - $recordEndDate);
} elseif ($exerciseTimeConstraint > 0) {
// if exerciseTimeConstrain has not passed yet calculate the remaining time
$timeleft = $exerciseTimeConstraint * 60 - ($temp_CurrentDate - $recordStartDate);
}
} elseif (!isset($_SESSION['exerciseUserRecordID'][$exerciseId][$attempt_value]) && $nbrQuestions > 0) {
$attempt = Database::get()->querySingle("SELECT COUNT(*) AS count FROM exercise_user_record WHERE eid = ?d AND uid= ?d", $exerciseId, $uid)->count;
Expand Down Expand Up @@ -457,8 +463,8 @@ function unset_exercise_var($exerciseId) {
$exerciseTimeLeft = $exercise_EndDate->getTimestamp() - $temp_CurrentDate;
if ($exerciseTimeLeft) {
if ($exerciseTimeLeft < 0 and $is_editor) {
// Give editors time to test expired exercises
$exerciseTimeLeft = 24 * 3600;
// Give editors unlimited time to test expired exercises
unset($timeleft);
} elseif ($exerciseTimeLeft < 3 * 3600 and (!isset($timeleft) or $exerciseTimeLeft < $timeleft)) {
// Display countdown of exercise remaining time if less than
// user's remaining time or less than 3 hours away
Expand All @@ -471,12 +477,9 @@ function unset_exercise_var($exerciseId) {
// if the user has submitted the form
if (isset($_POST['formSent'])) {
$time_expired = false;
// checking if user's time expired
if (isset($timeleft)) {
$timeleft += 1; // Add 1 sec for leniency when submitting
if ($timeleft < 0) {
$time_expired = true;
}
// check if user's time expired
if (isset($timeleft) and $timeleft <= 0) {
$time_expired = true;
}

// insert answers in the database and add them in the $exerciseResult array which is returned
Expand All @@ -489,18 +492,15 @@ function unset_exercise_var($exerciseId) {

$_SESSION['exerciseResult'][$exerciseId][$attempt_value] = $exerciseResult;

// if it is a non-sequential exercise
// OR the time has expired
if ($exerciseType == SINGLE_PAGE_TYPE && !isset($_POST['buttonSave']) ||
($exerciseType == MULTIPLE_PAGE_TYPE || $exerciseType == ONE_WAY_TYPE) && (isset($_POST['buttonFinish']) || $time_expired)) {
// if the user has made a final submission or the time has expired
if (isset($_POST['buttonFinish']) or $time_expired) {
if (isset($_POST['secsRemaining'])) {
$secs_remaining = $_POST['secsRemaining'];
} else {
$secs_remaining = 0;
}
$eurid = $_SESSION['exerciseUserRecordID'][$exerciseId][$attempt_value];
$record_end_date = date('Y-m-d H:i:s', time());

$totalScore = $objExercise->calculate_total_score($eurid);

if ($objExercise->isRandom() or $objExercise->hasQuestionListWithRandomCriteria()) {
Expand Down Expand Up @@ -580,13 +580,10 @@ function unset_exercise_var($exerciseId) {
}
}

if (isset($timeleft)) {
if (isset($timeleft)) { // time remaining
if ($timeleft <= 1) {
$timeleft = 1;
}
}

if (isset($timeleft)) { // time remaining
$tool_content .= "<div class='row alert alert-danger' style='margin-left:0px; margin-right:0px; border:1px solid #cab4b4; border-radius:5px;'>";
$tool_content .= "<div class='col-sm-12'><h4 class='text-center'>$langRemainingTime: <span id='progresstime'>$timeleft</span></h4></div>";
$tool_content .= "</div>";
Expand All @@ -612,8 +609,8 @@ function unset_exercise_var($exerciseId) {
<input type='hidden' name='attempt_value' value='$attempt_value'>
<input type='hidden' name='nbrQuestions' value='$nbrQuestions'>";

if (isset($timeleft) && $timeleft > 0) {
$tool_content .= "<input type='hidden' name='secsRemaining' id='secsRemaining' value='$timeleft' />";
if (isset($timeleft)) {
$tool_content .= "<input type='hidden' name='secsRemaining' id='secsRemaining' value='$timeleft'>";
}

$unansweredIds = $answeredIds = array();
Expand Down Expand Up @@ -694,18 +691,22 @@ function unset_exercise_var($exerciseId) {
$tool_content .= "<div style='margin-bottom: 20px;'>";
foreach ($questionList as $k => $q_id) {
$answered = in_array($q_id, $answeredIds);
$tool_content .= "<span style='display: inline-block; margin-right: 10px; margin-bottom: 15px;'>";
if ($questionNumber == $k) { // we are in the current question
$round_border = "border-radius: 70%;";
if ($answered) {
$class = 'btn-info';
$title = q($langHasAnswered);
} else {
$round_border = '';
$class = 'btn-default';
$title = q($langPendingAnswered);
}
if ($answered) {
$tool_content .= "<input class='btn btn-info' style='$round_border' type='submit' name='q_id' value='$k' data-toggle='tooltip' data-placement='top' title='$langHasAnswered'>";
if ($questionNumber == $k) { // we are in the current question
$extra_style = "style='outline: 2px solid #3584e4; outline-offset: 2px;'";
} else {
$tool_content .= "<input class='btn btn-default' style='$round_border' type='submit' name='q_id' value='$k' data-toggle='tooltip' data-placement='top' title='$langPendingAnswered'>";
$extra_style = '';
}
$tool_content .= "</span>";
$tool_content .= "
<div style='display: inline-block; margin-right: 10px; margin-bottom: 15px;'>
<input class='btn $class' $extra_style type='submit' name='q_id' id='q_num$k' value='$k' data-toggle='tooltip' data-placement='top' title='$title'>
</div>";
}
$tool_content .= "</div>";
}
Expand Down Expand Up @@ -813,7 +814,6 @@ function unset_exercise_var($exerciseId) {
// Enable check for unanswered questions when displaying more than one question
if ($exerciseType == ONE_WAY_TYPE) {
$checkSinglePage = 'true';
$answeredIds = [];
$unansweredIds = [];
$oneUnanswered = js_escape($langUnansweredQuestionsWarningThisOne);
$questionPrompt = js_escape($langUnansweredQuestionsNoTurnBack);
Expand Down

0 comments on commit 3051ada

Please sign in to comment.