Skip to content

Commit

Permalink
Quiz: Add questions saved counter next to the "Finish test" button - …
Browse files Browse the repository at this point in the history
…refs BT#18451
  • Loading branch information
AngelFQC committed Mar 5, 2021
1 parent 2453318 commit 4fc5228
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 0 additions & 2 deletions app/Resources/public/css/base.css
Expand Up @@ -2795,8 +2795,6 @@ div.admin_section h4 {
}

.exercise_save_now_button img {
position: relative;
top: 4px;
}

.exercise_save_now_button {
Expand Down
11 changes: 6 additions & 5 deletions main/exercise/exercise_submit.php
Expand Up @@ -1458,13 +1458,13 @@ function save_now(question_id, url_extra) {
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=save_exercise_by_now",
data: dataparam,
success: function(return_value) {
if (return_value == "ok") {
if (return_value.ok) {
$("#save_for_now_"+question_id).html(\''.
Display::return_icon('save.png', get_lang('Saved'), [], ICON_SIZE_SMALL).'\');
} else if (return_value == "error") {
} else if (return_value.error) {
$("#save_for_now_"+question_id).html(\''.
Display::return_icon('error.png', get_lang('Error'), [], ICON_SIZE_SMALL).'\');
} else if (return_value == "one_per_page") {
} else if (return_value.type == "one_per_page") {
var url = "";
if ('.$reminder.' == 1 ) {
url = "exercise_reminder.php?'.$params.'&num='.$current_question.'";
Expand All @@ -1486,7 +1486,7 @@ function save_now(question_id, url_extra) {
}
$("#save_for_now_"+question_id).html(\''.
Display::return_icon('save.png', get_lang('Saved'), [], ICON_SIZE_SMALL).'\');
Display::return_icon('save.png', get_lang('Saved'), [], ICON_SIZE_SMALL).'\' + return_value.savedAnswerMessage);
// Show popup
if ("check_answers" === url_extra) {
Expand Down Expand Up @@ -1580,8 +1580,9 @@ function save_now_all(validate) {
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=save_exercise_by_now",
data: requestData,
success: function(return_value) {
if (return_value == "ok") {
if (return_value.ok) {
if (validate == "validate") {
$("#save_all_response").html(return_value.savedAnswerMessage);
window.location = "'.$script_php.'?'.$params.'";
} else {
$("#save_all_response").html(\''.Display::return_icon('accept.png').'\');
Expand Down
37 changes: 27 additions & 10 deletions main/inc/ajax/exercise.ajax.php
Expand Up @@ -418,12 +418,14 @@
echo $objExercise->getReminderTable($questionList, $statInfo, true);
break;
case 'save_exercise_by_now':
header('Content-Type: application/json');

$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 (false === api_is_allowed_to_session_edit()) {
echo 'error';
echo json_encode(['error' => true]);
if ($debug) {
error_log(
'Exercises attempt '.$exeId.': Failed saving question(s) in course/session '.
Expand Down Expand Up @@ -472,7 +474,7 @@

// If exercise or question is not set then exit.
if (empty($question_list) || empty($objExercise)) {
echo 'error';
echo json_encode(['error' => true]);
if ($debug) {
if (empty($question_list)) {
error_log("question_list is empty");
Expand All @@ -486,11 +488,11 @@

if (WhispeakAuthPlugin::questionRequireAuthentify($question_id)) {
if ($objExercise->type == ONE_PER_PAGE) {
echo 'one_per_page';
echo json_encode(['type' => 'one_per_page']);
break;
}

echo 'ok';
echo json_encode(['ok' => true]);
break;
} else {
ChamiloSession::erase(WhispeakAuthPlugin::SESSION_QUIZ_QUESTION);
Expand All @@ -512,7 +514,7 @@
// No exe id? Can't save answer.
if (empty($exeId)) {
// Fires an error.
echo 'error';
echo json_encode(['error' => true]);
if ($debug) {
error_log('exe_id is empty');
}
Expand Down Expand Up @@ -574,7 +576,7 @@
' for track_e_exercises.exe_id = '.$exeId.
', we received an empty set of answers.'.
'Preventing submission to avoid overwriting w/ null.');
echo 'error';
echo json_encode(['error' => true]);
exit;
}
}
Expand Down Expand Up @@ -639,7 +641,7 @@
if (!empty($value) && isset($value['value']) && !empty($value['value'])) {
$questionDuration = Event::getAttemptQuestionDuration($exeId, $objQuestionTmp->iid);
if (empty($questionDuration)) {
echo 'error';
echo json_encode(['error' => true]);
if ($debug) {
error_log("Question duration = 0, in exeId: $exeId, question_id: $my_question_id");
}
Expand Down Expand Up @@ -809,12 +811,27 @@
error_log('Finished questions loop in save_exercise_by_now');
}

$questionsCount = count(explode(',', $exercise_stat_info['data_tracking']));
$savedAnswersCount = $objExercise->countUserAnswersSavedInExercise($exeId);

if ($savedAnswersCount !== $questionsCount) {
$savedQuestionsMessage = Display::span(
sprintf(get_lang('XAnswersSavedByUsersFromXTotal'), $savedAnswersCount, $questionsCount),
['class' => 'text-warning']
);
} else {
$savedQuestionsMessage = Display::span(
sprintf(get_lang('XAnswersSavedByUsersFromXTotal'), $savedAnswersCount, $questionsCount),
['class' => 'text-success']
);
}

if ($type === 'all') {
if ($debug) {
error_log("result: ok - all");
error_log(" ------ end ajax call ------- ");
}
echo 'ok';
echo json_encode(['ok' => true, 'savedAnswerMessage' => $savedQuestionsMessage]);
exit;
}

Expand All @@ -823,14 +840,14 @@
error_log("result: one_per_page");
error_log(" ------ end ajax call ------- ");
}
echo 'one_per_page';
echo json_encode(['type' => 'one_per_page', 'savedAnswerMessage' => $savedQuestionsMessage]);
exit;
}
if ($debug) {
error_log("result: ok");
error_log(" ------ end ajax call ------- ");
}
echo 'ok';
echo json_encode(['ok' => true, 'savedAnswerMessage' => $savedQuestionsMessage]);
break;
case 'show_question':
$isAllowedToEdit = api_is_allowed_to_edit(null, true, false, false);
Expand Down

0 comments on commit 4fc5228

Please sign in to comment.