Admin: Add config quiz_check_all_answers_before_end_test BT#18253

WIP
pull/3766/head^2
Julio 5 years ago
parent 4019759ed1
commit ea949a732d
  1. 21
      main/exercise/exercise.class.php
  2. 2
      main/exercise/exercise_reminder.php
  3. 55
      main/exercise/exercise_submit.php
  4. 669
      main/inc/ajax/exercise.ajax.php
  5. 3
      main/install/configuration.dist.php

@ -3328,11 +3328,13 @@ class Exercise
$endReminderValue = true;
}
}
$endTest = false;
if ($this->type == ALL_ON_ONE_PAGE || $nbrQuestions == $questionNum || $endReminderValue) {
if ($this->review_answers) {
$label = get_lang('ReviewQuestions');
$class = 'btn btn-success';
} else {
$endTest = true;
$label = get_lang('EndTest');
$class = 'btn btn-warning';
}
@ -3395,10 +3397,15 @@ class Exercise
]
);
} else {
$attributes = ['type' => 'button', 'class' => $class, 'data-question' => $question_id];
$name = 'save_now';
if ($endTest && api_get_configuration_value('quiz_check_all_answers_before_end_test')) {
$name = 'check_answers';
}
$buttonList[] = Display::button(
'save_now',
$name,
$label,
['type' => 'button', 'class' => $class, 'data-question' => $question_id]
$attributes
);
}
$buttonList[] = '<span id="save_for_now_'.$question_id.'" class="exercise_save_mini_message"></span>';
@ -4922,7 +4929,7 @@ class Exercise
$coords = array_filter($coords);
$user_array = '';
foreach ($coords as $coord) {
list($x, $y) = explode(';', $coord);
[$x, $y] = explode(';', $coord);
$user_array .= round($x).';'.round($y).'/';
}
$user_array = substr($user_array, 0, -1) ?: '';
@ -10363,7 +10370,7 @@ class Exercise
return $lpList;
}
public function getReminderTable($questionList, $exercise_stat_info)
public function getReminderTable($questionList, $exercise_stat_info, $disableCheckBoxes = false)
{
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0;
@ -10376,7 +10383,6 @@ class Exercise
$remindList = $exercise_stat_info['questions_to_check'];
$remindList = explode(',', $remindList);
$exeId = $exercise_stat_info['exe_id'];
$exerciseId = $exercise_stat_info['exe_exo_id'];
$exercise_result = $this->getUserAnswersSavedInExercise($exeId);
@ -10414,10 +10420,11 @@ class Exercise
if (!in_array($questionId, $exercise_result)) {
$questionTitle = Display::label($questionTitle, 'danger');
}
$label_attributes = [];
$label_attributes['for'] = $check_id;
$questionTitle = Display::tag('label', $checkbox.$questionTitle, $label_attributes);
if (false === $disableCheckBoxes) {
$questionTitle = Display::tag('label', $checkbox.$questionTitle, $label_attributes);
}
$table .= Display::div($questionTitle, ['class' => 'exercise_reminder_item ']);
}

