Fix question list order when using remember and random questions

See BT#13664
pull/2487/head
jmontoyaa 7 years ago
parent 658e223aca
commit d0965e0ef2
  1. 2
      main/exercise/admin.php
  2. 15
      main/exercise/answer.class.php
  3. 5
      main/exercise/exercise.class.php
  4. 6
      main/exercise/exercise_reminder.php
  5. 57
      main/exercise/exercise_submit.php
  6. 2
      main/inc/ajax/exercise.ajax.php
  7. 8
      main/inc/lib/exercise.lib.php

@ -446,6 +446,7 @@ if ($newQuestion || $editQuestion) {
echo '<div class="main-question">';
echo Display::div($objQuestion->selectTitle(), array('class' => 'question_title'));
ExerciseLib::showQuestion(
$objExercise,
$editQuestion,
false,
null,
@ -454,7 +455,6 @@ if ($newQuestion || $editQuestion) {
true,
false,
true,
$objExercise->feedback_type,
true
);
echo '</div>';

@ -48,8 +48,9 @@ class Answer
* @author Olivier Brouckaert
* @param int $questionId that answers belong to
* @param int $course_id
* @param Exercise $exercise
*/
public function __construct($questionId, $course_id = null)
public function __construct($questionId, $course_id = null, $exercise = null)
{
$this->questionId = intval($questionId);
$this->answer = array();
@ -72,10 +73,14 @@ class Answer
$this->course = $courseInfo;
$this->course_id = $courseInfo['real_id'];
// fills arrays
$objExercise = new Exercise($this->course_id);
$exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null;
$objExercise->read($exerciseId);
if (empty($exercise)) {
// fills arrays
$objExercise = new Exercise($this->course_id);
$exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null;
$objExercise->read($exerciseId);
} else {
$objExercise = $exercise;
}
if ($objExercise->random_answers == '1' && $this->getQuestionType() != CALCULATED_ANSWER) {
$this->readOrderedBy('rand()', ''); // randomize answers

@ -145,6 +145,7 @@ class Exercise
if (empty($this->course_id)) {
return false;
}
$sql = "SELECT * FROM $table
WHERE c_id = ".$this->course_id." AND id = ".$id;
$result = Database::query($sql);
@ -222,7 +223,7 @@ class Exercise
// Checking if question_order is correctly set
if ($parseQuestionList) {
$this->setQuestionList(true);
$this->setQuestionList(true, $checkCurrentUserQuestionList);
}
//overload questions list with recorded questions list
@ -6507,9 +6508,7 @@ class Exercise
{
// Getting question list.
$questionList = $this->selectQuestionList(true, $adminView);
$this->setMediaList($questionList);
$this->questionList = $this->transformQuestionListWithMedias(
$questionList,
false

@ -16,12 +16,6 @@ $this_section = SECTION_COURSES;
/* ACCESS RIGHTS */
// notice for unauthorized people.
api_protect_course_script(true);
if ($debug > 0) {
error_log('Entered exercise_result.php: '.print_r($_POST, 1));
}
// general parameters passed via POST/GET
$origin = api_get_origin();
if (empty($learnpath_id)) {

@ -36,7 +36,6 @@ $debug = false;
// Notice for unauthorized people.
api_protect_course_script(true);
$origin = api_get_origin();
$is_allowedToEdit = api_is_allowed_to_edit(null, true);
$glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
@ -81,11 +80,9 @@ $learnpath_item_view_id = isset($_REQUEST['learnpath_item_view_id']) ? intval($_
$reminder = isset($_REQUEST['reminder']) ? intval($_REQUEST['reminder']) : 0;
$remind_question_id = isset($_REQUEST['remind_question_id']) ? intval($_REQUEST['remind_question_id']) : 0;
$exerciseId = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
$formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null;
$exerciseResult = isset($_REQUEST['exerciseResult']) ? $_REQUEST['exerciseResult'] : null;
$exerciseResultCoordinates = isset($_REQUEST['exerciseResultCoordinates']) ? $_REQUEST['exerciseResultCoordinates'] : null;
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;
$choice = empty($choice) ? isset($_REQUEST['choice2']) ? $_REQUEST['choice2'] : null : null;
@ -97,7 +94,6 @@ $endExercise = isset($_REQUEST['end_exercise']) && $_REQUEST['end_exercise'] ==
// Error message
$error = '';
//Table calls
$exercise_attempt_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
/* Teacher takes an exam and want to see a preview,
@ -110,7 +106,6 @@ if (api_is_allowed_to_edit(null, true) &&
}
// 1. Loading the $objExercise variable
/** @var \Exercise $exerciseInSession */
$exerciseInSession = Session::read('objExercise');
if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSession->id != $_GET['exerciseId'])) {
@ -299,15 +294,15 @@ if ($objExercise->selectAttempts() > 0) {
}
if ($origin == 'learnpath') {
Display :: display_reduced_header();
Display::display_reduced_header();
} else {
Display :: display_header(get_lang('Exercises'));
Display::display_header(get_lang('Exercises'));
}
echo $attempt_html;
if ($origin != 'learnpath') {
Display:: display_footer();
Display::display_footer();
}
exit;
}
@ -324,7 +319,6 @@ $exercise_stat_info = $objExercise->get_stat_track_exercise_info(
// Fix in order to get the correct question list.
$questionListUncompressed = $objExercise->getQuestionListWithMediasUncompressed();
Session::write('question_list_uncompressed', $questionListUncompressed);
$clock_expired_time = null;
if (empty($exercise_stat_info)) {
if ($debug) {
@ -425,16 +419,19 @@ if (!isset($questionListInSession)) {
// Media questions.
$media_is_activated = $objExercise->mediaIsActivated();
//Getting order from random
// Getting order from random
if ($media_is_activated == false &&
$objExercise->isRandom() &&
(
$objExercise->isRandom() ||
!empty($objExercise->selectRandomByCat()) ||
$objExercise->getQuestionSelectionType() > 2
) &&
isset($exercise_stat_info) &&
!empty($exercise_stat_info['data_tracking'])
) {
$questionList = explode(',', $exercise_stat_info['data_tracking']);
}
Session::write('questionList', $questionList);
Session::write('questionList', $questionList);
if ($debug > 0) {
error_log('$_SESSION[questionList] was set');
@ -444,7 +441,6 @@ if (!isset($questionListInSession)) {
$questionList = Session::read('questionList');
}
}
// Array to check in order to block the chat
ExerciseLib::create_chat_exercise_session($exe_id);
@ -567,7 +563,7 @@ if (!isset($_SESSION['questionList'])) {
Session::write('questionList', $questionList);
} else {
if (isset($objExercise) && isset($_SESSION['objExercise'])) {
$questionList = $_SESSION['questionList'];
$questionList = Session::read('questionList');
}
}
@ -698,7 +694,9 @@ if ($formSent && isset($_POST)) {
header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
exit;
} else {
if ($debug) { error_log('10. Redirecting to exercise_show.php'); }
if ($debug) {
error_log('10. Redirecting to exercise_show.php');
}
header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
exit;
}
@ -708,9 +706,13 @@ if ($formSent && isset($_POST)) {
exit;
}
}
if ($debug) { error_log('11. $formSent was set - end'); }
if ($debug) {
error_log('11. $formSent was set - end');
}
} else {
if ($debug) { error_log('9. $formSent was NOT sent'); }
if ($debug) {
error_log('9. $formSent was NOT sent');
}
}
// If questionNum comes from POST and not from GET
@ -732,7 +734,9 @@ if ($question_count != 0) {
if (api_is_allowed_to_session_edit()) {
// goes to the script that will show the result of the exercise
if ($objExercise->type == ALL_ON_ONE_PAGE) {
if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
if ($debug) {
error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php');
}
//We check if the user attempts before sending to the exercise_result.php
if ($objExercise->selectAttempts() > 0) {
@ -769,7 +773,9 @@ if ($question_count != 0) {
}
}
} else {
if ($debug) { error_log('Redirecting to exercise_submit.php'); }
if ($debug) {
error_log('Redirecting to exercise_submit.php');
}
exit;
}
}
@ -914,13 +920,15 @@ if ($time_control) {
}
if ($origin != 'learnpath') {
echo '<div id="highlight-plugin" class="glossary-content">';
echo '<div id="highlight-plugin" class="glossary-content">';
}
if ($reminder == 2) {
if ($debug) { error_log(' $reminder == 2'); }
$data_tracking = $exercise_stat_info['data_tracking'];
$data_tracking = explode(',', $data_tracking);
if ($debug) {
error_log(' $reminder == 2');
}
$data_tracking = $exercise_stat_info['data_tracking'];
$data_tracking = explode(',', $data_tracking);
$current_question = 1; //set by default the 1st question
if (!empty($my_remind_list)) {
@ -1343,6 +1351,7 @@ if (!empty($error)) {
// Shows the question and its answers
ExerciseLib::showQuestion(
$objExercise,
$questionId,
false,
$origin,

@ -555,6 +555,7 @@ switch ($action) {
echo '<p class="lead">'.$objQuestion->get_question_type_name().'</p>';
ExerciseLib::showQuestion(
$objExercise,
$questionId,
false,
null,
@ -563,7 +564,6 @@ switch ($action) {
true,
false,
true,
$objExercise->feedback_type,
true
);
break;

@ -16,6 +16,7 @@ class ExerciseLib
/**
* Shows a question
*
* @param Exercise $exercise
* @param int $questionId $questionId question id
* @param bool $only_questions if true only show the questions, no exercise title
* @param bool $origin i.e = learnpath
@ -24,12 +25,12 @@ class ExerciseLib
* @param bool $freeze
* @param array $user_choice
* @param bool $show_comment
* @param null $exercise_feedback
* @param bool $show_answers
*
* @return bool|int
*/
public static function showQuestion(
$exercise,
$questionId,
$only_questions = false,
$origin = false,
@ -38,7 +39,6 @@ class ExerciseLib
$freeze = false,
$user_choice = array(),
$show_comment = false,
$exercise_feedback = null,
$show_answers = false
) {
$course_id = api_get_course_int_id();
@ -52,7 +52,7 @@ class ExerciseLib
return false;
}
if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
if ($exercise->feedback_type != EXERCISE_FEEDBACK_TYPE_END) {
$show_comment = false;
}
@ -99,7 +99,7 @@ class ExerciseLib
echo '<div class="question_options">';
// construction of the Answer object (also gets all answers details)
$objAnswerTmp = new Answer($questionId);
$objAnswerTmp = new Answer($questionId, api_get_course_int_id(), $exercise);
$nbrAnswers = $objAnswerTmp->selectNbrAnswers();
$quiz_question_options = Question::readQuestionOption(
$questionId,

Loading…
Cancel
Save