Bladeren bron

Add auto-evaluation mode with feedback without correct answer hint -ref #6513

Hubert Borderiou 11 jaren geleden
bovenliggende
commit
6288f11019

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

@@ -960,7 +960,7 @@ class Exercise {
                 $radios_results_disabled = array();
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'),  '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()'));
-                $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'),  '2', array('id'=>'result_disabled_2','onclick' => 'check_results_disabled()'));
+                $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'),  '2', array('id'=>'result_disabled_2'));
                 //$radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ExamModeWithFinalScoreShowOnlyFinalScoreWithCategoriesIfAvailable'),  '3', array('id'=>'result_disabled_3','onclick' => 'check_results_disabled()'));
 
                 $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
@@ -1900,6 +1900,7 @@ class Exercise {
         global $learnpath_id, $learnpath_item_id; //needed in order to use in the exercise_attempt() for the time
 
         $feedback_type = $this->selectFeedbackType();
+        $results_disabled = $this->selectResultsDisabled();
 
         require_once api_get_path(LIBRARY_PATH).'geometry.lib.php';
 
@@ -2561,7 +2562,6 @@ class Exercise {
 
             global $origin;
 
-
             if ($show_result) {
 
                 if ($debug) error_log('show result '.$show_result);
@@ -2572,15 +2572,15 @@ class Exercise {
                     if ($answerType != MATCHING || $answerCorrect) {
                         if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION, GLOBAL_MULTIPLE_ANSWER))) {
                             //if ($origin != 'learnpath') {
-                            ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, 0, 0, 0);
+                            ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, 0, 0, 0, $results_disabled);
                             //}
                         } elseif($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
                             //if ($origin!='learnpath') {
-                            ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,$questionId,0);
+                            ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,$questionId,0, $results_disabled);
                             //}
                         } elseif($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
                             //	if ($origin!='learnpath') {
-                            ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
+                            ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0, $results_disabled);
                             //}
                         } elseif($answerType == FILL_IN_BLANKS) {
                             //if ($origin!='learnpath') {
@@ -2597,7 +2597,7 @@ class Exercise {
                             //}
                         } elseif($answerType == HOT_SPOT) {
                             //if ($origin != 'learnpath') {
-                            ExerciseShowFunctions::display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment);
+                            ExerciseShowFunctions::display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment, $results_disabled);
                             //	}
                         } elseif($answerType == HOT_SPOT_ORDER) {
                             //if ($origin != 'learnpath') {
@@ -2771,23 +2771,23 @@ class Exercise {
                         case GLOBAL_MULTIPLE_ANSWER :
                         case MULTIPLE_ANSWER_COMBINATION :
                             if ($answerId==1) {
-                                ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
+                                ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId, $results_disabled);
                             } else {
-                                ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"");
+                                ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"", $results_disabled);
                             }
                             break;
                         case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
                             if ($answerId==1) {
-                                ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
+                                ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId, $results_disabled);
                             } else {
-                                ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"");
+                                ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"", $results_disabled);
                             }
                             break;
                         case MULTIPLE_ANSWER_TRUE_FALSE :
                             if ($answerId==1) {
-                                ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
+                                ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId, $results_disabled);
                             } else {
-                                ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId, "");
+                                ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId, "", $results_disabled);
                             }
                             break;
                         case FILL_IN_BLANKS:
@@ -2803,7 +2803,7 @@ class Exercise {
 		                            </table>';
                             break;
                         case HOT_SPOT:
-                            ExerciseShowFunctions::display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment);
+                            ExerciseShowFunctions::display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment, $results_disabled);
                             break;
                         case HOT_SPOT_DELINEATION:
                             $user_answer = $user_array;

+ 12 - 0
main/exercice/exercise.lib.php

@@ -2141,6 +2141,14 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
         $show_only_score = true;
     }
 
+    // Not display expected answer, but score, and feedback
+    $show_all_but_expected_answer = false;
+    if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY && $objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_END) {
+        $show_all_but_expected_answer = true;
+        $show_results = true;
+        $show_only_score = false;
+    }
+
     if ($show_results || $show_only_score) {
         $user_info   = api_get_user_info($exercise_stat_info['exe_user_id']);
         //Shows exercise header
@@ -2279,6 +2287,10 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
         echo $total_score_text;
     }
 
+    if ($show_all_but_expected_answer) {
+        echo "<p>Note : cet exercice est configuré pour ne pas montrer les corrections.</p>";
+    }
+
     if ($save_user_result) {
 
         // Tracking of results

+ 3 - 1
main/exercice/exercise_admin.php

@@ -120,7 +120,9 @@ $htmlHeadXtra[] = '<script>
 		}
 
 		function check_feedback() {
-			document.getElementById(\'result_disabled_0\').checked = true;
+		    if (document.getElementById(\'result_disabled_1\').checked == true) {
+		        document.getElementById(\'result_disabled_0\').checked = true;
+		    }
 		}
 
 		function check_direct_feedback() {

+ 8 - 2
main/exercice/overview.php

@@ -166,7 +166,8 @@ if (!empty($attempts)) {
 			$row['result'] = $score;
 		}
 
-		if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
+		if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))
+            || ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY && $objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_END)) {
 			$row['attempt_link'] = $attempt_link;
 		}
 		$my_attempt_array[] = $row;
