Browse Source

Fixing exercise results when propagate_neg parameter is = 0

Julio Montoya 14 years ago
parent
commit
1a2e827c74

+ 1 - 2
main/exercice/exercice_submit.php

@@ -497,7 +497,6 @@ if ($objExercise->selectAttempts() > 0) {
                     $last_attempt_info = $exercise_stat_info[$max_exe_id];
                     echo Display::div(get_lang('Date').': '.api_get_local_time($last_attempt_info['exe_date']), array('id'=>'')).'<br />';
                     
-                    //echo '<pre>';    //var_dump($last_attempt_info);  
                     if (!empty($last_attempt_info['question_list'])) {               
                         foreach($last_attempt_info['question_list'] as $question_data) {
                             $question_id = $question_data['question_id'];
@@ -508,7 +507,7 @@ if ($objExercise->selectAttempts() > 0) {
                             echo Display::div(get_lang('Score').' '.$marks, array('id'=>'question_score'));
                         }
                     }                    
-                    $score =  show_score($last_attempt_info['exe_result'],$last_attempt_info['exe_weighting']);
+                    $score =  show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']);
                     echo Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score'));
                     
                     

+ 17 - 20
main/exercice/exercise.class.php

@@ -3,7 +3,7 @@
 
 /**
 *	Exercise class: This class allows to instantiate an object of type Exercise
-*	@package dokeos.exercise
+*	@package chamilo.exercise
 * 	@author Olivier Brouckaert
 * 	@author Julio Montoya Cleaning exercises
 * 	@version $Id: exercise.class.php 22046 2009-07-14 01:45:19Z ivantcholakov $
@@ -1705,8 +1705,7 @@ class Exercise {
             $true_score     = $extra[0];
             $false_score    = $extra[1];
             $doubt_score    = $extra[2];        	
-        }
-        
+        }        
         
         $totalWeighting 		= 0;
         $totalScore				= 0;
@@ -2355,31 +2354,26 @@ class Exercise {
                         </tr>';                    
                     }
                 }
-            if($origin != 'learnpath') { 
+            if ($origin != 'learnpath') { 
             ?>
                 <tr>
                 <td colspan="<?php echo $colspan; ?>" align="left">                    
                     <?php                    
                     if ($this->type == ALL_ON_ONE_PAGE) {
-                        echo '<div id="question_score">';
-                        if ($questionScore==-1) {
-                            echo get_lang('Score').": 0 /".float_format($questionWeighting);
-                        } else {
-                            if ($propagate_neg == 0 && $questionScore < 0) {
-                    	        $questionScore = 0;
-                    	    }                    	    
-                            echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1);
-                        }
+                        echo '<div id="question_score">';                        
+                        if ($propagate_neg == 0 && $questionScore < 0) {
+                	        $questionScore = 0;
+                	    }                    	    
+                        echo get_lang('Score').": ".show_score($questionScore, $questionWeighting,false, false);
+                        
                         echo '</div>';
                     }
                     ?><br />
                 </td>
                 </tr>
                 </table>
-                <?php } ?>
-            <?php
-        }
-        
+                <?php }
+        }        
         unset ($objAnswerTmp);
         $i++;
     
@@ -2445,12 +2439,15 @@ class Exercise {
         }
             
         if ($saved_results) {
-            $stat_table 			= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+            $stat_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
             $sql_update = 'UPDATE ' . $stat_table . ' SET exe_result = exe_result + ' . floatval($totalScore) . ',exe_weighting = exe_weighting + ' .  floatval($totalWeighting) . ' WHERE exe_id = ' . $exeId;
     		Database::query($sql_update);
         }
-        
-        $return_array = array('score'=>$questionScore, 'weight'=>$questionWeighting);         
+        	
+    	if ($propagate_neg == 0 && $questionScore < 0) {
+    	    $questionScore = 0;
+    	}
+        $return_array = array('score'=>$questionScore, 'weight'=>$questionWeighting);
         return $return_array;
 	} //End function
     

+ 17 - 14
main/exercice/exercise.lib.php

@@ -1060,14 +1060,13 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
     
                     // if the float look like 10.00 we show only 10
     
-                    $my_res     = float_format($results[$i]['exresult'],1);
-                    $my_total   = float_format($results[$i]['exweight'],1);
+                    $my_res     = $results[$i]['exresult'];
+                    $my_total   = $results[$i]['exweight'];
                     if (!$results[$i]['propagate_neg'] && $my_res < 0) {
                         $my_res = 0;
                     }
                     $ex = show_score($my_res, $my_total);
                     
-                    //$result_list = round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')';
                     $result_list = $ex;
     
                     $html_link = '';
@@ -1132,32 +1131,36 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
 }
 
 /**
- * Transform the score with exercise_max_note and exercise_min_score the platform settings
+ * Converts the score with the exercise_max_note and exercise_min_score the platform settings + formats the results using the float_format function
+ * 
  * @param   float   score
  * @param   float   weight
  * @param   bool    show porcentage or not
+ * @param	bool	use or not the platform settings
  * @return  string  an html with the score modified
  */
-function show_score($score, $weight, $show_porcentage = true) {
+function show_score($score, $weight, $show_porcentage = true, $use_platform_settings = true) {
     $html  = '';
     $score_rounded = $score;
      
     $max_note =  api_get_setting('exercise_max_score');
     $min_note =  api_get_setting('exercise_min_score');
     
-    if ($max_note != '' && $min_note != '') {        
-        if (!empty($weight) && intval($weight) != 0) {
-	       $score        = $min_note + ($max_note - $min_note) * $score /$weight;
-        } else {
-           $score          = $min_note;
+    if ($use_platform_settings) {
+        if ($max_note != '' && $min_note != '') {        
+            if (!empty($weight) && intval($weight) != 0) {
+    	       $score        = $min_note + ($max_note - $min_note) * $score /$weight;
+            } else {
+               $score        = $min_note;
+            }
+            $score_rounded  = float_format($score, 1);
+            $weight         = $max_note;
         }
-        $score_rounded  = round($score, 2);
-        $weight         = $max_note;
     }
     if ($show_porcentage) {
-        $html = round(($score / ($weight != 0 ? $weight : 1)) * 100, 2) . '% (' . $score_rounded . ' / ' . $weight . ')';	
+        $html = float_format(($score / ($weight != 0 ? $weight : 1)) * 100, 1) . '% (' . $score_rounded . ' / ' . $weight . ')';	
     } else {            
-        $weight = round($weight, 2);
+        $weight = float_format($weight, 1);
     	$html = $score_rounded . ' / ' . $weight;
     }
     return $html;	

+ 17 - 25
main/exercice/exercise_result.php

@@ -54,9 +54,6 @@ $main_user_table 		= Database::get_main_table(TABLE_MAIN_USER);
 $main_admin_table       = Database::get_main_table(TABLE_MAIN_ADMIN);
 $main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
 
-
-//temp values to move to admin settings
-$dsp_percent = false; //false to display total score as absolute values
 //debug param. 0: no display - 1: debug display
 $debug=0;
 if($debug>0){error_log('Entered exercise_result.php: '.print_r($_POST,1));}
@@ -303,23 +300,19 @@ 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', $exerciseResultCoordinates, true, false, true, $objExercise->selectPropagateNeg());    
-    $totalScore        += $result['score'];
+	$result = $objExercise->manage_answer($exeId, $questionId, $choice,'exercise_result', $exerciseResultCoordinates, true, false, true, $objExercise->selectPropagateNeg());   	
+    $totalScore        += $result['score'];    
     $totalWeighting    += $result['weight'];
     
 } // end huge foreach() block that loops over all questions
 
 if($origin != 'learnpath') {
     echo '<div id="question_score">';
-    echo get_lang('YourTotalScore')." ";
-	if ($dsp_percent) {
-        echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
-	} else {	    
-	    if ($objExercise->selectPropagateNeg() == 0 && $totalScore < 0) {
-		    $totalScore = 0;
-        } 
-        echo show_score($totalScore, $totalWeighting, false);
-	}
+    echo get_lang('YourTotalScore')." ";	
+    if ($objExercise->selectPropagateNeg() == 0 && $totalScore < 0) {
+	    $totalScore = 0;
+    }     
+    echo show_score($totalScore, $totalWeighting, false);	
     echo '</div>';
 	?>
     <button type="submit" class="save"><?php echo get_lang('Finish');?></button>
@@ -328,18 +321,17 @@ if($origin != 'learnpath') {
 
 // Tracking of results
 
-if ($_configuration['tracking_enabled']) {
-	//	Updates the empty exercise
-	$safe_lp_id = $learnpath_id==''?0:(int)$learnpath_id;
-	$safe_lp_item_id = $learnpath_item_id==''?0:(int)$learnpath_item_id;
-    $safe_lp_item_view_id = $learnpath_item_view_id==''?0:(int)$learnpath_item_view_id;
-	$quizDuration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0);
-	if (api_is_allowed_to_session_edit() ) {
-		update_event_exercice($exeId, $objExercise->selectId(),$totalScore, $totalWeighting,api_get_session_id(),$safe_lp_id,$safe_lp_item_id,$safe_lp_item_view_id, $quizDuration);
-	}
+//	Updates the empty exercise
+$safe_lp_id = $learnpath_id==''?0:(int)$learnpath_id;
+$safe_lp_item_id = $learnpath_item_id==''?0:(int)$learnpath_item_id;
+$safe_lp_item_view_id = $learnpath_item_view_id==''?0:(int)$learnpath_item_view_id;
+$quizDuration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0);
+if (api_is_allowed_to_session_edit() ) {
+	update_event_exercice($exeId, $objExercise->selectId(), $totalScore, $totalWeighting,api_get_session_id(),$safe_lp_id,$safe_lp_item_id,$safe_lp_item_view_id, $quizDuration);
 }
 
-if($objExercise->results_disabled) {
+
+if ($objExercise->results_disabled) {
 	ob_end_clean();
 	if ($origin != 'learnpath') {
 		Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
@@ -416,7 +408,7 @@ if (api_get_course_setting('email_alert_manager_on_new_quiz') == 1 ) {
 			<link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
 			<meta content="text/html; charset='.$mycharset.'" http-equiv="content-type"></head>';
 
-		if(count($arrques)>0) {
+		if (count($arrques)>0) {
 			$msg .= '
 			<body><br />
 			<p>'.get_lang('OpenQuestionsAttempted').' :

+ 16 - 21
main/exercice/exercise_show.php

@@ -12,7 +12,7 @@
  * */
 
 // name of the language file that needs to be included
-$language_file=array('exercice');
+$language_file = array('exercice');
 
 // including additional libraries
 require_once 'exercise.class.php';
@@ -46,7 +46,6 @@ $main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
 $TBL_TRACK_EXERCICES	= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
 $TBL_TRACK_ATTEMPT		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
 
-$dsp_percent = false;
 $debug=0;
 
 // General parameters passed via POST/GET
@@ -374,7 +373,7 @@ if ($show_results) {
 			<?php
 			// construction of the Answer object
        
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, true, $objExercise->selectPropagateNeg());            
             //var_dump($question_result);
             $questionScore      = $question_result['score'];
             $totalScore        += $question_result['score'];            
@@ -399,7 +398,7 @@ if ($show_results) {
 			</tr>
 			<?php
 	            
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);                       
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, true, $objExercise->selectPropagateNeg());                       
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
 
@@ -425,7 +424,7 @@ if ($show_results) {
 				</tr>
 			<?php	
             
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, true, $objExercise->selectPropagateNeg());
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];  
 			echo '</table>';
@@ -444,7 +443,7 @@ if ($show_results) {
 			</tr>
 			<?php
                       
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, true, $objExercise->selectPropagateNeg());
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
               
@@ -465,12 +464,12 @@ if ($show_results) {
 
 			<?php
 			
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, true, $objExercise->selectPropagateNeg());            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
 
 		} elseif ($answerType == MATCHING) {            
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, true, $objExercise->selectPropagateNeg());            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];			
 			echo '</table>';
@@ -480,7 +479,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', array(), false, true);            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, true, $objExercise->selectPropagateNeg());            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
 			echo '</table></td></tr>';            
@@ -592,7 +591,9 @@ if ($show_results) {
 	        $my_total_score = 0;
 	    }  
 	    
-		echo get_lang('Score')." : $my_total_score / $my_total_weight";        
+		//echo get_lang('Score')." : $my_total_score / $my_total_weight";
+		echo get_lang('Score')." : ".show_score($my_total_score, $my_total_weight, false, false);    
+		
         //echo get_lang('Score')." : ".show_score($my_total_score, $total_weighting, false);
 		echo '</div>';
 
@@ -606,17 +607,11 @@ if ($show_results) {
 if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
 	if ($show_results) {        
 		echo '<div id="question_score">'.get_lang('YourTotalScore').": ";
-        //@todo $dsp_percent who do that and why?
-		if ($dsp_percent) {
-			$my_result = number_format(($totalScore/$totalWeighting)*100,1,'.','');
-			$my_result = float_format($my_result,1);
-			echo $my_result."%";
-		} else {          
-		    if ($objExercise->selectPropagateNeg() == 0 && $totalScore < 0) {
-		        $totalScore = 0;
-		    }          
-            echo show_score($totalScore, $totalWeighting, false);
-		}
+        $my_total_score_temp = $totalScore; 
+	    if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
+	        $my_total_score_temp = 0;
+	    }          
+        echo show_score($my_total_score_temp, $totalWeighting, false);	
 		echo '</div>';
 	}
 }