@ -88,7 +88,7 @@ if (!$hideHeaderAndFooter) {
}
// I'm in a preview mode as course admin. Display the action menu.
if (api_is_course_admin() && !$hideHeaderAndFooter) {
if (!$hideHeaderAndFooter && api_is_course_admin()) {
echo '<div class="actions">';
echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.
Display::return_icon('back.png', get_lang('GoBackToQuestionList'), [], 32).'</a>';

@ -467,6 +467,7 @@ if (empty($exercise_stat_info)) {
}
Session::write('exe_id', $exe_id);
$checkAnswersUrl = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=check_answers&exe_id='.$exe_id.'&'.api_get_cidreq();
$saveDurationUrl = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=update_duration&exe_id='.$exe_id.'&'.api_get_cidreq();
$questionListInSession = Session::read('questionList');
$selectionType = $objExercise->getQuestionSelectionType();
@ -1272,6 +1273,7 @@ $saveIcon = Display::return_icon(
false,
true
);
$loading = Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin');
echo '<script>
function addExerciseEvent(elm, evType, fn, useCapture) {
@ -1350,10 +1352,52 @@ echo '<script>
save_question_list(questionList);
});
$(\'button[name="save_now"]\').on(\'touchstart click\', function (e) {
$(\'button[name="check_answers"]\').on(\'touchstart click\', function (e) {
e.preventDefault();
e.stopPropagation();
var $this = $(this);
var urlExtra = $this.data(\'url\') || null;
var questionId = parseInt($this.data(\'question\')) || 0;
save_now(questionId, "check_answers");
var checkUrl = "'.$checkAnswersUrl.'";
$("#global-modal").attr("data-keyboard", "false");
$("#global-modal").attr("data-backdrop", "static");
$("#global-modal").find(".close").hide();
$("#global-modal .modal-body").load(checkUrl, function() {
$("#global-modal .modal-body").append("<div class=\"btn-group\"></div>");
var continueTest = $("<a>",{
text: "'.addslashes(get_lang('ContinueTest')).'",
title: "'.addslashes(get_lang('ContinueTest')).'",
href: "javascript:void(0);",
click: function(){
$(this).attr("disabled", "disabled");
$("#global-modal").modal("hide");
$("#global-modal .modal-body").html("");
}
}).addClass("btn btn-default").appendTo("#global-modal .modal-body .btn-group");
$("<a>",{
text: "'.addslashes(get_lang('EndTest')).'",
title: "'.addslashes(get_lang('EndTest')).'",
href: "javascript:void(0);",
click: function() {
$(this).attr("disabled", "disabled");
continueTest.attr("disabled", "disabled");
save_now(questionId, urlExtra);
$("#global-modal .modal-body").html("<span style=\"text-align:center\">'.addslashes($loading).addslashes(get_lang('Loading')).'</span>");
}
}).addClass("btn btn-primary").appendTo("#global-modal .modal-body .btn-group");
});
$("#global-modal").modal("show");
});
$(\'button[name="save_now"]\').on(\'touchstart click\', function (e) {
e.preventDefault();
e.stopPropagation();
var
$this = $(this),
questionId = parseInt($this.data(\'question\')) || 0,
@ -1442,8 +1486,7 @@ echo '<script>
dataparam += remind_list ? ("&" + remind_list) : "";
dataparam += my_choiceDc ? ("&" + my_choiceDc) : "";
$("#save_for_now_"+question_id).html(\''.
Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin').'\');
$("#save_for_now_"+question_id).html(\''.$loading.'\');
$.ajax({
type:"post",
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=save_exercise_by_now",
@ -1478,6 +1521,10 @@ echo '<script>
$("#save_for_now_"+question_id).html(\''.
Display::return_icon('save.png', get_lang('Saved'), [], ICON_SIZE_SMALL).'\');
if ("check_answers" === url_extra) {
return true;
}
// window.quizTimeEnding will be reset in exercise.class.php
if (window.quizTimeEnding) {
redirectExerciseToResult();
@ -1517,7 +1564,7 @@ echo '<script>
});
free_answers = $.param(free_answers);
$("#save_all_response").html(\''.Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin').'\');
$("#save_all_response").html(\''.$loading.'\');
var requestData = "'.$params.'&type=all";
requestData += "&" + my_choice;

@ -394,400 +394,421 @@ switch ($action) {
echo 1;
exit;
break;
case 'check_answers':
if (false === api_is_allowed_to_session_edit()) {
echo 'error';
exit;
}
/** @var Exercise $objExercise */
$objExercise = Session::read('objExercise');
$questionList = Session::read('questionList');
$exeId = Session::read('exe_id');
// If exercise or question is not set then exit.
if (empty($questionList) || empty($objExercise)) {
echo 'error';
exit;
}
$statInfo = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
echo Display::page_subheader(get_lang('QuestionsToReview'));
echo $objExercise->getReminderTable($questionList, $statInfo, true);
break;
case 'save_exercise_by_now':
$course_info = api_get_course_info_by_id($course_id);
$course_id = $course_info['real_id'];
// Use have permissions to edit exercises results now?
if (api_is_allowed_to_session_edit()) {
// "all" or "simple" strings means that there's one or all questions exercise type
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
if (false === api_is_allowed_to_session_edit()) {
echo 'error';
if ($debug) {
error_log(
'Exercises attempt '.$exeId.': Failed saving question(s) in course/session '.
$course_id.'/'.$session_id.
': The user ('.api_get_user_id().') does not have the permission to access this session now'
);
}
exit;
}
// Questions choices.
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : [];
// "all" or "simple" strings means that there's one or all questions exercise type
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
// certainty degree choice
$choiceDegreeCertainty = isset($_REQUEST['choiceDegreeCertainty']) ? $_REQUEST['choiceDegreeCertainty'] : [];
// Questions choices.
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : [];
// Hot spot coordinates from all questions.
$hot_spot_coordinates = isset($_REQUEST['hotspot']) ? $_REQUEST['hotspot'] : [];
// certainty degree choice
$choiceDegreeCertainty = isset($_REQUEST['choiceDegreeCertainty']) ? $_REQUEST['choiceDegreeCertainty'] : [];
// There is a reminder?
$remind_list = isset($_REQUEST['remind_list']) && !empty($_REQUEST['remind_list'])
? array_keys($_REQUEST['remind_list']) : [];
// Hot spot coordinates from all questions.
$hot_spot_coordinates = isset($_REQUEST['hotspot']) ? $_REQUEST['hotspot'] : [];
// Needed in manage_answer.
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0;
// There is a reminder?
$remind_list = isset($_REQUEST['remind_list']) && !empty($_REQUEST['remind_list'])
? array_keys($_REQUEST['remind_list']) : [];
if ($debug) {
error_log("exe_id = $exeId");
error_log("type = $type");
error_log("choice = ".print_r($choice, 1)." ");
error_log("hot_spot_coordinates = ".print_r($hot_spot_coordinates, 1));
error_log("remind_list = ".print_r($remind_list, 1));
error_log("--------------------------------");
}
// Needed in manage_answer.
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0;
// Exercise information.
/** @var Exercise $objExercise */
$objExercise = Session::read('objExercise');
if ($debug) {
error_log("exe_id = $exeId");
error_log("type = $type");
error_log("choice = ".print_r($choice, 1)." ");
error_log("hot_spot_coordinates = ".print_r($hot_spot_coordinates, 1));
error_log("remind_list = ".print_r($remind_list, 1));
error_log("--------------------------------");
}
// Question info.
$question_id = isset($_REQUEST['question_id']) ? (int) $_REQUEST['question_id'] : null;
$question_list = Session::read('questionList');
/** @var Exercise $objExercise */
$objExercise = Session::read('objExercise');
// If exercise or question is not set then exit.
if (empty($question_list) || empty($objExercise)) {
echo 'error';
if ($debug) {
if (empty($question_list)) {
error_log("question_list is empty");
}
if (empty($objExercise)) {
error_log("objExercise is empty");
}
}
exit;
}
// Question info.
$question_id = isset($_REQUEST['question_id']) ? (int) $_REQUEST['question_id'] : null;
$question_list = Session::read('questionList');
if (WhispeakAuthPlugin::questionRequireAuthentify($question_id)) {
if ($objExercise->type == ONE_PER_PAGE) {
echo 'one_per_page';
break;
// If exercise or question is not set then exit.
if (empty($question_list) || empty($objExercise)) {
echo 'error';
if ($debug) {
if (empty($question_list)) {
error_log("question_list is empty");
}
echo 'ok';
break;
} else {
ChamiloSession::erase(WhispeakAuthPlugin::SESSION_QUIZ_QUESTION);
}
// Getting information of the current exercise.
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
$exercise_id = $exercise_stat_info['exe_exo_id'];
$attemptList = [];
// First time here we create an attempt (getting the exe_id).
if (!empty($exercise_stat_info)) {
// We know the user we get the exe_id.
$exeId = $exercise_stat_info['exe_id'];
$total_score = $exercise_stat_info['exe_result'];
// Getting the list of attempts
$attemptList = Event::getAllExerciseEventByExeId($exeId);
}
// No exe id? Can't save answer.
if (empty($exeId)) {
// Fires an error.
echo 'error';
if ($debug) {
error_log('exe_id is empty');
if (empty($objExercise)) {
error_log("objExercise is empty");
}
exit;
}
exit;
}
Session::write('exe_id', $exeId);
// Updating Reminder algorithm.
if (WhispeakAuthPlugin::questionRequireAuthentify($question_id)) {
if ($objExercise->type == ONE_PER_PAGE) {
$bd_reminder_list = explode(',', $exercise_stat_info['questions_to_check']);
if (empty($remind_list)) {
$remind_list = $bd_reminder_list;
$new_list = [];
foreach ($bd_reminder_list as $item) {
if ($item != $question_id) {
$new_list[] = $item;
}
}
$remind_list = $new_list;
} else {
if (isset($remind_list[0])) {
if (!in_array($remind_list[0], $bd_reminder_list)) {
array_push($bd_reminder_list, $remind_list[0]);
}
$remind_list = $bd_reminder_list;
}
}
echo 'one_per_page';
break;
}
// Getting the total weight if the request is simple.
$total_weight = 0;
if ($type === 'simple') {
foreach ($question_list as $my_question_id) {
$objQuestionTmp = Question::read($my_question_id, $objExercise->course);
$total_weight += $objQuestionTmp->selectWeighting();
}
}
unset($objQuestionTmp);
echo 'ok';
break;
} else {
ChamiloSession::erase(WhispeakAuthPlugin::SESSION_QUIZ_QUESTION);
}
// Getting information of the current exercise.
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
$exercise_id = $exercise_stat_info['exe_exo_id'];
$attemptList = [];
// First time here we create an attempt (getting the exe_id).
if (!empty($exercise_stat_info)) {
// We know the user we get the exe_id.
$exeId = $exercise_stat_info['exe_id'];
$total_score = $exercise_stat_info['exe_result'];
// Getting the list of attempts
$attemptList = Event::getAllExerciseEventByExeId($exeId);
}
// No exe id? Can't save answer.
if (empty($exeId)) {
// Fires an error.
echo 'error';
if ($debug) {
error_log('Starting questions loop in save_exercise_by_now');
error_log('exe_id is empty');
}
exit;
}
Session::write('exe_id', $exeId);
// Check we have at least one non-empty answer in the array
// provided by the user's click on the "Finish test" button.
if ('all' === $type) {
$atLeastOneAnswer = false;
foreach ($question_list as $my_question_id) {
if (!empty($choice[$my_question_id])) {
$atLeastOneAnswer = true;
break;
// Updating Reminder algorithm.
if ($objExercise->type == ONE_PER_PAGE) {
$bd_reminder_list = explode(',', $exercise_stat_info['questions_to_check']);
if (empty($remind_list)) {
$remind_list = $bd_reminder_list;
$new_list = [];
foreach ($bd_reminder_list as $item) {
if ($item != $question_id) {
$new_list[] = $item;
}
}
if (!$atLeastOneAnswer) {
error_log(
'In '.__FILE__.'::action save_exercise_by_now,'.
' from user '.api_get_user_id().
' for track_e_exercises.exe_id = '.$exeId.
', we received an empty set of answers.'.
'Preventing submission to avoid overwriting w/ null.');
echo 'error';
exit;
$remind_list = $new_list;
} else {
if (isset($remind_list[0])) {
if (!in_array($remind_list[0], $bd_reminder_list)) {
array_push($bd_reminder_list, $remind_list[0]);
}
$remind_list = $bd_reminder_list;
}
}
}
// Looping the question list from database (not from the user answer)
// Getting the total weight if the request is simple.
$total_weight = 0;
if ($type === 'simple') {
foreach ($question_list as $my_question_id) {
if ($type === 'simple' && $question_id != $my_question_id) {
continue;
}
$my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null;
$objQuestionTmp = Question::read($my_question_id, $objExercise->course);
$myChoiceDegreeCertainty = null;
if ($objQuestionTmp->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
if (isset($choiceDegreeCertainty[$my_question_id])) {
$myChoiceDegreeCertainty = $choiceDegreeCertainty[$my_question_id];
}
}
$total_weight += $objQuestionTmp->selectWeighting();
}
}
unset($objQuestionTmp);
// Getting free choice data.
if ('all' === $type && in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION])) {
$my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id])
? $_REQUEST['free_choice'][$my_question_id]
: null;
}
if ($debug) {
error_log('Starting questions loop in save_exercise_by_now');
}
if ($type === 'all') {
// If saving the whole exercise (not only one question),
// record the sum of individual max scores (called
// "exe_weighting" in track_e_exercises)
$total_weight += $objQuestionTmp->selectWeighting();
// Check we have at least one non-empty answer in the array
// provided by the user's click on the "Finish test" button.
if ('all' === $type) {
$atLeastOneAnswer = false;
foreach ($question_list as $my_question_id) {
if (!empty($choice[$my_question_id])) {
$atLeastOneAnswer = true;
break;
}
}
if (!$atLeastOneAnswer) {
error_log(
'In '.__FILE__.'::action save_exercise_by_now,'.
' from user '.api_get_user_id().
' for track_e_exercises.exe_id = '.$exeId.
', we received an empty set of answers.'.
'Preventing submission to avoid overwriting w/ null.');
echo 'error';
exit;
}
}
// This variable came from exercise_submit_modal.php.
$hotspot_delineation_result = null;
if (isset($_SESSION['hotspot_delineation_result']) &&
isset($_SESSION['hotspot_delineation_result'][$objExercise->selectId()])
) {
$hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$my_question_id];
// Looping the question list from database (not from the user answer)
foreach ($question_list as $my_question_id) {
if ($type === 'simple' && $question_id != $my_question_id) {
continue;
}
$my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null;
$objQuestionTmp = Question::read($my_question_id, $objExercise->course);
$myChoiceDegreeCertainty = null;
if ($objQuestionTmp->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
if (isset($choiceDegreeCertainty[$my_question_id])) {
$myChoiceDegreeCertainty = $choiceDegreeCertainty[$my_question_id];
}
}
if ('simple' === $type) {
// Getting old attempt in order to decrease the total score.
$old_result = $objExercise->manage_answer(
$exeId,
$my_question_id,
null,
'exercise_show',
[],
false,
true,
false,
$objExercise->selectPropagateNeg()
);
// Removing old score.
$total_score = $total_score - $old_result['score'];
}
// Getting free choice data.
if ('all' === $type && in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION])) {
$my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id])
? $_REQUEST['free_choice'][$my_question_id]
: null;
}
$questionDuration = 0;
if (api_get_configuration_value('allow_time_per_question')) {
$extraFieldValue = new ExtraFieldValue('question');
$value = $extraFieldValue->get_values_by_handler_and_field_variable($objQuestionTmp->iid, 'time');
if (!empty($value) && isset($value['value']) && !empty($value['value'])) {
$questionDuration = Event::getAttemptQuestionDuration($exeId, $objQuestionTmp->iid);
if (empty($questionDuration)) {
echo 'error';
if ($debug) {
error_log("Question duration = 0, in exeId: $exeId, question_id: $my_question_id");
}
exit;
if ($type === 'all') {
// If saving the whole exercise (not only one question),
// record the sum of individual max scores (called
// "exe_weighting" in track_e_exercises)
$total_weight += $objQuestionTmp->selectWeighting();
}
// This variable came from exercise_submit_modal.php.
$hotspot_delineation_result = null;
if (isset($_SESSION['hotspot_delineation_result']) &&
isset($_SESSION['hotspot_delineation_result'][$objExercise->selectId()])
) {
$hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$my_question_id];
}
if ('simple' === $type) {
// Getting old attempt in order to decrease the total score.
$old_result = $objExercise->manage_answer(
$exeId,
$my_question_id,
null,
'exercise_show',
[],
false,
true,
false,
$objExercise->selectPropagateNeg()
);
// Removing old score.
$total_score = $total_score - $old_result['score'];
}
$questionDuration = 0;
if (api_get_configuration_value('allow_time_per_question')) {
$extraFieldValue = new ExtraFieldValue('question');
$value = $extraFieldValue->get_values_by_handler_and_field_variable($objQuestionTmp->iid, 'time');
if (!empty($value) && isset($value['value']) && !empty($value['value'])) {
$questionDuration = Event::getAttemptQuestionDuration($exeId, $objQuestionTmp->iid);
if (empty($questionDuration)) {
echo 'error';
if ($debug) {
error_log("Question duration = 0, in exeId: $exeId, question_id: $my_question_id");
}
exit;
}
}
}
// Deleting old attempt.
if (isset($attemptList) && !empty($attemptList[$my_question_id])) {
if ($debug) {
error_log("delete_attempt exe_id : $exeId, my_question_id: $my_question_id");
}
Event::delete_attempt(
// Deleting old attempt.
if (isset($attemptList) && !empty($attemptList[$my_question_id])) {
if ($debug) {
error_log("delete_attempt exe_id : $exeId, my_question_id: $my_question_id");
}
Event::delete_attempt(
$exeId,
api_get_user_id(),
$course_id,
$session_id,
$my_question_id
);
if ($objQuestionTmp->type === HOT_SPOT) {
Event::delete_attempt_hotspot(
$exeId,
api_get_user_id(),
$course_id,
$session_id,
$my_question_id
);
if ($objQuestionTmp->type === HOT_SPOT) {
Event::delete_attempt_hotspot(
$exeId,
api_get_user_id(),
$course_id,
$session_id,
$my_question_id
);
}
if (isset($attemptList[$my_question_id]) &&
isset($attemptList[$my_question_id]['marks'])
) {
$total_score -= $attemptList[$my_question_id]['marks'];
}
}
// We're inside *one* question. Go through each possible answer for this question
if ($objQuestionTmp->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
$myChoiceTmp = [];
$myChoiceTmp['choice'] = $my_choice;
$myChoiceTmp['choiceDegreeCertainty'] = $myChoiceDegreeCertainty;
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$myChoiceTmp,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result,
true,
false,
false,
$questionDuration
);
} else {
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$my_choice,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result,
true,
false,
false,
$questionDuration
);
if (isset($attemptList[$my_question_id]) &&
isset($attemptList[$my_question_id]['marks'])
) {
$total_score -= $attemptList[$my_question_id]['marks'];
}
}
// Adding the new score.
$total_score += $result['score'];
// We're inside *one* question. Go through each possible answer for this question
if ($objQuestionTmp->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
$myChoiceTmp = [];
$myChoiceTmp['choice'] = $my_choice;
$myChoiceTmp['choiceDegreeCertainty'] = $myChoiceDegreeCertainty;
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$myChoiceTmp,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result,
true,
false,
false,
$questionDuration
);
} else {
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$my_choice,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result,
true,
false,
false,
$questionDuration
);
}
if ($debug) {
error_log("total_score: $total_score ");
error_log("total_weight: $total_weight ");
}
// Adding the new score.
$total_score += $result['score'];
$duration = 0;
$now = time();
if ($type === 'all') {
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
}
if ($debug) {
error_log("total_score: $total_score ");
error_log("total_weight: $total_weight ");
}
$key = ExerciseLib::get_time_control_key(
$exercise_id,
$exercise_stat_info['orig_lp_id'],
$exercise_stat_info['orig_lp_item_id']
);
$duration = 0;
$now = time();
if ($type === 'all') {
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
}
$durationTime = Session::read('duration_time');
if (isset($durationTime[$key]) && !empty($durationTime[$key])) {
if ($debug) {
error_log('Session time: '.$durationTime[$key]);
}
$duration = $now - $durationTime[$key];
if (!empty($exercise_stat_info['exe_duration'])) {
$duration += $exercise_stat_info['exe_duration'];
}
$duration = (int) $duration;
} else {
if (!empty($exercise_stat_info['exe_duration'])) {
$duration = $exercise_stat_info['exe_duration'];
}
}
$key = ExerciseLib::get_time_control_key(
$exercise_id,
$exercise_stat_info['orig_lp_id'],
$exercise_stat_info['orig_lp_item_id']
);
$durationTime = Session::read('duration_time');
if (isset($durationTime[$key]) && !empty($durationTime[$key])) {
if ($debug) {
error_log('duration to save in DB:'.$duration);
error_log('Session time: '.$durationTime[$key]);
}
Session::write('duration_time', [$key => $now]);
Event::updateEventExercise(
$exeId,
$objExercise->selectId(),
$total_score,
$total_weight,
$session_id,
$exercise_stat_info['orig_lp_id'],
$exercise_stat_info['orig_lp_item_id'],
$exercise_stat_info['orig_lp_item_view_id'],
$duration,
$question_list,
'incomplete',
$remind_list
);
if (api_get_configuration_value('allow_time_per_question')) {
$questionStart = Session::read('question_start', []);
if (!empty($questionStart)) {
if (isset($questionStart[$my_question_id])) {
unset($questionStart[$my_question_id]);
}
array_filter($questionStart);
Session::write('question_start', $questionStart);
}
$duration = $now - $durationTime[$key];
if (!empty($exercise_stat_info['exe_duration'])) {
$duration += $exercise_stat_info['exe_duration'];
}
HookQuizQuestionAnswered::create()
->setEventData(
[
'exe_id' => (int) $exeId,
'quiz' => [
'id' => (int) $objExercise->id,
'title' => $objExercise->selectTitle(true),
],
'question' => [
'id' => (int) $my_question_id,
'weight' => (float) $result['weight'],
],
]
)
->notifyQuizQuestionAnswered();
// Destruction of the Question object
unset($objQuestionTmp);
if ($debug) {
error_log("---------- end question ------------");
$duration = (int) $duration;
} else {
if (!empty($exercise_stat_info['exe_duration'])) {
$duration = $exercise_stat_info['exe_duration'];
}
}
if ($debug) {
error_log('Finished questions loop in save_exercise_by_now');
error_log('duration to save in DB:'.$duration);
}
Session::write('duration_time', [$key => $now]);
Event::updateEventExercise(
$exeId,
$objExercise->selectId(),
$total_score,
$total_weight,
$session_id,
$exercise_stat_info['orig_lp_id'],
$exercise_stat_info['orig_lp_item_id'],
$exercise_stat_info['orig_lp_item_view_id'],
$duration,
$question_list,
'incomplete',
$remind_list
);
if (api_get_configuration_value('allow_time_per_question')) {
$questionStart = Session::read('question_start', []);
if (!empty($questionStart)) {
if (isset($questionStart[$my_question_id])) {
unset($questionStart[$my_question_id]);
}
array_filter($questionStart);
Session::write('question_start', $questionStart);
}
}
} else {
HookQuizQuestionAnswered::create()
->setEventData(
[
'exe_id' => (int) $exeId,
'quiz' => [
'id' => (int) $objExercise->id,
'title' => $objExercise->selectTitle(true),
],
'question' => [
'id' => (int) $my_question_id,
'weight' => (float) $result['weight'],
],
]
)
->notifyQuizQuestionAnswered();
// Destruction of the Question object
unset($objQuestionTmp);
if ($debug) {
error_log(
'Exercises attempt '.$exeId.': Failed saving question(s) in course/session '.
$course_id.'/'.$session_id.
': The user ('.
api_get_user_id().
') does not have the permission to access this session now');
error_log("---------- end question ------------");
}
echo 'error';
exit;
}
if ($debug) {
error_log('Finished questions loop in save_exercise_by_now');
}
if ($type === 'all') {
if ($debug) {

@ -1824,6 +1824,9 @@ ALTER TABLE gradebook_comment ADD CONSTRAINT FK_C3B70763AD3ED51C FOREIGN KEY (gr
// Add certificate footer. Add your template main/template/default/export/pdf_certificate_footer.tpl
// $_configuration['add_certificate_pdf_footer'] = true;
// Shows a popup with the list of answered/unanswered questions before sending a test.
// $_configuration['quiz_check_all_answers_before_end_test'] = true;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

Loading…
Cancel
Save