@@ -185,7 +186,12 @@ if (!empty($attempts)) {
 			$header_names = array(get_lang('Attempt'), get_lang('StartDate'));
 			break;
 		case RESULT_DISABLE_SHOW_SCORE_ONLY:
-			$header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'));
+            if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_END) {
+			    $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'));
+            }
+            else {
+                $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'), get_lang('Details'));
+            }
 			break;
 	}
 	$column = 0;

+ 43 - 18
main/inc/lib/exercise_show_functions.lib.php

@@ -117,7 +117,11 @@ class ExerciseShowFunctions {
 	 * @param string $studentChoice
 	 * @param string $answerComment
 	 */
-	static function display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment) {
+	static function display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment, $in_results_disabled) {
+        $hide_expected_answer = false;
+        if ($feedback_type == 0 && $in_results_disabled == 2) {
+            $hide_expected_answer = true;
+        }
 
 		$hotspot_colors = array(
             "", // $i starts from 1 on next loop (ugly fix)
@@ -148,8 +152,10 @@ class ExerciseShowFunctions {
 			</td>
 			<td width="50px" style="padding-right:15px" valign="top" align="left">
 				<?php
-				$my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault');
-				echo $my_choice;
+                if (!$hide_expected_answer) {
+    				$my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault');
+    				echo $my_choice;
+                }
 				?>
 			</td>
 			<?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
@@ -184,7 +190,11 @@ class ExerciseShowFunctions {
 	 * @param boolean Whether to show the answer comment or not
 	 * @return void
 	 */
-	static function display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
+	static function display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans, $in_results_disabled) {
+        $hide_expected_answer = false;
+        if ($feedback_type == 0 && $in_results_disabled == 2) {
+            $hide_expected_answer = true;
+        }
 		?>
 		<tr>
 		<td width="5%">
@@ -192,8 +202,12 @@ class ExerciseShowFunctions {
 			border="0" alt="" />
 		</td>
 		<td width="5%">
-			<img src="../img/<?php echo (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION))) ? 'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
-			border="0" alt=" " />
+            <?php if (!$hide_expected_answer) { ?>
+			    <img src="../img/<?php echo (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION))) ? 'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif" border="0" alt=" " />
+            <?php }
+            else {
+                echo "-";
+            }?>
 		</td>
 		<td width="40%">
 			<?php
@@ -248,7 +262,11 @@ class ExerciseShowFunctions {
      * @param boolean Whether to show the answer comment or not
      * @return void
      */
-    static function display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
+    static function display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans, $in_results_disabled) {
+        $hide_expected_answer = false;
+        if ($feedback_type == 0 && $in_results_disabled == 2) {
+            $hide_expected_answer = true;
+        }
         ?>
         <tr>
         <td width="5%">
@@ -269,12 +287,13 @@ class ExerciseShowFunctions {
         <td width="5%">
         <?php
 		//Expected choice
-        if (isset($new_options[$answerCorrect])) {
-            echo get_lang($new_options[$answerCorrect]['name']);
-        } else {
-            echo '-';
+        if (!$hide_expected_answer) {
+            if (isset($new_options[$answerCorrect])) {
+                echo get_lang($new_options[$answerCorrect]['name']);
+            } else {
+                echo '-';
+            }
         }
-
         ?>
         </td>
         <td width="40%">
@@ -318,7 +337,11 @@ class ExerciseShowFunctions {
      * @param boolean Whether to show the answer comment or not
      * @return void
      */
-    static function display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
+    static function display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans, $in_results_disabled) {
+        $hide_expected_answer = false;
+        if ($feedback_type == 0 && $in_results_disabled == 2) {
+            $hide_expected_answer = true;
+        }
         ?>
         <tr>
         <td width="5%">
@@ -335,10 +358,12 @@ class ExerciseShowFunctions {
         <td width="5%">
         <?php
 		//Expected choice
-        if (isset($question->options[$answerCorrect])) {
-            echo $question->options[$answerCorrect];
-        } else {
-            echo $question->options[2];
+        if (!$hide_expected_answer) {
+            if (isset($question->options[$answerCorrect])) {
+                echo $question->options[$answerCorrect];
+            } else {
+                echo $question->options[2];
+            }
         }
         ?>
         </td>
@@ -382,4 +407,4 @@ class ExerciseShowFunctions {
         </tr>
         <?php
     }
-}
+}