diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 6c7e8a18b3..88696feb7b 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -61,7 +61,6 @@ class Exercise { public $exercise_was_added_in_lp = false; public $force_edit_exercise_in_lp = false; - /** * Constructor of the class * @@ -234,7 +233,6 @@ class Exercise { return $this->feedback_type; } - /** * returns the time limit */ @@ -1897,8 +1895,17 @@ class Exercise { * @return string html code */ public function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true, $propagate_neg = 0, $hotspot_delineation_result = array()) { - global $feedback_type, $debug; + global $debug; global $learnpath_id, $learnpath_item_id; //needed in order to use in the exercise_attempt() for the time + + $feedback_type = $this->selectFeedbackType(); + if ($from == 'exercise_show') { + if (api_is_allowed_to_edit()) { + //For teachers + $feedback_type = EXERCISE_FEEDBACK_TYPE_END; + } + } + require_once api_get_path(LIBRARY_PATH).'geometry.lib.php'; if ($debug) error_log("<------ manage_answer ------> "); @@ -1935,9 +1942,10 @@ class Exercise { // Creates a temporary Question object $course_id = api_get_course_int_id(); $objQuestionTmp = Question::read($questionId, $course_id); - if ($objQuestionTmp === false) { - return false; - } + + if ($objQuestionTmp === false) { + return false; + } $questionName = $objQuestionTmp->selectTitle(); $questionWeighting = $objQuestionTmp->selectWeighting(); @@ -1960,6 +1968,9 @@ class Exercise { $totalWeighting = 0; $totalScore = 0; + + + // Destruction of the Question object unset ($objQuestionTmp); @@ -2454,10 +2465,14 @@ class Exercise { $user_answer = ''.$real_list[$s_user_answer].''; } } + if ($show_result) { - echo ''; - echo ''.$s_answer_label.''.$user_answer.' '.$real_list[$i_answer_correct_answer].''; - echo ''; + echo ''; + echo ''.$s_answer_label.''; + echo ''.$user_answer; + echo ' '.$real_list[$i_answer_correct_answer].' '; + echo ''; + echo ''; } } break(2); //break the switch and the "for" condition @@ -2742,14 +2757,12 @@ class Exercise { error_log(__LINE__.' first',0); } } - - - } elseif($answerType==MATCHING) { - if ($origin != 'learnpath') { - echo ''; - echo ''.$answer_matching[$answerId].''.$user_answer.' / '.text_filter($answer_matching[$answerCorrect]).''; - echo ''; - } + } elseif($answerType == MATCHING) { + if ($origin != 'learnpath') { + echo ''; + echo ''.$answer_matching[$answerId].''.$user_answer.' / '.$answer_matching[$answerCorrect].''; + echo ''; + } } } } else { @@ -2945,11 +2958,11 @@ class Exercise { ExerciseShowFunctions::display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment); break; case MATCHING: - if ($origin != 'learnpath') { - echo ''; - echo ''.text_filter($answer_matching[$answerId]).''.text_filter($user_answer).' / '.text_filter($answer_matching[$answerCorrect]).''; - echo ''; - } + if ($origin != 'learnpath') { + echo ''; + echo ''.$answer_matching[$answerId].''.$user_answer.' / '.$answer_matching[$answerCorrect].''; + echo ''; + } break; } } @@ -2959,13 +2972,6 @@ class Exercise { if ($debug) error_log('-- end answer loop --'); - /* - 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; foreach ($real_answers as $my_answer) { if (!$my_answer) { @@ -3014,15 +3020,16 @@ class Exercise { } } - $extra_data = array('final_overlap' => $final_overlap, - 'final_missing'=>$final_missing, - 'final_excess'=> $final_excess, - 'overlap_color' => $overlap_color, - 'missing_color'=>$missing_color, - 'excess_color'=> $excess_color, - 'threadhold1' => $threadhold1, - 'threadhold2'=>$threadhold2, - 'threadhold3'=> $threadhold3, + $extra_data = array( + 'final_overlap' => $final_overlap, + 'final_missing'=>$final_missing, + 'final_excess'=> $final_excess, + 'overlap_color' => $overlap_color, + 'missing_color'=>$missing_color, + 'excess_color'=> $excess_color, + 'threadhold1' => $threadhold1, + 'threadhold2'=>$threadhold2, + 'threadhold3'=> $threadhold3, ); if ($from == 'exercise_result') { @@ -3175,6 +3182,8 @@ class Exercise { } unset ($objAnswerTmp); + + $totalWeighting += $questionWeighting; // Store results directly in the database // For all in one page exercises, the results will be @@ -3260,17 +3269,16 @@ class Exercise { Database::query($sql_update); } - $return_array = array( 'score' => $questionScore, - 'weight' => $questionWeighting, - 'extra' => $extra_data, - 'open_question' => $arrques, - 'open_answer' => $arrans, - 'answer_type' => $answerType + $return_array = array( + 'score' => $questionScore, + 'weight' => $questionWeighting, + 'extra' => $extra_data, + 'open_question' => $arrques, + 'open_answer' => $arrans, + 'answer_type' => $answerType ); - - return $return_array; - } //End function + } /** * Sends a notification when a user ends an examn diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 4b2fe0ff0f..fa80937ffd 100644 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -2134,7 +2134,7 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu //this variable commes from exercise_submit_modal.php ob_start(); - + // We're inside *one* question. Go through each possible answer for this question $result = $objExercise->manage_answer($exercise_stat_info['exe_id'], $questionId, null, 'exercise_result', array(), $save_user_result, true, $show_results, $objExercise->selectPropagateNeg(), $hotspot_delineation_result); if (empty($result)) { diff --git a/main/inc/lib/exercise_show_functions.lib.php b/main/inc/lib/exercise_show_functions.lib.php index 34a6a403cc..034f1a1a23 100644 --- a/main/inc/lib/exercise_show_functions.lib.php +++ b/main/inc/lib/exercise_show_functions.lib.php @@ -56,20 +56,20 @@ class ExerciseShowFunctions { * @return void */ static function display_free_answer($answer, $exe_id, $questionId, $questionScore = null) { - global $feedback_type; - + global $feedback_type; + $comments = get_comments($exe_id, $questionId); - + if (!empty($answer)) { echo ''; echo nl2br(Security::remove_XSS($answer, COURSEMANAGERLOWSECURITY)); echo ''; } - - if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { - if ($questionScore > 0 || !empty($comments)) { + + if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { + if ($questionScore > 0 || !empty($comments)) { } else { - echo ''; + echo ''; echo Display::tag('td', Display::return_message(get_lang('notCorrectedYet')), array()); echo ''; } @@ -277,6 +277,7 @@ class ExerciseShowFunctions { } else { echo '-'; } + ?> @@ -285,7 +286,7 @@ class ExerciseShowFunctions { -