Modify behaviour of setting result_disabled see BT#11202

result disabled value:
RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT
1.10.x
jmontoyaa 10 years ago
parent 748658d204
commit a788c0e861
  1. 180
      main/exercice/exercise.class.php
  2. 90
      main/exercice/exercise_show.php
  3. 17
      main/exercice/fill_blanks.class.php
  4. 2
      main/exercice/overview.php
  5. 29
      main/inc/lib/exercise.lib.php
  6. 178
      main/inc/lib/exercise_show_functions.lib.php

@ -3137,7 +3137,8 @@ class Exercise
$from_database = false,
$show_result = true,
$propagate_neg = 0,
$hotspot_delineation_result = array()
$hotspot_delineation_result = array(),
$showTotalScoreAndUserChoices = false
) {
global $debug;
//needed in order to use in the exercise_attempt() for the time
@ -3279,7 +3280,6 @@ class Exercise
if ($debug) error_log('Start answer loop ');
$answer_correct_array = array();
$orderedHotspots = [];
if ($answerType == HOT_SPOT) {
@ -3300,8 +3300,6 @@ class Exercise
$answerWeighting = (float)$objAnswerTmp->selectWeighting($answerId);
$answerAutoId = $objAnswerTmp->selectAutoId($answerId);
$answer_correct_array[$answerId] = (bool)$answerCorrect;
if ($debug) {
error_log("answer auto id: $answerAutoId ");
error_log("answer correct: $answerCorrect ");
@ -3455,7 +3453,7 @@ class Exercise
$real_answers[$answerId] = false;
}
} else {
$studentChoice = $choice[$answerAutoId];
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : '';
if ($answerCorrect == $studentChoice) {
//$answerCorrect = 1;
$real_answers[$answerId] = true;
@ -3492,7 +3490,6 @@ class Exercise
}
} else {
$studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
if ($answerCorrect == 1) {
if ($studentChoice) {
$real_answers[$answerId] = true;
@ -3512,10 +3509,10 @@ class Exercise
$str = '';
if ($from_database) {
$sql = "SELECT answer
FROM $TBL_TRACK_ATTEMPT
WHERE
exe_id = $exeId AND
question_id= ".intval($questionId);
FROM $TBL_TRACK_ATTEMPT
WHERE
exe_id = $exeId AND
question_id= ".intval($questionId);
$result = Database::query($sql);
$str = Database::result($result, 0, 'answer');
}
@ -3571,9 +3568,9 @@ class Exercise
}
if ($from_database) {
$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
WHERE
exe_id = '".$exeId."' AND
question_id= ".intval($questionId)."";
WHERE
exe_id = '".$exeId."' AND
question_id= ".intval($questionId)."";
$resfill = Database::query($queryfill);
$str = Database::result($resfill, 0, 'answer');
api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
@ -3683,12 +3680,8 @@ class Exercise
// loop other all blanks words
if (!$switchableAnswerSet) {
// not switchable answer, must be in the same place than teacher order
for ($i = 0; $i < count(
$listCorrectAnswers['tabwords']
); $i++) {
$studentAnswer = isset($choice[$i]) ? trim(
$choice[$i]
) : '';
for ($i = 0; $i < count($listCorrectAnswers['tabwords']); $i++) {
$studentAnswer = isset($choice[$i]) ? trim($choice[$i]) : '';
// This value is the user input, not escaped while correct answer is escaped by fckeditor
// Works with cyrillic alphabet and when using ">" chars see #7718 #7610 #7618
@ -3719,16 +3712,12 @@ class Exercise
$listStudentAnswerTemp = $choice;
$listTeacherAnswerTemp = $listCorrectAnswers['tabwords'];
// for every teacher answer, check if there is a student answer
for ($i = 0; $i < count(
$listStudentAnswerTemp
); $i++) {
for ($i = 0; $i < count($listStudentAnswerTemp); $i++) {
$studentAnswer = trim(
$listStudentAnswerTemp[$i]
);
$found = false;
for ($j = 0; $j < count(
$listTeacherAnswerTemp
); $j++) {
for ($j = 0; $j < count($listTeacherAnswerTemp); $j++) {
$correctAnswer = $listTeacherAnswerTemp[$j];
if (!$found) {
if (FillBlanks::isGoodStudentAnswer(
@ -3835,9 +3824,9 @@ class Exercise
if ($from_database && empty($calculatedAnswerId)) {
$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
WHERE
exe_id = '".$exeId."' AND
question_id= ".intval($questionId)."";
WHERE
exe_id = '".$exeId."' AND
question_id= ".intval($questionId)."";
$resfill = Database::query($queryfill);
$answer = Database::result($resfill, 0, 'answer');
}
@ -3870,7 +3859,6 @@ class Exercise
}
}
break;
// for free answer
case FREE_ANSWER:
if ($from_database) {
$query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT."
@ -3892,7 +3880,7 @@ class Exercise
$questionScore = 0;
}
$arrques = $questionName;
$arrans = $choice;
$arrans = $choice;
} else {
$studentChoice = $choice;
if ($studentChoice) {
@ -3911,7 +3899,7 @@ class Exercise
$choice = str_replace('\r\n', '', $choice);
$choice = stripslashes($choice);
$questionScore = Database::result($resq,0,"marks");
if ($questionScore==-1) {
if ($questionScore == -1) {
$totalScore+=0;
} else {
$totalScore+=$questionScore;
@ -4010,12 +3998,15 @@ class Exercise
}
if ($show_result) {
if ($showTotalScoreAndUserChoices == true) {
$user_answer = '';
}
echo '<tr>';
echo '<td>' . $s_answer_label . '</td>';
echo '<td>' . $user_answer;
if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
if (isset($real_list[$i_answer_correct_answer])) {
if (isset($real_list[$i_answer_correct_answer]) && $showTotalScoreAndUserChoices == false) {
echo Display::span(
$real_list[$i_answer_correct_answer],
['style' => 'color: #008000; font-weight: bold;']
@ -4060,8 +4051,8 @@ class Exercise
$studentChoice = Database::result($result, 0, "hotspot_correct");
if ($studentChoice) {
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
}
} else {
if (!isset($choice[$answerAutoId])) {
@ -4095,10 +4086,9 @@ class Exercise
}
$choice[$answerAutoId] = 0;
if ($choiceIsValid) {
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
$choice[$answerAutoId] = 1;
}
}
@ -4157,21 +4147,17 @@ class Exercise
}
}
}
$_SESSION['hotspot_coord'][1] = $delineation_cord;
$_SESSION['hotspot_dest'][1] = $answer_delineation_destination;
$_SESSION['hotspot_coord'][1] = $delineation_cord;
$_SESSION['hotspot_dest'][1] = $answer_delineation_destination;
break;
} // end switch Answertype
if ($show_result) {
if ($debug) error_log('show result '.$show_result);
if ($debug) error_log('Showing questions $from '.$from);
if ($from == 'exercise_result') {
if ($debug) error_log('Showing questions $from '.$from);
//display answers (if not matching type, or if the answer is correct)
// display answers (if not matching type, or if the answer is correct)
if (
!in_array(
$answerType,
[MATCHING, DRAGGABLE, MATCHING_DRAGGABLE]
) ||
!in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE]) ||
$answerCorrect
) {
if (
@ -4187,7 +4173,6 @@ class Exercise
)
)
) {
//if ($origin != 'learnpath') {
ExerciseShowFunctions::display_unique_or_multiple_answer(
$feedback_type,
$answerType,
@ -4198,11 +4183,10 @@ class Exercise
0,
0,
0,
$results_disabled
$results_disabled,
$showTotalScoreAndUserChoices
);
//}
} elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
//if ($origin!='learnpath') {
ExerciseShowFunctions::display_multiple_answer_true_false(
$feedback_type,
$answerType,
@ -4213,11 +4197,10 @@ class Exercise
0,
$questionId,
0,
$results_disabled
$results_disabled,
$showTotalScoreAndUserChoices
);
//}
} elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
// if ($origin!='learnpath') {
} elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
ExerciseShowFunctions::display_multiple_answer_combination_true_false(
$feedback_type,
$answerType,
@ -4228,39 +4211,48 @@ class Exercise
0,
0,
0,
$results_disabled
$results_disabled,
$showTotalScoreAndUserChoices
);
//}
} elseif ($answerType == FILL_IN_BLANKS) {
//if ($origin!='learnpath') {
ExerciseShowFunctions::display_fill_in_blanks_answer($feedback_type, $answer,0,0, $results_disabled);
// }
ExerciseShowFunctions::display_fill_in_blanks_answer(
$feedback_type,
$answer,
0,
0,
$results_disabled,
'',
$showTotalScoreAndUserChoices
);
} elseif ($answerType == CALCULATED_ANSWER) {
//if ($origin!='learnpath') {
ExerciseShowFunctions::display_calculated_answer($feedback_type, $answer,0,0);
// }
ExerciseShowFunctions::display_calculated_answer(
$feedback_type,
$answer,
0,
0,
$results_disabled,
$showTotalScoreAndUserChoices
);
} elseif ($answerType == FREE_ANSWER) {
//if($origin != 'learnpath') {
ExerciseShowFunctions::display_free_answer(
$feedback_type,
$choice,
$exeId,
$questionId,
$questionScore
$questionScore,
$results_disabled
);
//}
} elseif ($answerType == ORAL_EXPRESSION) {
// to store the details of open questions in an array to be used in mail
//if ($origin != 'learnpath') {
ExerciseShowFunctions::display_oral_expression_answer(
$feedback_type,
$choice,
0,
0,
$nano);
//}
$nano,
$results_disabled
);
} elseif ($answerType == HOT_SPOT) {
//if ($origin != 'learnpath') {
foreach ($orderedHotspots as $correctAnswerId => $hotspot) {
if ($hotspot->getHotspotAnswerId() == $answerAutoId) {
break;
@ -4274,11 +4266,10 @@ class Exercise
$studentChoice,
$answerComment,
$results_disabled,
$answerId
$answerId,
$showTotalScoreAndUserChoices
);
// }
} elseif ($answerType == HOT_SPOT_ORDER) {
//if ($origin != 'learnpath') {
ExerciseShowFunctions::display_hotspot_order_answer(
$feedback_type,
$answerId,
@ -4286,7 +4277,6 @@ class Exercise
$studentChoice,
$answerComment
);
//}
} elseif ($answerType == HOT_SPOT_DELINEATION) {
$user_answer = $_SESSION['exerciseResultCoordinates'][$questionId];
@ -4480,7 +4470,8 @@ class Exercise
$exeId,
$questionId,
$answerId,
$results_disabled
$results_disabled,
$showTotalScoreAndUserChoices
);
} else {
ExerciseShowFunctions::display_unique_or_multiple_answer(
@ -4492,8 +4483,9 @@ class Exercise
$answerCorrect,
$exeId,
$questionId,
"",
$results_disabled
'',
$results_disabled,
$showTotalScoreAndUserChoices
);
}
break;
@ -4509,7 +4501,8 @@ class Exercise
$exeId,
$questionId,
$answerId,
$results_disabled
$results_disabled,
$showTotalScoreAndUserChoices
);
} else {
ExerciseShowFunctions::display_multiple_answer_combination_true_false(
@ -4521,8 +4514,9 @@ class Exercise
$answerCorrect,
$exeId,
$questionId,
"",
$results_disabled
'',
$results_disabled,
$showTotalScoreAndUserChoices
);
}
break;
@ -4538,7 +4532,8 @@ class Exercise
$exeId,
$questionId,
$answerId,
$results_disabled
$results_disabled,
$showTotalScoreAndUserChoices
);
} else {
ExerciseShowFunctions::display_multiple_answer_true_false(
@ -4550,8 +4545,9 @@ class Exercise
$answerCorrect,
$exeId,
$questionId,
"",
$results_disabled
'',
$results_disabled,
$showTotalScoreAndUserChoices
);
}
break;
@ -4562,7 +4558,8 @@ class Exercise
$exeId,
$questionId,
$results_disabled,
$str
$str,
$showTotalScoreAndUserChoices
);
break;
case CALCULATED_ANSWER:
@ -4570,7 +4567,10 @@ class Exercise
$feedback_type,
$answer,
$exeId,
$questionId
$questionId,
$results_disabled,
'',
$showTotalScoreAndUserChoices
);
break;
case FREE_ANSWER:
@ -4579,7 +4579,8 @@ class Exercise
$choice,
$exeId,
$questionId,
$questionScore
$questionScore,
$results_disabled
);
break;
case ORAL_EXPRESSION:
@ -4589,7 +4590,8 @@ class Exercise
$choice,
$exeId,
$questionId,
$nano
$nano,
$results_disabled
) . '</td>
</tr>
</table>';
@ -4601,7 +4603,8 @@ class Exercise
$answer,
$studentChoice,
$answerComment,
$results_disabled);
$results_disabled
);
break;
case HOT_SPOT_DELINEATION:
$user_answer = $user_array;
@ -6606,7 +6609,6 @@ class Exercise
foreach ($questionList as $questionId) {
$i++;
// For sequential exercises
if ($this->type == ONE_PER_PAGE) {
// If it is not the right question, goes to the next loop iteration
if ($currentQuestion != $i) {
@ -7428,7 +7430,6 @@ class Exercise
$selected = 'selected="selected"';
$selectedValue = $val['id'];
}
//$s .= '<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].'</option>';
$s .= '<option value="'.$item.'" '.$selected.'>'.$val['letter'].'</option>';
$item++;
}
@ -7442,7 +7443,6 @@ class Exercise
</script>';
}
if (isset($select_items[$lines_count])) {
$s.= '<div id="window_'.$windowId.'_answer" class="">
<b>'.$select_items[$lines_count]['letter'].'.</b> '.$select_items[$lines_count]['answer'].'

@ -174,14 +174,16 @@ function getFCK(vals,marksid) {
<?php
$show_results = true;
$show_only_total_score = false;
$showTotalScoreAndUserChoices = true;
// Avoiding the "Score 0/0" message when the exe_id is not set
if (!empty($track_exercise_info)) {
// if the results_disabled of the Quiz is 1 when block the script
$result_disabled = $track_exercise_info['results_disabled'];
$result_disabled = $track_exercise_info['results_disabled'];
if (!(api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) ) {
if ($result_disabled == 1) {
if (true) {
//if (!(api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) ) {
if ($result_disabled == RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS) {
$show_results = false;
if ($origin != 'learnpath') {
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
@ -195,7 +197,7 @@ if (!empty($track_exercise_info)) {
</tr>
</table>';
}
} elseif ($result_disabled == 2) {
} elseif ($result_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY) {
$show_results = false;
$show_only_total_score = true;
if ($origin != 'learnpath') {
@ -207,6 +209,26 @@ if (!empty($track_exercise_info)) {
</tr>
</table>';
}
} elseif ($result_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
$attempts = Event::getExerciseResultsByUser(
api_get_user_id(),
$objExercise->id,
api_get_course_int_id(),
api_get_session_id(),
$track_exercise_info['orig_lp_id'],
$track_exercise_info['orig_lp_item_id'],
'desc'
);
$numberAttempts = count($attempts);
if ($numberAttempts >= $track_exercise_info['max_attempt']) {
$show_results = true;
$show_only_total_score = true;
$showTotalScoreAndUserChoices = false;
} else {
$show_results = true;
$show_only_total_score = true;
$showTotalScoreAndUserChoices = true;
}
}
}
} else {
@ -218,7 +240,7 @@ if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
$show_results = false;
}
if ($show_results || $show_only_total_score) {
if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices) {
$user_info = api_get_user_info($student_id);
//Shows exercise header
echo $objExercise->show_exercise_result_header(
@ -237,7 +259,7 @@ if ($debug > 0) {
}
$arrques = array();
$arrans = array();
$arrans = array();
$user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($student_id)." ";
$sql = "SELECT attempts.question_id, answer
@ -320,9 +342,7 @@ foreach ($questionList as $questionId) {
// Start buffer
ob_start();
/* Use switch
switch ($answerType) {
}*/
// Use switch
if ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
$question_result = $objExercise->manage_answer(
@ -334,7 +354,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -349,7 +371,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -363,7 +387,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -378,7 +404,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -392,7 +420,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -406,7 +436,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -420,7 +452,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -434,7 +468,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -448,12 +484,14 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
} elseif ($answerType == HOT_SPOT) {
if ($show_results) {
if ($show_results || $showTotalScoreAndUserChoices) {
echo '<table width="500" border="0"><tr>
<td valign="top" align="center" style="padding-left:0px;" >
<table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
@ -467,7 +505,9 @@ foreach ($questionList as $questionId) {
false,
true,
$show_results,
$objExercise->selectPropagateNeg()
$objExercise->selectPropagateNeg(),
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -508,7 +548,9 @@ foreach ($questionList as $questionId) {
true,
$show_results,
$objExercise->selectPropagateNeg(),
'database'
'database',
[],
$showTotalScoreAndUserChoices
);
$questionScore = $question_result['score'];
@ -776,7 +818,7 @@ foreach ($questionList as $questionId) {
}
}
$my_total_score = $questionScore;
$my_total_score = $questionScore;
$my_total_weight = $questionWeighting;
$totalWeighting += $questionWeighting;
$category_was_added_for_this_test = false;
@ -850,7 +892,7 @@ $total_score_text = null;
//Total score
if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
if ($show_results || $show_only_total_score) {
if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices) {
$total_score_text .= '<div class="question_row">';
$my_total_score_temp = $totalScore;
if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
@ -866,7 +908,7 @@ if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type'])))
}
}
if (!empty($category_list) && ($show_results || $show_only_total_score)) {
if (!empty($category_list) && ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices)) {
// Adding total
$category_list['total'] = array(
'score' => $my_total_score_temp,

@ -725,7 +725,7 @@ class FillBlanks extends Question
return $listAnswerResults;
}
/**
* Return an array of student state answers for fill the blank questions
* for each students that answered the question
@ -1037,14 +1037,23 @@ class FillBlanks extends Question
* return the HTML display of the answer
* @param string $answer
* @param bool $resultsDisabled
* @param bool $showTotalScoreAndUserChoices
*
* @return string
*/
public static function getHtmlDisplayForAnswer($answer, $resultsDisabled = false)
public static function getHtmlDisplayForAnswer($answer, $resultsDisabled = false, $showTotalScoreAndUserChoices = false)
{
$result = "";
$result = '';
$listStudentAnswerInfo = self::getAnswerInfo($answer, true);
if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
if ($showTotalScoreAndUserChoices) {
$resultsDisabled = true;
} else {
$resultsDisabled = false;
}
}
// rebuild the answer with good HTML style
// this is the student answer, right or wrong
for ($i=0; $i < count($listStudentAnswerInfo['studentanswer']); $i++) {
@ -1094,7 +1103,7 @@ class FillBlanks extends Question
$type = FillBlanks::getFillTheBlankAnswerType($correct);
switch ($type) {
case self::FILL_THE_BLANK_MENU:
$correctAnswerHtml = "";
$correctAnswerHtml = '';
$listPossibleAnswers = FillBlanks::getFillTheBlankMenuAnswers($correct, false);
$correctAnswerHtml .= "<span style='color: green'>".$listPossibleAnswers[0]."</span>";
$correctAnswerHtml .= " <span style='font-weight:normal'>(";

@ -171,7 +171,7 @@ if ($current_browser == 'Internet Explorer') {
$blockShowAnswers = false;
if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
if (count($attempts) < $objExercise->attempts ) {
if (count($attempts) < $objExercise->attempts) {
$blockShowAnswers = true;
}
}

@ -3500,8 +3500,11 @@ HOTSPOT;
$show_only_score = false;
}
$show_total_score_and_user_choices = false;
if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
$show_only_score = true;
$show_results = true;
if ($objExercise->attempts > 0) {
$attempts = Event::getExerciseResultsByUser(
api_get_user_id(),
@ -3521,7 +3524,10 @@ HOTSPOT;
if ($numberAttempts >= $objExercise->attempts) {
$show_results = true;
$show_only_score = false;
};
$show_total_score_and_user_choices = false;
} else {
$show_total_score_and_user_choices = true;
}
}
}
}
@ -3540,7 +3546,6 @@ HOTSPOT;
);
}
// Display text when test is finished #4074 and for LP #4227
$end_of_message = $objExercise->selectTextWhenFinished();
if (!empty($end_of_message)) {
@ -3558,7 +3563,7 @@ HOTSPOT;
// creates a temporary Question object
$objQuestionTmp = Question::read($questionId);
// This variable came from exercise_submit_modal.php
ob_start();
@ -3568,23 +3573,19 @@ HOTSPOT;
$questionId,
null,
'exercise_result',
array(),
[],
$save_user_result,
true,
$show_results,
$objExercise->selectPropagateNeg(),
array()
[],
$show_total_score_and_user_choices
);
if (empty($result)) {
continue;
}
// In case of global score, make sure the calculated total score is integer
/*if (!is_int($result['score'])) {
$result['score'] = round($result['score']);
}*/
$total_score += $result['score'];
$total_weight += $result['weight'];
@ -3670,13 +3671,7 @@ HOTSPOT;
$question_content = '';
if ($show_results) {
$question_content = '<div class="question_row_answer">';
$show_media = false;
/*if ($objQuestionTmp->parent_id != 0 && !in_array($objQuestionTmp->parent_id, $media_list)) {
$show_media = true;
$media_list[] = $objQuestionTmp->parent_id;
}*/
//Shows question title an description
// Shows question title an description
$question_content .= $objQuestionTmp->return_header(
null,
$counter,

@ -4,8 +4,8 @@
* EVENTS LIBRARY
*
* This is the events library for Chamilo.
* Functions of this library are used to record informations when some kind
* of event occur. Each event has his own types of informations then each event
* Functions of this library are used to record information when some kind
* of event occur.
* use its own function.
*
* @package chamilo.library
@ -19,16 +19,25 @@ class ExerciseShowFunctions
{
/**
* Shows the answer to a fill-in-the-blanks question, as HTML
* @param string Answer text
* @param int Exercise ID
* @param int Question ID
* @param int $feedbackType
* @param string $answer
* @param int $id Exercise ID
* @param int $questionId Question ID
* @param int $resultsDisabled
* @param string $originalStudentAnswer
*
* @return void
*/
public static function display_fill_in_blanks_answer($feedbackType, $answer, $id, $questionId, $resultsDisabled, $originalStudentAnswer = '')
{
$answerHTML = FillBlanks::getHtmlDisplayForAnswer($answer, $resultsDisabled);
public static function display_fill_in_blanks_answer(
$feedbackType,
$answer,
$id,
$questionId,
$resultsDisabled,
$originalStudentAnswer = '',
$showTotalScoreAndUserChoices
) {
$answerHTML = FillBlanks::getHtmlDisplayForAnswer($answer, $resultsDisabled, $showTotalScoreAndUserChoices);
if (strpos($originalStudentAnswer, 'font color') !== false) {
$answerHTML = $originalStudentAnswer;
}
@ -47,9 +56,9 @@ class ExerciseShowFunctions
<?php
if (!api_is_allowed_to_edit(null,true) && $feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
<td>
<?php
$comm = Event::get_comments($id, $questionId);
?>
<?php
$comm = Event::get_comments($id, $questionId);
?>
</td>
<?php } ?>
</tr>
@ -64,8 +73,14 @@ class ExerciseShowFunctions
* @param int Question ID
* @return void
*/
public static function display_calculated_answer($feedback_type, $answer, $id, $questionId)
{
public static function display_calculated_answer(
$feedback_type,
$answer,
$id,
$questionId,
$results_disabled,
$showTotalScoreAndUserChoices
) {
if (empty($id)) {
echo '<tr><td>'. Security::remove_XSS($answer).'</td></tr>';
} else {
@ -97,8 +112,14 @@ class ExerciseShowFunctions
* @param int Question ID
* @return void
*/
public static function display_free_answer($feedback_type, $answer, $exe_id, $questionId, $questionScore = null)
{
public static function display_free_answer(
$feedback_type,
$answer,
$exe_id,
$questionId,
$questionScore = null,
$results_disabled = 0
) {
$comments = Event::get_comments($exe_id, $questionId);
if (!empty($answer)) {
@ -117,8 +138,22 @@ class ExerciseShowFunctions
}
}
public static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $nano = null)
{
/**
* @param $feedback_type
* @param $answer
* @param $id
* @param $questionId
* @param null $nano
* @param int $results_disabled
*/
public static function display_oral_expression_answer(
$feedback_type,
$answer,
$id,
$questionId,
$nano = null,
$results_disabled = 0
) {
if (isset($nano)) {
echo $nano->show_audio_file();
}
@ -158,7 +193,7 @@ class ExerciseShowFunctions
* @param string $answer
* @param string $studentChoice
* @param string $answerComment
* @param string $in_results_disabled
* @param int $resultsDisabled
* @param int $orderColor
*/
public static function display_hotspot_answer(
@ -167,15 +202,23 @@ class ExerciseShowFunctions
$answer,
$studentChoice,
$answerComment,
$in_results_disabled,
$orderColor
)
{
$resultsDisabled,
$orderColor,
$showTotalScoreAndUserChoices
) {
$hide_expected_answer = false;
if ($feedback_type == 0 && $in_results_disabled == 2) {
if ($feedback_type == 0 && $resultsDisabled == 2) {
$hide_expected_answer = true;
}
if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
if ($showTotalScoreAndUserChoices) {
$hide_expected_answer = true;
} else {
$hide_expected_answer = false;
}
}
$hotspot_colors = array(
"", // $i starts from 1 on next loop (ugly fix)
"#4271B5",
@ -190,7 +233,9 @@ class ExerciseShowFunctions
"#F4EB24",
"#ED2024",
"#3B3B3B",
"#F7BDE2");
"#F7BDE2"
);
?>
<table class="data_table">
<tr>
@ -203,7 +248,7 @@ class ExerciseShowFunctions
<td class="text-left" width="10%">
<?php
if (!$hide_expected_answer) {
$my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault');
$my_choice = $studentChoice ? get_lang('Correct') : get_lang('Fault');
echo $my_choice;
}
?>
@ -246,19 +291,29 @@ class ExerciseShowFunctions
$id,
$questionId,
$ans,
$in_results_disabled
$resultsDisabled,
$showTotalScoreAndUserChoices
) {
$hide_expected_answer = false;
if ($feedback_type == 0 && $in_results_disabled == 2) {
if ($feedback_type == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) {
$hide_expected_answer = true;
}
if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
if ($showTotalScoreAndUserChoices) {
$hide_expected_answer = true;
} else {
$hide_expected_answer = false;
}
}
$icon = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
$icon .= $studentChoice?'_on':'_off';
$icon .= '.gif';
$iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
$iconAnswer .= $answerCorrect?'_on':'_off';
$iconAnswer .= $answerCorrect ? '_on' : '_off';
$iconAnswer .= '.gif';
?>
@ -290,14 +345,10 @@ class ExerciseShowFunctions
$color = 'black';
//echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
}
echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
} else {
if ($answerCorrect) {
//echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
} else {
//echo '<span style="font-weight: normal; color: #000;">'.nl2br($answerComment).'</span>';
if ($hide_expected_answer) {
$color = '';
}
echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
}
?>
</td>
@ -336,19 +387,28 @@ class ExerciseShowFunctions
$id,
$questionId,
$ans,
$in_results_disabled
$resultsDisabled,
$showTotalScoreAndUserChoices
) {
$hide_expected_answer = false;
if ($feedback_type == 0 && $in_results_disabled == 2) {
if ($feedback_type == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) {
$hide_expected_answer = true;
}
if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
if ($showTotalScoreAndUserChoices) {
$hide_expected_answer = true;
} else {
$hide_expected_answer = false;
}
}
?>
<tr>
<td width="5%">
<?php
$question = new MultipleAnswerTrueFalse();
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
$new_options = Question::readQuestionOption($questionId, $course_id);
//Your choice
@ -363,7 +423,7 @@ class ExerciseShowFunctions
<td width="5%">
<?php
//Expected choice
// Expected choice
if (!$hide_expected_answer) {
if (isset($new_options[$answerCorrect])) {
echo get_lang($new_options[$answerCorrect]['name']);
@ -387,6 +447,11 @@ class ExerciseShowFunctions
if ($studentChoice == $answerCorrect) {
$color = "green";
}
if ($hide_expected_answer) {
$color = '';
}
echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
}
?>
@ -416,7 +481,7 @@ class ExerciseShowFunctions
* @param boolean Whether to show the answer comment or not
* @return void
*/
static function display_multiple_answer_combination_true_false(
public static function display_multiple_answer_combination_true_false(
$feedback_type,
$answerType,
$studentChoice,
@ -426,12 +491,22 @@ class ExerciseShowFunctions
$id,
$questionId,
$ans,
$in_results_disabled
$resultsDisabled,
$showTotalScoreAndUserChoices
) {
$hide_expected_answer = false;
if ($feedback_type == 0 && $in_results_disabled == 2) {
if ($feedback_type == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) {
$hide_expected_answer = true;
}
if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
if ($showTotalScoreAndUserChoices) {
$hide_expected_answer = true;
} else {
$hide_expected_answer = false;
}
}
?>
<tr>
<td width="5%">
@ -447,7 +522,7 @@ class ExerciseShowFunctions
</td>
<td width="5%">
<?php
//Expected choice
// Expected choice
if (!$hide_expected_answer) {
if (isset($question->options[$answerCorrect])) {
echo $question->options[$answerCorrect];
@ -476,17 +551,12 @@ class ExerciseShowFunctions
if ($studentChoice == $answerCorrect) {
$color = "green";
}
if ($hide_expected_answer) {
$color = '';
}
echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
}
if ($studentChoice == 2 || $studentChoice == '') {
//echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
} else {
if ($studentChoice == $answerCorrect) {
//echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
} else {
//echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
}
}
?>
</td>
<?php

Loading…
Cancel
Save