Kaynağa Gözat

Fixing hotspot test in exercises and exercises + LP

Julio Montoya 14 yıl önce
ebeveyn
işleme
a215aa3d78

+ 14 - 22
main/exercice/exercice_submit.php

@@ -95,9 +95,6 @@ if (empty ($formSent)) {
 if (empty ($exerciseResult)) {
     $exerciseResult = $_REQUEST['exerciseResult'];
 }
-if (empty ($exerciseResultCoordinates)) {
-    $exerciseResultCoordinates = $_REQUEST['exerciseResultCoordinates'];
-}
 if (empty ($exerciseType)) {
     $exerciseType = $_REQUEST['exerciseType'];
 }
@@ -127,10 +124,9 @@ if ($buttonCancel) {
     header("Location: exercice.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
     exit;
 }
-if ($origin == 'builder') {
-    /*******************************/
-    /* Clears the exercise session */
-    /*******************************/
+
+if ($origin == 'builder') {    
+    /* Clears the exercise session */    
     if ($debug) {error_log('origin = builder'); };
     if (isset ($_SESSION['objExercise'])) {
         api_session_unregister('objExercise');
@@ -332,7 +328,7 @@ if ($formSent && isset($_POST)) {
     // Initializing
     if (!is_array($exerciseResult)) {
         $exerciseResult = array ();
-        $exerciseResultCoordinates = array ();
+        $exerciseResultCoordinates = array();
     }
 
     //Only for hotspot
@@ -340,23 +336,19 @@ if ($formSent && isset($_POST)) {
         $hotspot_id = (int)($_REQUEST['hidden_hotspot_id']);
         $choice = array($hotspot_id => '');
     }
-
     // if the user has answered at least one question
     if (is_array($choice)) {
-        if ($debug > 0) {if ($debug > 0) { error_log('$choice is an array'); } }		
+        if ($debug > 0) {if ($debug > 0) { error_log('$choice is an array'); } }	
+        // Also store hotspot spots in the session ($exerciseResultCoordinates
+        // will be stored in the session at the end of this script)
+
+        if (isset ($_POST['hotspot'])) {
+            $exerciseResultCoordinates = $_POST['hotspot'];               
+        }        	
         if ($exerciseType == ALL_ON_ONE_PAGE) {
             // $exerciseResult receives the content of the form.
             // Each choice of the student is stored into the array $choice
-            $exerciseResult = $choice;
-
-            // Also store hotspot spots in the session ($exerciseResultCoordinates
-            // will be stored in the session at the end of this script)
-            // The results will be stored by exercise_result.php if we are in
-            // an exercise of type 1 (=all on one page)
-            //This seems not useful
-            if (isset ($_POST['hotspot'])) {
-                $exerciseResultCoordinates = $_POST['hotspot'];
-            }
+            $exerciseResult = $choice;            
         } else {
             // gets the question ID from $choice. It is the key of the array
             list ($key) = array_keys($choice);
@@ -365,7 +357,7 @@ if ($formSent && isset($_POST)) {
                 // stores the user answer into the array
                 $exerciseResult[$key] = $choice[$key];
                 //saving each question
-                if ($_configuration['live_exercise_tracking'] && $exerciseType == ONE_PER_PAGE && $objExercise->feedbacktype != EXERCISE_FEEDBACK_TYPE_DIRECT) {
+                if ($_configuration['live_exercise_tracking'] && $objExercise->feedbacktype != EXERCISE_FEEDBACK_TYPE_DIRECT) {
                     $nro_question = $questionNum; // - 1;
                     //START of saving and qualifying each question submitted
                     define('ENABLED_LIVE_EXERCISE_TRACKING', 1);
@@ -374,7 +366,7 @@ if ($formSent && isset($_POST)) {
                     $choice = $exerciseResult[$questionId];                    
                     if (isset($exe_id)) {
                     	//Manage the question and answer attempts
-                    	$objExercise->manage_answer($exe_id, $questionId, $choice,'exercise_show', true, false,false);
+                    	$objExercise->manage_answer($exe_id, $questionId, $choice,'exercise_show',$exerciseResultCoordinates, true, false,false);
                     }
                     //END of saving and qualifying
                 }

+ 6 - 6
main/exercice/exercise.class.php

@@ -1638,14 +1638,18 @@ class Exercise {
      * @param   int     exe id
      * @param   int     question id
      * @param   int     the choice the user selected
+     * @param   array   the hotspot coordinates $hotspot[$question_id] = coordinates
      * @param   string  function is called from 'exercise_show' or 'exercise_result'
      * @param   bool    save results in the DB or just show the reponse
      * @param   bool    gets information from DB or from the current selection
      * @param   bool    show results or not
+     * @todo    reduce parameters of this function
      * @return  string  html code
 	 */
-	function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $saved_results = true, $from_database = false, $show_result = true) {        
+	function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true) {        
 		global $_configuration;
+        error_log('manage_answer');
+        error_log('$exerciseResultCoordinates'.print_r($exerciseResultCoordinates,1));
         $questionId   = intval($questionId);
 		$exeId        = intval($exeId);        
         $TBL_TRACK_ATTEMPT      = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
@@ -1666,10 +1670,6 @@ class Exercise {
         // Destruction of the Question object
         unset ($objQuestionTmp);
         
-        if (isset($_SESSION['exerciseResultCoordinates'])) {
-            $exerciseResultCoordinates = $_SESSION['exerciseResultCoordinates'];
-        }
-
         // Construction of the Answer object
         $objAnswerTmp = new Answer($questionId);
         $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
@@ -2262,7 +2262,7 @@ class Exercise {
             } elseif ($answerType == HOT_SPOT) {                
                 exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
                 
-                if (is_array($exerciseResultCoordinates[$questionId])) {
+                if (isset($exerciseResultCoordinates[$questionId]) && !empty($exerciseResultCoordinates[$questionId])) {
                     foreach($exerciseResultCoordinates[$questionId] as $idx => $val) {
                         exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val,$this->id);
                     }

+ 2 - 1
main/exercice/exercise_result.php

@@ -69,6 +69,7 @@ if ( empty ( $learnpath_item_view_id ) ) {  $learnpath_item_view_id = intval($_R
 if ( empty ( $formSent ) ) {                $formSent               = $_REQUEST['formSent'];}
 if ( empty ( $exerciseResult ) ) {          $exerciseResult         = $_SESSION['exerciseResult'];}
 if ( empty ( $exerciseResultCoordinates)){  $exerciseResultCoordinates = $_SESSION['exerciseResultCoordinates'];}
+
 if ( empty ( $questionId ) ) {              $questionId             = $_REQUEST['questionId'];}
 if ( empty ( $choice ) ) {                  $choice                 = $_REQUEST['choice'];}
 if ( empty ( $questionNum ) ) {             $questionNum            = $_REQUEST['questionNum'];}
@@ -301,7 +302,7 @@ foreach ($questionList as $questionId) {
 	}
 
 	// We're inside *one* question. Go through each possible answer for this question
-	$result = $objExercise->manage_answer($exeId, $questionId, $choice,'exercise_result');    
+	$result = $objExercise->manage_answer($exeId, $questionId, $choice,'exercise_result', $exerciseResultCoordinates, true);    
     $totalScore        += $result['score'];
     $totalWeighting    += $result['weight'];
     

+ 7 - 7
main/exercice/exercise_show.php

@@ -367,7 +367,7 @@ if ($show_results) {
 			<?php
 			// construction of the Answer object
        
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
             //var_dump($question_result);
             $questionScore  = $question_result['score'];
             $totalScore     += $question_result['score'];
@@ -390,7 +390,7 @@ if ($show_results) {
 			</tr>
 			<?php
 	            
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
 
@@ -416,7 +416,7 @@ if ($show_results) {
 				</tr>
 			<?php	
             
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];  
 			echo '</table>';
@@ -435,7 +435,7 @@ if ($show_results) {
 			</tr>
 			<?php
                       
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
               
@@ -456,12 +456,12 @@ if ($show_results) {
 
 			<?php
 			
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
 
 		} elseif ($answerType == MATCHING) {            
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];			
 			echo '</table>';
@@ -471,7 +471,7 @@ if ($show_results) {
             <tr>
                     <td valign="top" align="center" style="padding-left:0px;" >
                         <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';			
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
 			echo '</table></td></tr>';