Browse Source

More exercise fixes

Julio Montoya 14 years ago
parent
commit
98cb37b03a
2 changed files with 29 additions and 315 deletions
  1. 24 23
      main/exercice/exercise.class.php
  2. 5 292
      main/exercice/exercise_show.php

+ 24 - 23
main/exercice/exercise.class.php

@@ -1649,8 +1649,7 @@ class Exercise {
         
 		$exeId = intval($exeId);        
         $TBL_TRACK_ATTEMPT      = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
-        $table_ans              = Database::get_course_table(TABLE_QUIZ_ANSWER);
-        
+        $table_ans              = Database::get_course_table(TABLE_QUIZ_ANSWER);        
                     
      	// Creates a temporary Question object
         $objQuestionTmp         = Question :: read($questionId);
@@ -2037,8 +2036,8 @@ class Exercise {
                         $numAnswer=$objAnswerTmp->selectAutoId($answerId);
                         if ($answerCorrect) {
                             if ($answerCorrect == $choice[$numAnswer]) {
-                                $questionScore+=$answerWeighting;
-                                $totalScore+=$answerWeighting;
+                                $questionScore  += $answerWeighting;
+                                $totalScore     += $answerWeighting;
                                 $user_answer = '<span>'.$answer_matching[$choice[$numAnswer]].'</span>';
                             } else {
                                 $user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$answer_matching[$choice[$numAnswer]].'</span>';                    
@@ -2050,6 +2049,7 @@ class Exercise {
                     
                     // for hotspot with no order
                 case HOT_SPOT :
+                
                     if ($from_database) {                      
                         if ($show_result) {
                             $TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
@@ -2058,10 +2058,10 @@ class Exercise {
                             $studentChoice = Database::result($resq,0,"hotspot_correct");                                
                         }
                     }  else {
-                        $studentChoice = $choice[$answerId];
+                        $studentChoice = $choice[$answerId];                        
                         if ($studentChoice) {
-                            $questionScore += $answerWeighting;
-                            $totalScore += $answerWeighting;
+                            $questionScore  += $answerWeighting;
+                            $totalScore     += $answerWeighting;
                         }
                     }
                     break;
@@ -2070,8 +2070,8 @@ class Exercise {
                 case HOT_SPOT_ORDER :
                     $studentChoice = $choice['order'][$answerId];
                     if ($studentChoice == $answerId) {
-                        $questionScore += $answerWeighting;
-                        $totalScore += $answerWeighting;
+                        $questionScore  += $answerWeighting;
+                        $totalScore     += $answerWeighting;
                         $studentChoice = true;
                     } else {
                         $studentChoice = false;
@@ -2079,11 +2079,10 @@ class Exercise {
                     break;
             } // end switch Answertype            
             
-            global $origin;
-            
-            if ($show_result) {      
+            global $origin;            
+            if ($show_result) {
                           
-                if ($from == 'exercise_result') {         
+                if ($from == 'exercise_result') {       
                         //display answers (if not matching type, or if the answer is correct)
                         
                     if ($answerType != MATCHING || $answerCorrect) {
@@ -2188,11 +2187,11 @@ class Exercise {
         } // end for that loops over all answers of the current question
         
         // destruction of Answer
-
-        if ($answerType == HOT_SPOT) {         
-            $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($exeId)."' and question_id= '".Database::escape_string($questionId)."'";
-            $resfree = Database::query($queryfree);
-            $questionScore= Database::result($resfree,0,"marks");
+        
+        if (!$saved_results && $answerType == HOT_SPOT) {         
+            $queryfree      = "SELECT marks FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($exeId)."' and question_id= '".Database::escape_string($questionId)."'";
+            $resfree        = Database::query($queryfree);
+            $questionScore  = Database::result($resfree,0,"marks");
         }
 
         $final_answer = true;
@@ -2201,6 +2200,7 @@ class Exercise {
                 $final_answer = false;
             }
         }        
+        
         //we add the total score after dealing with the answers
         if ($answerType == MULTIPLE_ANSWER_COMBINATION) {            
             if ($final_answer) {
@@ -2210,7 +2210,7 @@ class Exercise {
                 $totalScore+=$answerWeighting;
             }
         }        
-        
+       
        if ($from == 'exercise_result') {
             global $colspan;
             // if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
@@ -2231,17 +2231,18 @@ class Exercise {
                 }
             if($origin != 'learnpath') { ?>
                 <tr>
-                <td colspan="<?php echo $colspan; ?>" align="left">
-                    <b>
+                <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 {
                             echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1);
                         }
+                        echo '</div>';
                     }
-                    ?></b><br /><br />
+                    ?><br />
                 </td>
                 </tr>
                 </table>
@@ -2291,7 +2292,7 @@ class Exercise {
             } elseif ($answerType == UNIQUE_ANSWER) {
                 $answer = $choice;
                 exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
-            } elseif ($answerType == HOT_SPOT) {
+            } elseif ($answerType == HOT_SPOT) {                
                 exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
                 if (is_array($exerciseResultCoordinates[$questionId])) {
                     foreach($exerciseResultCoordinates[$questionId] as $idx => $val) {

+ 5 - 292
main/exercice/exercise_show.php

@@ -366,39 +366,7 @@ if ($show_results) {
 			</tr>
 			<?php
 			// construction of the Answer object
-           
-           /* $choice=array();
-                        
-			$objAnswerTmp=new Answer($questionId);
-			$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
-			$questionScore=0;
-			for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
-				$answer=$objAnswerTmp->selectAnswer($answerId);
-				$answerComment=$objAnswerTmp->selectComment($answerId);
-				$answerCorrect=$objAnswerTmp->isCorrect($answerId);
-				$answerWeighting=$objAnswerTmp->selectWeighting($answerId);
-                
-				$queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
-				$resultans = Database::query($queryans);
-				while ($row = Database::fetch_array($resultans)) {
-					$ind = $row['answer'];
-					$choice[$ind] = 1;
-				}
-				$numAnswer=$objAnswerTmp->selectAutoId($answerId);
-				$studentChoice=$choice[$numAnswer];
-				if ($studentChoice) {
-					$questionScore+=$answerWeighting;
-					$totalScore+=$answerWeighting;
-				}
-				echo '<tr><td>';
-				if ($answerId==1) {
-					//ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
-				} else {
-					//ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
-				}
-				echo '</td></tr>';
-				$i++;
-		 	}*/            
+       
             $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
             //var_dump($question_result);
             $questionScore  = $question_result['score'];
@@ -421,66 +389,8 @@ if ($show_results) {
 			<td>&nbsp;</td>
 			</tr>
 			<?php
-			// construction of the Answer object
-			/*$objAnswerTmp=new Answer($questionId);
-			$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
-			$questionScore=0;
-
-			$real_answers = array();
-
-			for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
-				$answer=$objAnswerTmp->selectAnswer($answerId);
-				$answerComment=$objAnswerTmp->selectComment($answerId);
-				$answerCorrect=$objAnswerTmp->isCorrect($answerId);
-				$answerWeighting=$objAnswerTmp->selectWeighting($answerId);
-				$queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
-				$resultans = Database::query($queryans);
-				while ($row = Database::fetch_array($resultans)) {
-					$ind = $row['answer'];
-					$choice[$ind] = 1;
-				}
-				$numAnswer=$objAnswerTmp->selectAutoId($answerId);
-				$studentChoice=$choice[$numAnswer];
-
-				if ($answerCorrect == 1) {
-					if ($studentChoice) {
-						$real_answers[$answerId] = true;
-					} else {
-						$real_answers[$answerId] = false;
-					}
-				} else {
-					if ($studentChoice) {
-						$real_answers[$answerId] = false;
-					} else {
-						$real_answers[$answerId] = true;
-					}
-				}
-
-				echo '<tr><td>';
-				if ($answerId==1) {
-					ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
-				} else {
-					ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
-				}
-				echo '</td></tr>';
-				$i++;
-		 	}
-		 	$final_answer = true;
-		 	foreach($real_answers as $my_answer) {
-		 		if (!$my_answer) {
-		 			$final_answer = false;
-		 		}
-		 	}
-
-		 	if ($final_answer) {
-		 		//getting only the first score where we save the weight of all the question
-		 		$answerWeighting=$objAnswerTmp->selectWeighting(1);
-				$questionScore+=$answerWeighting;
-				$totalScore+=$answerWeighting;
-			}*/
-            
-            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
-            
+	            
+            $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
 
@@ -504,35 +414,7 @@ if ($show_results) {
 				<tr>
 				<td>&nbsp;</td>
 				</tr>
-			<?php
-			/*$objAnswerTmp=new Answer($questionId);
-			$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
-			$questionScore=0;
-			for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
-				$answer=$objAnswerTmp->selectAnswer($answerId);
-				$answerComment=$objAnswerTmp->selectComment($answerId);
-				$answerCorrect=$objAnswerTmp->isCorrect($answerId);
-				$answerWeighting=$objAnswerTmp->selectWeighting($answerId);
-				$queryans = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
-				$resultans = Database::query($queryans);
-				$choice = Database::result($resultans,0,"answer");
-
-				$numAnswer=$objAnswerTmp->selectAutoId($answerId);
-
-				$studentChoice=($choice == $numAnswer)?1:0;
-				if ($studentChoice) {
-				  	$questionScore+=$answerWeighting;
-					$totalScore+=$answerWeighting;
-				}
-				echo '<tr><td>';
-				if ($answerId==1) {
-					ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
-				} else {
-					ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
-				}
-				echo '</td></tr>';
-				$i++;
-			}*/
+			<?php	
             
             $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
             $questionScore  = $question_result['score'];
@@ -552,153 +434,7 @@ if ($show_results) {
 			<td>&nbsp;</td>
 			</tr>
 			<?php
-            /*
-			$objAnswerTmp=new Answer($questionId);
-			$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
-			$questionScore=0;
-
-			for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
-				$answer = $objAnswerTmp->selectAnswer($answerId);
-				$answerComment = $objAnswerTmp->selectComment($answerId);
-				$answerCorrect = $objAnswerTmp->isCorrect($answerId);
-				$answerWeighting = $objAnswerTmp->selectWeighting($answerId);
-
-			    // the question is encoded like this
-			    // [A] B [C] D [E] F::10,10,10@1
-			    // number 1 before the "@" means that is a switchable fill in blank question
-			    // [A] B [C] D [E] F::10,10,10@ or  [A] B [C] D [E] F::10,10,10
-			    // means that is a normal fill blank question
-
-				$pre_array = explode('::', $answer);
-
-				// is switchable fill blank or not
-				$is_set_switchable = explode('@', $pre_array[1]);
-				$switchable_answer_set=false;
-				if ($is_set_switchable[1]==1) {
-					$switchable_answer_set=true;
-				}
-
-				$answer = $pre_array[0];
-                
-
-				// splits weightings that are joined with a comma
-				$answerWeighting = explode(',',$is_set_switchable[0]);
-				//list($answer,$answerWeighting)=explode('::',$multiple[0]);
-
-				//$answerWeighting=explode(',',$answerWeighting);
-				// we save the answer because it will be modified
-			    //$temp=$answer;
-			    $temp = text_filter($answer);
-
-
-
-				$j=0;
-				// the loop will stop at the end of the text
-				$i=0;
-				//normal fill in blank
-                
-				if (!$switchable_answer_set) {
-					while (1) {
-						// quits the loop if there are no more blanks
-						if (($pos = api_strpos($temp,'[')) === false) {
-							// adds the end of the text
-							$answer.=$temp;
-		
-							break;
-						}
-					    $temp=api_substr($temp,$pos+1);
-						// quits the loop if there are no more blanks
-						if (($pos = api_strpos($temp,']')) === false) {
-							break;
-						}
-
-						$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' AND question_id= '".Database::escape_string($questionId)."'";
-						$resfill = Database::query($queryfill);
-						$str = Database::result($resfill,0,'answer');
-                        
-
-						preg_match_all('#\[([^[]*)\]#', $str, $arr);
-						$str = str_replace('\r\n', '', $str);
-						$choice = $arr[1];
-
-						$tmp=strrpos($choice[$j],' / ');
-						$choice[$j]=api_substr($choice[$j],0,$tmp);
-						$choice[$j]=trim($choice[$j]);
-
-						//Needed to let characters ' and " to work as part of an answer
-						$choice[$j] = stripslashes($choice[$j]);
-
-
-						// if the word entered by the student IS the same as the one defined by the professor
-						if (api_strtolower(api_substr($temp,0,$pos)) == api_strtolower($choice[$j])) {
-						//if ((api_substr($temp,0,$pos)) == ($choice[$j])) {
-							// gives the related weighting to the student
-							$questionScore+=$answerWeighting[$j];
-							// increments total score
-							$totalScore+=$answerWeighting[$j];
-						}
-						// else if the word entered by the student IS NOT the same as the one defined by the professor
-						$j++;
-						$temp=api_substr($temp,$pos+1);
-						$i=$i+1;
-					}
-					$answer = stripslashes($str);
-
-				} else {
-					//multiple fill in blank
-					while (1) {
-						// quits the loop if there are no more blanks
-						if (($pos = api_strpos($temp,'[')) === false) {
-							// adds the end of the text
-							$answer.=$temp;
-
-							break;
-						}
-						// adds the piece of text that is before the blank and ended by [
-						$real_text[]=api_substr($temp,0,$pos+1);
-						$answer.=api_substr($temp,0,$pos+1);
-						$temp=api_substr($temp,$pos+1);
-
-						// quits the loop if there are no more blanks
-						if (($pos = api_strpos($temp,']')) === false) {
-							// adds the end of the text
-							//$answer.=$temp;
-							break;
-						}
-
-						$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
-						$resfill = Database::query($queryfill);
-						$str=Database::result($resfill,0,"answer");
-						preg_match_all ('#\[([^[/]*)/#', $str, $arr);
-						$choice = $arr[1];
-
-						$choice[$j]=trim($choice[$j]);
-						$user_tags[]=api_strtolower($choice[$j]);
-						$correct_tags[]=api_strtolower(api_substr($temp,0,$pos));
-
-						$j++;
-						$temp=api_substr($temp,$pos+1);
-						$i=$i+1;
-					}
-					$answer='';
-					for ($i=0;$i<count($correct_tags);$i++) {
-						if (in_array($user_tags[$i],$correct_tags)) {
-							// gives the related weighting to the student
-							$questionScore+=$answerWeighting[$i];
-							// increments total score
-							$totalScore+=$answerWeighting[$i];
-						}
-					}
-					$answer = stripslashes($str);
-					$answer = str_replace('rn', '', $answer);
-				}
-				//echo $questionScore."-".$totalScore;
-				echo '<tr><td>';
-				ExerciseShowFunctions::display_fill_in_blanks_answer($answer,$id,$questionId);
-				echo '</td></tr>';
-				$i++;
-			}*/
-            
+                      
             $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
@@ -720,32 +456,9 @@ if ($show_results) {
 
 			<?php
 			
-           /* $objAnswerTmp = new Answer($questionId);
-			$nbrAnswers = $objAnswerTmp->selectNbrAnswers();
-			$questionScore = 0;
-			$query 	= "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' AND question_id= '".Database::escape_string($questionId)."'";
-			$resq	= Database::query($query);
-			$choice = Database::result($resq,0,'answer');
-			$choice = str_replace('\r\n', '', $choice);
-			$choice = stripslashes($choice);
-
-			$questionScore = Database::result($resq,0,"marks");
-			if ($questionScore==-1) {
-				$totalScore+=0;
-			} else {
-				$totalScore+=$questionScore;
-			}
-
-			$arrques[] = $questionName;
-            $arrans[]  = $choice;*/
             $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);            
             $questionScore  = $question_result['score'];
             $totalScore    += $question_result['score'];
-            
-			/*echo '<tr>
-			<td valign="top">'.ExerciseShowFunctions::display_free_answer($choice, $id, $questionId).'</td>
-			</tr>
-			</table>';*/
 
 		} elseif ($answerType == MATCHING) {            
             $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);