Browse Source

Revert "Fix CALCULATED_ANSWER see #8237"

This reverts commit 8104fe7279f37039507985fdfdaba56455d70b03.
Angel Fernando Quiroz Campos 8 years ago
parent
commit
a82e76b766

+ 1 - 0
main/exercice/answer.class.php

@@ -72,6 +72,7 @@ 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 {

+ 5 - 25
main/exercice/exercise.class.php

@@ -1,8 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-use ChamiloSession as Session;
-
 /**
  * Class Exercise
  *
@@ -164,7 +162,9 @@ class Exercise
             $this->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
@@ -3746,16 +3746,7 @@ class Exercise
                     }
                     break;
                 case CALCULATED_ANSWER:
-                    $calculatedAnswerId = Session::read('calculatedAnswerId');
-                    $answer = '';
-                    if ($calculatedAnswerId) {
-                        $calculatedAnswerInfo = Session::read('calculatedAnswerInfo');
-                        if (isset($calculatedAnswerInfo[$questionId])) {
-                            $answer = $calculatedAnswerInfo[$questionId];
-                        } else {
-                            $answer = $objAnswerTmp->selectAnswer($calculatedAnswerId[$questionId]);
-                        }
-                    }
+                    $answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]);
                     $preArray = explode('@@', $answer);
                     $last = count($preArray) - 1;
                     $answer = '';
@@ -3821,16 +3812,6 @@ 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];
@@ -4603,7 +4584,6 @@ class Exercise
                                 $answer,
                                 $studentChoice,
                                 $answerComment,
-                                $results_disabled
                                 $results_disabled,
                                 $answerId
                             );

+ 1 - 4
main/exercice/exercise_result.php

@@ -165,6 +165,7 @@ ExerciseLib::exercise_time_control_delete(
     $learnpath_id,
     $learnpath_item_id
 );
+
 ExerciseLib::delete_chat_exercise_session($exe_id);
 
 if ($origin != 'learnpath') {
@@ -179,8 +180,6 @@ 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 {
@@ -191,8 +190,6 @@ 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)

+ 27 - 47
main/exercice/exercise_show.php

@@ -1,8 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-use ChamiloSession as Session;
-
 /**
  *  Shows the exercise results
  *
@@ -14,6 +12,8 @@ use ChamiloSession as Session;
  *
  */
 
+use ChamiloSession as Session;
+
 require_once '../inc/global.inc.php';
 $debug = false;
 if (empty($origin) ) {
@@ -27,10 +27,10 @@ if ($origin == 'learnpath') {
 }
 
 // Database table definitions
-$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
-$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
-$TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
-$TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
+$TBL_EXERCISE_QUESTION 	= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+$TBL_QUESTIONS         	= Database::get_course_table(TABLE_QUIZ_QUESTION);
+$TBL_TRACK_EXERCISES    = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
+$TBL_TRACK_ATTEMPT		= Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
 
 // General parameters passed via POST/GET
 if ($debug) { error_log('Entered exercise_result.php: '.print_r($_POST,1)); }
@@ -77,13 +77,13 @@ if (empty($track_exercise_info)) {
     api_not_allowed(true);
 }
 
-$exercise_id = $track_exercise_info['id'];
-$exercise_date = $track_exercise_info['start_date'];
-$student_id = $track_exercise_info['exe_user_id'];
-$learnpath_id = $track_exercise_info['orig_lp_id'];
-$learnpath_item_id = $track_exercise_info['orig_lp_item_id'];
-$lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
-$current_user_id = api_get_user_id();
+$exercise_id        = $track_exercise_info['id'];
+$exercise_date      = $track_exercise_info['start_date'];
+$student_id         = $track_exercise_info['exe_user_id'];
+$learnpath_id       = $track_exercise_info['orig_lp_id'];
+$learnpath_item_id  = $track_exercise_info['orig_lp_item_id'];
+$lp_item_view_id    = $track_exercise_info['orig_lp_item_view_id'];
+$current_user_id    = api_get_user_id();
 
 if (api_is_excluded_user_type(true, $student_id)) {
     api_not_allowed(true);
@@ -116,7 +116,7 @@ $fromlink = '';
 
 $interbreadcrumb[]= array("url" => "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;
 
@@ -322,6 +322,7 @@ foreach ($questionList as $questionId) {
 $counter = 1;
 $exercise_content = null;
 $category_list = array();
+
 $useAdvancedEditor = true;
 
 if (!empty($maxEditors) && count($questionList) > $maxEditors) {
@@ -334,10 +335,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();
@@ -410,22 +411,6 @@ 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(),
-            [],
-            $showTotalScoreAndUserChoices
-        );
-        $questionScore = $question_result['score'];
-        $totalScore += $question_result['score'];
     } elseif ($answerType == GLOBAL_MULTIPLE_ANSWER) {
         $question_result = $objExercise->manage_answer(
             $id,
@@ -665,8 +650,7 @@ 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;
@@ -731,13 +715,7 @@ foreach ($questionList as $questionId) {
 				}
 			}
             echo '<br />';
-            echo Display::url(
-                $url_name,
-                'javascript://',
-                array(
-                    'class' => 'btn btn-default',
-                    'onclick' => "showfck('".$name."', '".$marksname."');")
-            );
+            echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick'=>"showfck('".$name."', '".$marksname."');"));
 			echo '<br />';
 
             echo '<div id="feedback_'.$name.'" style="width:100%">';
@@ -866,9 +844,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;
     }
@@ -877,9 +855,11 @@ foreach ($questionList as $questionId) {
 	$i++;
 
     $contents = ob_get_clean();
+
     $question_content = '<div class="question_row">';
+
  	if ($show_results) {
-        // Shows question title an description
+        //Shows question title an description
 	    $question_content .= $objQuestionTmp->return_header(null, $counter, $score);
 	}
 	$counter++;

+ 3 - 2
main/inc/ajax/exercise.ajax.php

@@ -351,7 +351,8 @@ 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)."");
@@ -361,7 +362,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;
                 }
 

+ 11 - 23
main/inc/lib/exercise.lib.php

@@ -622,20 +622,17 @@ class ExerciseLib
                      * the text to find mustn't contains HTML tags
                      * the text to find mustn't contains char "
                      */
-                    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)) {
+                    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)) {
                             $_SESSION['calculatedAnswerId'][$questionId] = mt_rand(
                                 1,
                                 $nbrAnswers
@@ -643,14 +640,6 @@ 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];
-                            }
                         }
                     }
 
@@ -662,7 +651,6 @@ 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(