From 07e6e29db35c1fdabcf52345f5c818adb166bfc5 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 22 May 2013 18:08:36 +0200 Subject: [PATCH] Fixing question_list_flatten session array assignation --- main/exercice/exercise.class.php | 41 ++++++++++++----------- main/exercice/exercise_submit.php | 6 ++-- main/exercice/testcategory.class.php | 2 +- main/inc/ajax/exercise.ajax.php | 50 ++++++++++++++-------------- main/inc/lib/display.lib.php | 38 ++++++++++++++++++--- main/inc/lib/exercise.lib.php | 8 ++--- 6 files changed, 89 insertions(+), 56 deletions(-) diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 80b4f53ec8..b3f38b2c92 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -551,7 +551,6 @@ class Exercise ON (e.question_id= q.iid) WHERE e.exercice_id = '".Database::escape_string($this->id)."' ORDER BY question_order"; - //var_dump($sql); $result = Database::query($sql); // Fills the array with the question ID for this exercise @@ -3165,8 +3164,6 @@ class Exercise $i_answer_correct_answer = $objAnswerTmp->getAnswerIdFromList($i_answer_correct_answer); } - //var_dump($s_user_answer, $i_answer_correct_answer); - $user_answer = ''; if (!empty($s_user_answer)) { if ($s_user_answer == $i_answer_correct_answer) { @@ -3214,7 +3211,6 @@ class Exercise if ($answerType == MATCHING) { $answerCorrect = $objAnswerTmp->getAnswerIdFromList($answerCorrect); $matchingKey = $numAnswer; - //var_dump($answer_matching, $numAnswer); } if ($answerCorrect == $choice[$numAnswer]) { @@ -3875,7 +3871,6 @@ class Exercise //Fixes multiple answer question in order to be exact if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { - //var_dump($answer_correct_array, $real_answers); $diff = @array_diff($answer_correct_array, $real_answers); //var_dump($diff); /* @@ -3894,12 +3889,7 @@ class Exercise error_log("answer_correct_array: ".print_r($answer_correct_array, 1).""); error_log("real_answers: ".print_r($real_answers, 1).""); } - - /* if ($correct_answer == false) { - $questionScore = 0; - } */ - - //This makes the result non exact + // This makes the result non exact if (!empty($diff)) { //$questionScore = 0; } @@ -4613,7 +4603,8 @@ class Exercise function get_media_list() { $media_questions = array(); - $question_list = $this->get_validated_question_list(); + //$question_list = $this->get_validated_question_list(); + $question_list = $this->selectQuestionList(true); if (!empty($question_list)) { foreach ($question_list as $questionId) { @@ -4857,10 +4848,6 @@ class Exercise **/ public function transform_question_list_with_medias($question_list, $expand_media_questions = false) { - $questionFlatten = Session::read('question_list_flatten'); - if (!empty($questionFlatten)) { - return $questionFlatten; - } $new_question_list = array(); if (!empty($question_list)) { $media_questions = $this->get_media_list(); @@ -4898,7 +4885,6 @@ class Exercise $new_question_list = $question_list; } } - Session::write('question_list_flatten', $new_question_list); return $new_question_list; } @@ -5186,9 +5172,20 @@ class Exercise } + /** + * @param int $exe_id + * @param array $questionList + * @param array $my_remind_list + * @param int $reminder + * @param int $remind_question_id + * @param array $questionListFlatten + * @param array $mediaQuestions + * @param string $url + * @param int $current_question + * @return string + */ public function getProgressPagination($exe_id, $questionList, $my_remind_list, $reminder, $remind_question_id, $questionListFlatten, $mediaQuestions, $url, $current_question) { - $exercise_result = get_answered_questions_from_attempt($exe_id, $this); $fixedRemindList = array(); @@ -5214,6 +5211,7 @@ class Exercise $categoryList = Testcategory::getListOfCategoriesWithQuestionForTestObject($this, $questionListFlatten, $mediaQuestions); Session::write('categoryList', $categoryList); } + $html = '
'; $html .= '
'; @@ -5221,7 +5219,12 @@ class Exercise if ($this->review_answers) { $reviewAnswerLabel = Display::label(get_lang('ToReview'), 'warning').'
'; } - $html .= Display::label(get_lang('Answered'), 'success').'
'.Display::label(get_lang('Unanswered')).'
'.$reviewAnswerLabel.Display::label(get_lang('CurrentQuestion'), 'info'); + $currentAnswerLabel = null; + if (!empty($current_question)) { + $currentAnswerLabel = Display::label(get_lang('CurrentQuestion'), 'info'); + } + $html .= Display::label(get_lang('Answered'), 'success').'
'.Display::label(get_lang('Unanswered')).'
'. + $reviewAnswerLabel.$currentAnswerLabel; $html .= '
'; $conditions = array(); diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index 0fb5aabf6a..a8a5aea8f2 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -513,6 +513,7 @@ if (!isset($_SESSION['questionList'])) { //Fix in order to get the correct question list $questionListFlatten = $objExercise->transform_question_list_with_medias($questionList, true); +Session::write('question_list_flatten', $questionListFlatten); $clock_expired_time = null; if (empty($exercise_stat_info)) { @@ -545,7 +546,7 @@ if (empty($exercise_stat_info)) { if ($debug) error_log("5 exercise_stat_info[] exists getting exe_id: $exe_id "); } -//Array to check in order to block the chat +// Array to check in order to block the chat ExerciseLib::create_chat_exercise_session($exe_id); if ($debug) { error_log('6. $objExercise->get_stat_track_exercise_info function called:: '.print_r($exercise_stat_info, 1)); }; @@ -831,7 +832,6 @@ if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') { if (!empty ($gradebook) && $gradebook == 'view') { $interbreadcrumb[]= array ('url' => '../gradebook/' . Security::remove_XSS($_SESSION['gradebook_dest']),'name' => get_lang('ToolGradebook')); } - $interbreadcrumb[]= array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices')); $interbreadcrumb[]= array ("url" => "#","name" => $objExercise->name); @@ -1230,7 +1230,7 @@ if (!empty($error)) { '; - //Show list of questions + // Show list of questions. $attempt_list = array(); if (isset($exe_id)) { $attempt_list = get_all_exercise_event_by_exe_id($exe_id); diff --git a/main/exercice/testcategory.class.php b/main/exercice/testcategory.class.php index 1a0f4b3770..9354f2fec8 100644 --- a/main/exercice/testcategory.class.php +++ b/main/exercice/testcategory.class.php @@ -525,8 +525,8 @@ class Testcategory $newMediaList[$questionId] = $mediaId; } } + foreach ($questionList as $question_id) { - //var_dump($question_id); $categoryList = Testcategory::getCategoryForQuestion($question_id); foreach ($categoryList as $categoryId) { diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index 864b8e4e38..d052648d6f 100644 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -9,6 +9,8 @@ require_once '../../exercice/question.class.php'; require_once '../../exercice/answer.class.php'; require_once '../global.inc.php'; +use \ChamiloSession as Session; + api_protect_course_script(true); $action = $_REQUEST['a']; @@ -282,8 +284,7 @@ switch ($action) { // Question info. $question_id = intval($_REQUEST['question_id']); - - $question_list = $_SESSION['question_list_flatten']; + $question_list = Session::read('question_list_flatten'); // If exercise or question is not set then exit. if (empty($question_list) || empty($objExercise)) { @@ -316,7 +317,7 @@ switch ($action) { // Fixing reminder order $fixedRemindList = array(); if (!empty($bd_reminder_list)) { - foreach($question_list as $questionId) { + foreach ($question_list as $questionId) { if (in_array($questionId, $bd_reminder_list)) { $fixedRemindList[] = $questionId; } @@ -325,30 +326,29 @@ switch ($action) { $bd_reminder_list = $fixedRemindList; - if (empty($remind_list)) { - $remind_list = $bd_reminder_list; - - $new_list = array(); - 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; - } - } - } + if (empty($remind_list)) { + $remind_list = $bd_reminder_list; + $new_list = array(); + 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; + } + } + } - //No exe id? Can't save answer. + // No exe id? Can't save answer. if (empty($exe_id)) { - //Fires an error + // Fires an error. echo 'error'; exit; } else { @@ -367,7 +367,7 @@ switch ($action) { unset($objQuestionTmp); - //Looping the question list + // Looping the question list if ($debug) error_log("Looping question list".print_r($question_list, 1)); if ($debug) error_log("Trying to save question: $question_id "); diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 5ebb156cb8..2ce10e124d 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -1761,6 +1761,13 @@ class Display $defaultClass = "before"; + $affectAllItems = false; + if ($addLetters && $fixValue) { + if ($current == $fixValue) { + $affectAllItems = true; + } + } + foreach ($list as $item_id) { $class = $defaultClass; @@ -1791,8 +1798,22 @@ class Display } } - if ($current == $counter) { - $class = "before current"; + if ($addLetters && $fixValue) { + $current = $counter; + if ($affectAllItems) { + if ($current == $counter) { + //if ($class == $defaultClass) { + $class = "before current"; + //} + } + } else { + + } + } else { + // Default behaviour + if ($current == $counter) { + $class = "before current"; + } } if (empty($link)) { @@ -1843,6 +1864,7 @@ class Display $useLetters = false; $fixValue = null; + if ($mediaQuestionId != 999) { $useLetters = true; $fixValue = $counter; @@ -1852,7 +1874,15 @@ class Display $html .= '
'; $html .= '
'.$category['name'].'
'; $html .= '
'; - $html .= self::progress_pagination_bar($questionList, $current, $conditions, $link, $counter, $useLetters, $fixValue); + $html .= self::progress_pagination_bar( + $questionList, + $current, + $conditions, + $link, + $counter, + $useLetters, + $fixValue + ); $html .= '
'; $html .= '
'; @@ -1871,7 +1901,7 @@ class Display /** * @param int $current * @param int $total - * @return null + * @return string */ public static function paginationIndicator($current, $total) { diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 68bbe0e2e4..51a2f1ec4b 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -2578,7 +2578,7 @@ class ExerciseLib } } - //Medias question render + // Media question render if (isset($media_questions) && !empty($media_questions) && isset($media_questions[$questionId])) { $media_question_list = $media_questions[$questionId]; $objQuestionTmp = Question::read($questionId); @@ -2607,12 +2607,12 @@ class ExerciseLib $i++; } } else { - //Normal question render + // Normal question render. self::render_question($objExercise, $questionId, $attempt_list, $remind_list, $i, $current_question, null, null, $questionList, $current_question); $i++; } - // for sequential exercises + // For sequential exercises. if ($objExercise->type == ONE_PER_PAGE) { // quits the loop break; @@ -2661,7 +2661,7 @@ class ExerciseLib $remind_highlight = ' remind_highlight '; } - //Showing the question + // Showing the question $exercise_actions = null;