Julio Montoya %!s(int64=14) %!d(string=hai) anos
pai
achega
76554797dc

+ 35 - 7
main/exercice/exercise.class.php

@@ -39,6 +39,7 @@ class Exercise {
 	public $results_disabled;
   	public $expired_time;    
     public $course;
+    public $propagate_neg;
     
   	
 	/**
@@ -61,6 +62,7 @@ class Exercise {
 		$this->start_time 		= '0000-00-00 00:00:00';
 		$this->results_disabled = 1;
 		$this->expired_time 	= '0000-00-00 00:00:00';
+		$this->propagate_neg    = 0;
         
         if (!empty($course_id)) {
             $this->course_id        =  intval($course_id);
@@ -85,7 +87,7 @@ class Exercise {
 	    $TBL_QUESTIONS          = Database::get_course_table(TABLE_QUIZ_QUESTION,$this->course['db_name']);
     	#$TBL_REPONSES           = Database::get_course_table(TABLE_QUIZ_ANSWER);
 
-		$sql="SELECT title,description,sound,type,random, random_answers, active, results_disabled, max_attempt,start_time,end_time,feedback_type,expired_time FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
+		$sql="SELECT title,description,sound,type,random, random_answers, active, results_disabled, max_attempt,start_time,end_time,feedback_type,expired_time,propagate_neg FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
 		$result=Database::query($sql);
 
 		// if the exercise has been found
@@ -101,6 +103,7 @@ class Exercise {
 			$this->results_disabled = $object->results_disabled;
 			$this->attempts 		= $object->max_attempt;
 			$this->feedbacktype 	= $object->feedback_type;
+			$this->propagate_neg    = $object->propagate_neg;
 			
 			if ($object->end_time != '0000-00-00 00:00:00') {
 				$this->end_time 		= api_get_local_time($object->end_time); 
@@ -110,6 +113,8 @@ class Exercise {
 			}
       		$this->expired_time 	= $object->expired_time; //control time
       		
+      		
+      		
 			$sql="SELECT question_id, question_order FROM $TBL_EXERCICE_QUESTION, $TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($id)."' ORDER BY question_order";
 			
 			$result=Database::query($sql);
@@ -283,6 +288,10 @@ class Exercise {
 	function selectNbrQuestions() {
 		return sizeof($this->questionList);
 	}
+	
+    function selectPropagateNeg() {
+		return $this->propagate_neg;
+	}
 
 	/**
      * Selects questions randomly in the question list
@@ -377,7 +386,11 @@ class Exercise {
 	* @param - int The expired time of the quiz
 	*/
 	function updateExpiredTime($expired_time) {
-	$this->expired_time = $expired_time;
+	    $this->expired_time = $expired_time;
+	}
+	
+	function updatePropagateNegative($value) {
+	    $this->propagate_neg = $value;
 	}
 
 	/**
@@ -514,6 +527,7 @@ class Exercise {
 		$random 		= $this->random;
 		$random_answers = $this->random_answers;
 		$active 		= $this->active;
+		$propagate_neg  = $this->propagate_neg;
 		$session_id 	= api_get_session_id();    	
 
 		if ($feedbacktype==1){
@@ -542,6 +556,7 @@ class Exercise {
 						start_time='$start_time',end_time='$end_time',
 						max_attempt='".Database::escape_string($attempts)."',
             			expired_time='".Database::escape_string($expired_time)."',
+            			propagate_neg='".Database::escape_string($propagate_neg)."',
 						results_disabled='".Database::escape_string($results_disabled)."'";
 				}
 			$sql .= " WHERE id='".Database::escape_string($id)."'";
@@ -957,6 +972,9 @@ class Exercise {
 			} else {
 				$diplay = 'block';
 			}
+			
+			$form -> addElement('checkbox', 'propagate_neg',get_lang('PropagetNegativeResult'),null);
+			
 
     		$form -> addElement('html','<div id="divtimecontrol"  style="display:'.$diplay.';">');
 
@@ -967,14 +985,17 @@ class Exercise {
 			$expired_date = (int)$this->selectExpiredTime();
 
 			if(($expired_date!='0')) {
-			$form -> addElement('html','<div id="timercontrol" style="display:block;">');
+			    $form -> addElement('html','<div id="timercontrol" style="display:block;">');
 			} else {
-			$form -> addElement('html','<div id="timercontrol" style="display:none;">');
+			    $form -> addElement('html','<div id="timercontrol" style="display:none;">');
 			}
 
 			$form -> addElement('text', 'enabletimercontroltotalminutes',get_lang('ExerciseTotalDurationInMinutes'),array('style' => 'width : 35px','id' => 'enabletimercontroltotalminutes'));
 			$form -> addElement('html','</div>');
 			//$form -> addElement('text', 'exerciseAttempts', get_lang('ExerciseAttempts').' : ',array('size'=>'2'));
+			
+			
+			
 
 			$form -> addElement('html','</div>');  //End advanced setting
 			$form -> addElement('html','</div>');
@@ -1036,6 +1057,7 @@ class Exercise {
 				$defaults['exerciseAttempts'] = $this->selectAttempts();
 				$defaults['exerciseFeedbackType'] = $this->selectFeedbackType();
 				$defaults['results_disabled'] = $this->selectResultsDisabled();
+				$defaults['propagate_neg'] = $this->selectPropagateNeg();
 
 	  			if(($this -> start_time!='0000-00-00 00:00:00')||($this -> end_time!='0000-00-00 00:00:00'))
 	            	$defaults['enabletimelimit'] = 1;
@@ -1079,7 +1101,7 @@ class Exercise {
 	 * function which process the creation of exercises
 	 * @param FormValidator $form the formvalidator instance
 	 */
-	function processCreation($form,$type='') {
+	function processCreation($form, $type='') {
 
 		$this -> updateTitle($form -> getSubmitValue('exerciseTitle'));
 		$this -> updateDescription($form -> getSubmitValue('exerciseDescription'));
@@ -1090,6 +1112,8 @@ class Exercise {
 		$this -> updateRandomAnswers($form -> getSubmitValue('randomAnswers'));
 		$this -> updateResultsDisabled($form -> getSubmitValue('results_disabled'));
     	$this -> updateExpiredTime($form -> getSubmitValue('enabletimercontroltotalminutes'));
+    	
+    	$this -> updatePropagateNegative($form -> getSubmitValue('propagate_neg'));
 
 		if($form -> getSubmitValue('enabletimelimit')==1) {
            $start_time = $form -> getSubmitValue('start_time');
@@ -1657,7 +1681,7 @@ class Exercise {
      * @todo    reduce parameters of this function
      * @return  string  html code
 	 */
-	function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $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, $propagate_neg = 0) {        
 		global $_configuration, $feedback_type;   
 		   
         $questionId   = intval($questionId);
@@ -2338,9 +2362,13 @@ class Exercise {
                     <?php                    
                     if ($this->type == ALL_ON_ONE_PAGE) {
                         echo '<div id="question_score">';
-                        if($questionScore==-1){
+                        if ($questionScore==-1) {
                             echo get_lang('Score').": 0 /".float_format($questionWeighting);
                         } else {
+
+                            if ($propagate_neg && $questionScore < 0) {
+                    	        $questionScore = 0;
+                    	    }                    	    
                             echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1);
                         }
                         echo '</div>';

+ 6 - 3
main/exercice/exercise_result.php

@@ -303,7 +303,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', $exerciseResultCoordinates, true);    
+	$result = $objExercise->manage_answer($exeId, $questionId, $choice,'exercise_result', $exerciseResultCoordinates, true, false, true, $objExercise->selectPropagateNeg());    
     $totalScore        += $result['score'];
     $totalWeighting    += $result['weight'];
     
@@ -313,9 +313,12 @@ if($origin != 'learnpath') {
     echo '<div id="question_score">';
     echo get_lang('YourTotalScore')." ";
 	if ($dsp_percent) {
-	  echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
+        echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
 	} else {
-	  echo float_format($totalScore,1)."/".float_format($totalWeighting,1);
+	    if ($objExercise->selectPropagateNeg() && $totalScore < 0) {
+		    $totalScore = 0;
+        } 
+        echo show_score($totalScore, $totalWeighting, false);
 	}
     echo '</div>';
 	?>

+ 9 - 2
main/exercice/exercise_show.php

@@ -584,6 +584,10 @@ if ($show_results) {
 		$my_total_weight = convert_score($questionWeighting, $total_weighting);       
 
 		echo '<div id="question_score">';
+	    if ($objExercise->selectPropagateNeg() && $my_total_score < 0) {
+	        $my_total_score = 0;
+	    }  
+	    
 		echo get_lang('Score')." : $my_total_score / $my_total_weight";        
         //echo get_lang('Score')." : ".show_score($my_total_score, $total_weighting, false);
 		echo '</div>';
@@ -599,11 +603,14 @@ 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) {            
+		if ($dsp_percent) {
 			$my_result = number_format(($totalScore/$totalWeighting)*100,1,'.','');
 			$my_result = float_format($my_result,1);
 			echo $my_result."%";
-		} else {                    
+		} else {          
+		    if ($objExercise->selectPropagateNeg() && $totalScore < 0) {
+		        $totalScore = 0;
+		    }          
             echo show_score($totalScore, $totalWeighting, false);
 		}
 		echo '</div>';

+ 1 - 0
main/inc/lib/add_course.lib.inc.php

@@ -631,6 +631,7 @@ function update_Db_course($course_db_name) {
         feedback_type int NOT NULL default 0,
         expired_time int NOT NULL default '0',
         session_id smallint default 0,
+        propagate_neg INT NOT NULL DEFAULT 0,
         PRIMARY KEY (id)
         )" . $charset_clause;
     Database::query($sql);

+ 2 - 0
main/install/migrate-db-1.8.7-1.8.8-pre.sql

@@ -189,3 +189,5 @@ CREATE TABLE usergroup ( id INT NOT NULL AUTO_INCREMENT,	name VARCHAR(255) NOT N
 CREATE TABLE usergroup_rel_user    ( usergroup_id INT NOT NULL, user_id 	INT NOT NULL );
 CREATE TABLE usergroup_rel_course  ( usergroup_id INT NOT NULL, course_id 	INT NOT NULL );
 CREATE TABLE usergroup_rel_session ( usergroup_id INT NOT NULL, session_id  INT NOT NULL );
+
+ALTER TABLE quiz ADD COLUMN propagate_neg INT NOT NULL DEFAULT 0;