diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php index 284cc199bb..3bbc8ccab1 100755 --- a/main/exercice/answer.class.php +++ b/main/exercice/answer.class.php @@ -71,7 +71,6 @@ class Answer $objExercise = new Exercise($this->course_id); $exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null; $objExercise->read($exerciseId); - if ($objExercise->random_answers == '1') { $this->readOrderedBy('rand()', '');// randomize answers } else { diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index d223b2e82a..b3a9bf72dd 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1,6 +1,8 @@ display_category_name = $object->display_category_name; $this->pass_percentage = $object->pass_percentage; $this->sessionId = $object->session_id; - $this->is_gradebook_locked = api_resource_is_locked_by_gradebook($id, LINK_EXERCISE); - $this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false; $this->globalCategoryId = isset($object->global_category_id) ? $object->global_category_id : null; $this->questionSelectionType = isset($object->question_selection_type) ? $object->question_selection_type : null; @@ -190,10 +190,10 @@ class Exercise } if ($object->end_time != '0000-00-00 00:00:00') { - $this->end_time = $object->end_time; + $this->end_time = $object->end_time; } if ($object->start_time != '0000-00-00 00:00:00') { - $this->start_time = $object->start_time; + $this->start_time = $object->start_time; } //control time @@ -3757,7 +3757,16 @@ class Exercise } break; case CALCULATED_ANSWER: - $answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]); + $calculatedAnswerId = Session::read('calculatedAnswerId'); + $answer = ''; + if ($calculatedAnswerId) { + $calculatedAnswerInfo = Session::read('calculatedAnswerInfo'); + if (isset($calculatedAnswerInfo[$questionId])) { + $answer = $calculatedAnswerInfo[$questionId]; + } else { + $answer = $objAnswerTmp->selectAnswer($calculatedAnswerId[$questionId]); + } + } $preArray = explode('@@', $answer); $last = count($preArray) - 1; $answer = ''; @@ -3823,6 +3832,16 @@ class Exercise } $answer = ''; $realCorrectTags = $correctTags; + + if ($from_database && empty($calculatedAnswerId)) { + $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." + WHERE + exe_id = '".$exeId."' AND + question_id= ".intval($questionId).""; + $resfill = Database::query($queryfill); + $answer = Database::result($resfill, 0, 'answer'); + } + for ($i = 0; $i < count($realCorrectTags); $i++) { if ($i == 0) { $answer .= $realText[0]; diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index 0c068613d9..d37aba233b 100755 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -165,7 +165,6 @@ ExerciseLib::exercise_time_control_delete( $learnpath_id, $learnpath_item_id ); - ExerciseLib::delete_chat_exercise_session($exe_id); if ($origin != 'learnpath') { @@ -180,6 +179,8 @@ if ($origin != 'learnpath') { if (api_is_allowed_to_session_edit()) { Session::erase('objExercise'); Session::erase('exe_id'); + Session::erase('calculatedAnswerId'); + Session::erase('calculatedAnswerInfo'); } Display::display_footer(); } else { @@ -190,6 +191,8 @@ if ($origin != 'learnpath') { if (api_is_allowed_to_session_edit()) { Session::erase('objExercise'); Session::erase('exe_id'); + Session::erase('calculatedAnswerId'); + Session::erase('calculatedAnswerInfo'); } // Record the results in the learning path, using the SCORM interface (API) diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index bd929c4bb4..6db1c27e3e 100755 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -1,6 +1,8 @@ "exercise.php?".api_get_cidreq(),"name" => get_lang('Exercises')); $interbreadcrumb[]= array("url" => "overview.php?exerciseId=".$exercise_id.'&'.api_get_cidreq(),"name" => $objExercise->name); -$interbreadcrumb[]= array("url" => "#","name" => get_lang('Result')); +$interbreadcrumb[]= array("url" => "#", "name" => get_lang('Result')); $this_section = SECTION_COURSES; @@ -300,7 +300,6 @@ foreach ($questionList as $questionId) { $counter = 1; $exercise_content = null; $category_list = array(); - $useAdvancedEditor = true; if (!empty($maxEditors) && count($questionList) > $maxEditors) { @@ -313,10 +312,10 @@ foreach ($questionList as $questionId) { // destruction of the Question object unset($objQuestionTmp); - // creates a temporary Question object - $objQuestionTmp = Question::read($questionId); - $questionWeighting = $objQuestionTmp->selectWeighting(); - $answerType = $objQuestionTmp->selectType(); + // creates a temporary Question object + $objQuestionTmp = Question::read($questionId); + $questionWeighting = $objQuestionTmp->selectWeighting(); + $answerType = $objQuestionTmp->selectType(); // Start buffer ob_start(); @@ -383,6 +382,20 @@ foreach ($questionList as $questionId) { ); $questionScore = $question_result['score']; $totalScore += $question_result['score']; + } elseif ($answerType == CALCULATED_ANSWER) { + $question_result = $objExercise->manage_answer( + $id, + $questionId, + $choice, + 'exercise_show', + array(), + false, + true, + $show_results, + $objExercise->selectPropagateNeg() + ); + $questionScore = $question_result['score']; + $totalScore += $question_result['score']; } elseif ($answerType == GLOBAL_MULTIPLE_ANSWER) { $question_result = $objExercise->manage_answer( $id, @@ -610,7 +623,8 @@ foreach ($questionList as $questionId) { } //showing the score - $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." WHERE exe_id = ".intval($id)." and question_id= ".intval($questionId).""; + $queryfree = "SELECT marks FROM ".$TBL_TRACK_ATTEMPT." + WHERE exe_id = ".intval($id)." and question_id= ".intval($questionId).""; $resfree = Database::query($queryfree); $questionScore= Database::result($resfree,0,"marks"); $totalScore+=$questionScore; @@ -675,7 +689,13 @@ foreach ($questionList as $questionId) { } } echo '
'; - echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick'=>"showfck('".$name."', '".$marksname."');")); + echo Display::url( + $url_name, + 'javascript://', + array( + 'class' => 'btn btn-default', + 'onclick' => "showfck('".$name."', '".$marksname."');") + ); echo '
'; echo '
'; @@ -804,9 +824,9 @@ foreach ($questionList as $questionId) { $score = array(); if ($show_results) { $score['result'] = get_lang('Score')." : ".ExerciseLib::show_score($my_total_score, $my_total_weight, false, false); - $score['pass'] = $my_total_score >= $my_total_weight ? true : false; - $score['type'] = $answerType; - $score['score'] = $my_total_score; + $score['pass'] = $my_total_score >= $my_total_weight ? true : false; + $score['type'] = $answerType; + $score['score'] = $my_total_score; $score['weight'] = $my_total_weight; $score['comments'] = isset($comnt) ? $comnt : null; } @@ -815,11 +835,9 @@ foreach ($questionList as $questionId) { $i++; $contents = ob_get_clean(); - $question_content = '
'; - if ($show_results) { - //Shows question title an description + // Shows question title an description $question_content .= $objQuestionTmp->return_header(null, $counter, $score); } $counter++; diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index 3b23af281e..383d99c077 100755 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -351,8 +351,7 @@ switch ($action) { continue; } - $my_choice = isset($choice[$my_question_id]) ? - $choice[$my_question_id] : null; + $my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null; if ($debug) { error_log("my_choice = ".print_r($my_choice, 1).""); @@ -362,7 +361,7 @@ switch ($action) { $objQuestionTmp = Question::read($my_question_id, $course_id); // Getting free choice data. - if ($objQuestionTmp->type == FREE_ANSWER && $type == 'all') { + if ($objQuestionTmp->type == FREE_ANSWER && $type == 'all') { $my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id]) ? $_REQUEST['free_choice'][$my_question_id]: null; } diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 241b35d1ce..58ff05b08e 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -622,17 +622,20 @@ class ExerciseLib * the text to find mustn't contains HTML tags * the text to find mustn't contains char " */ - if ($origin !== null) { - global $exe_id; - $trackAttempts = Database::get_main_table( - TABLE_STATISTIC_TRACK_E_ATTEMPT - ); - $sql = 'SELECT answer FROM ' . $trackAttempts . ' - WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId; - $rsLastAttempt = Database::query($sql); - $rowLastAttempt = Database::fetch_array($rsLastAttempt); - $answer = $rowLastAttempt['answer']; - if (empty($answer)) { + global $exe_id; + $trackAttempts = Database::get_main_table( + TABLE_STATISTIC_TRACK_E_ATTEMPT + ); + $sql = 'SELECT answer FROM ' . $trackAttempts . ' + WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId; + $rsLastAttempt = Database::query($sql); + $rowLastAttempt = Database::fetch_array($rsLastAttempt); + $answer = $rowLastAttempt['answer']; + + $calculatedAnswerId = Session::read('calculatedAnswerId'); + $calculatedAnswerInfo = Session::read('calculatedAnswerInfo'); + if (empty($answer)) { + if (empty($calculatedAnswerId)) { $_SESSION['calculatedAnswerId'][$questionId] = mt_rand( 1, $nbrAnswers @@ -640,6 +643,14 @@ class ExerciseLib $answer = $objAnswerTmp->selectAnswer( $_SESSION['calculatedAnswerId'][$questionId] ); + + Session::write('calculatedAnswerInfo', [$questionId => $answer]); + + } else { + $calculatedAnswerInfo = Session::read('calculatedAnswerInfo'); + if (isset($calculatedAnswerInfo[$questionId])) { + $answer = $calculatedAnswerInfo[$questionId]; + } } } @@ -651,6 +662,7 @@ class ExerciseLib $correctAnswerList ); + // get student answer to display it if student go back to previous calculated answer question in a test if (isset($user_choice[0]['answer'])) { api_preg_match_all(