Skip to content

Commit

Permalink
Exercises: Allow review answers when block categories is turn on
Browse files Browse the repository at this point in the history
WIP see BT#17789
  • Loading branch information
jmontoyaa committed Jan 20, 2021
1 parent 1df59b6 commit 8d3c091
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
28 changes: 21 additions & 7 deletions main/exercise/exercise_question_reminder.php
Expand Up @@ -104,9 +104,9 @@
// I'm in a preview mode as course admin. Display the action menu.
if (!$hideHeaderAndFooter && api_is_course_admin()) {
echo '<div class="actions">';
echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.
echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->iId.'">'.
Display::return_icon('back.png', get_lang('GoBackToQuestionList'), [], 32).'</a>';
echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.
echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->iId.'">'.
Display::return_icon('edit.png', get_lang('ModifyExercise'), [], 32).'</a>';
echo '</div>';
}
Expand All @@ -116,12 +116,12 @@

$categoryList = Session::read('categoryList');
$disableAllQuestions = '';
$questionList = [];
if (isset($categoryList[$categoryId])) {
$questionList = $categoryList[$categoryId];
}
if ($objExercise->review_answers) {
$disableAllQuestions = 'changeOptionStatus(0);';
$questionList = [];
if (isset($categoryList[$categoryId])) {
$questionList = $categoryList[$categoryId];
}
echo $objExercise->getReminderTable($questionList, $trackInfo);
}

Expand All @@ -131,14 +131,28 @@

echo Display::div('', ['id' => 'message']);
$previousQuestion = $currentQuestion - 1;

$nextQuestion = $currentQuestion + 1;
if (!empty($questionList)) {
$firstQuestionOfCategory = end($questionList);
$dataTracking = explode(',', $trackInfo['data_tracking']);
$index = 0;
foreach ($dataTracking as $index => $question) {
if ($firstQuestionOfCategory == $question) {
break;
}
}
$nextQuestion = $index + 1;
}

echo '<script>
function goBack() {
window.location = "'.$url.'&num='.$previousQuestion.'";
}
function continueExercise() {
'.$disableAllQuestions.'
window.location = "'.$validateUrl.'&num='.$currentQuestion.'";
window.location = "'.$validateUrl.'&num='.$nextQuestion.'";
}
function final_submit() {
Expand Down
23 changes: 16 additions & 7 deletions main/exercise/exercise_submit.php
Expand Up @@ -432,6 +432,7 @@
$exe_id = $exercise_stat_info['exe_id'];
// Remember last question id position.
$isFirstTime = Session::read('firstTime');
//$isFirstTime = true;
if ($isFirstTime && ONE_PER_PAGE == $objExercise->type) {
$resolvedQuestions = Event::getAllExerciseEventByExeId($exe_id);
if (!empty($resolvedQuestions) &&
Expand All @@ -445,18 +446,22 @@
break;
}
$count++;
}*/
}
$current_question = $count;
*/
// Get current question based in data_tracking question list, instead of track_e_attempt order BT#17789.
$resolvedQuestionsQuestionIds = array_keys($resolvedQuestions);
$count = 0;
$attemptQuestionList = explode(',', $exercise_stat_info['data_tracking']);
foreach ($attemptQuestionList as $question) {
//var_dump($attemptQuestionList, $resolvedQuestionsQuestionIds);
foreach ($attemptQuestionList as $index => $question) {
if (in_array($question, $resolvedQuestionsQuestionIds)) {
++$count;
$count = $index;
continue;
}
}
$current_question = $count;
//var_dump($current_question, $index);exit;
}
}
}
Expand Down Expand Up @@ -665,7 +670,7 @@
}
$count++;
}

//var_dump($questionCheck);exit;
// Use reminder list to get the current question.
/*if (2 === $reminder && !empty($myRemindList)) {
$remindQuestionId = current($myRemindList);
Expand All @@ -680,17 +685,19 @@
if ($objExercise->review_answers && isset($_GET['category_id'])) {
$categoryId = $_GET['category_id'] ?? 0;
}
//var_dump($categoryId);
//var_dump($categoryId, $categoryList);
if (!empty($categoryId)) {
$categoryInfo = $categoryList[$categoryId];
$count = 1;
$total = count($categoryList[$categoryId]);
//var_dump($questionCheck);
foreach ($categoryList[$categoryId] as $checkQuestionId) {
if ((int) $checkQuestionId === (int) $questionCheck->iid) {
break;
}
$count++;
}

//var_dump($count , $total);
if ($count === $total) {
$isLastQuestionInCategory = $categoryId;
Expand All @@ -712,6 +719,7 @@
}
}
//var_dump($categoryId, $blockedCategories, $isLastQuestionInCategory);

// Blocked if category was already answered.
if ($categoryId && in_array($categoryId, $blockedCategories)) {
// Redirect to category intro.
Expand All @@ -720,6 +728,7 @@
api_location($url);
}
}
//exit;
//var_dump($isLastQuestionInCategory);
if ($debug) {
error_log('8. Question list loaded '.print_r($questionList, 1));
Expand All @@ -730,7 +739,7 @@
if (!empty($questionList)) {
$question_count = count($questionList);
}

//var_dump($current_question);
if ($current_question > $question_count) {
// If time control then don't change the current question, otherwise there will be a loop.
// @todo
Expand Down Expand Up @@ -1460,7 +1469,7 @@ function save_now(question_id, url_extra) {
// If last question in category send to exercise_question_reminder.php
if ('.$isLastQuestionInCategory.' > 0 ) {
url = "exercise_question_reminder.php?'.$params.'&num='.$current_question.'&category_id='.$isLastQuestionInCategory.'";
url = "exercise_question_reminder.php?'.$params.'&num='.($current_question-1).'&category_id='.$isLastQuestionInCategory.'";
}
if (url_extra) {
Expand Down
4 changes: 2 additions & 2 deletions main/inc/ajax/exercise.ajax.php
Expand Up @@ -562,7 +562,7 @@
}

// Getting free choice data.
if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION]) && $type === 'all') {
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;
Expand Down Expand Up @@ -616,7 +616,7 @@
}
}

// Deleting old 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");
Expand Down

0 comments on commit 8d3c091

Please sign in to comment.