';
$content .= '';
$content .= '';
$content .= ' | ';
$content .= '';
$content .= "$answerId - $answer";
$content .= ' | ';
$content .= '';
if (!$hide_expected_answer) {
$status = Display::label(get_lang('Incorrect'), 'danger');
if ($studentChoice) {
$status = Display::label(get_lang('Correct'), 'success');
} else {
if (in_array($resultsDisabled, [
RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
])
) {
return '';
}
}
$content .= $status;
}
$content .= ' | ';
if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
$content .= '';
if ($studentChoice) {
$content .= ''.nl2br($answerComment).'';
}
$content .= ' | ';
} else {
$content .= ' | ';
}
$content .= '
';
echo $content;
}
/**
* Display the answers to a multiple choice question.
*
* @param Exercise $exercise
* @param int $feedbackType Feedback type
* @param int $answerType Answer type
* @param int $studentChoice Student choice
* @param string $answer Textual answer
* @param string $answerComment Comment on answer
* @param string $answerCorrect Correct answer comment
* @param int $id Exercise ID
* @param int $questionId Question ID
* @param bool $ans Whether to show the answer comment or not
* @param bool $resultsDisabled
* @param bool $showTotalScoreAndUserChoices
* @param bool $export
*/
public static function display_unique_or_multiple_answer(
$exercise,
$feedbackType,
$answerType,
$studentChoice,
$answer,
$answerComment,
$answerCorrect,
$id,
$questionId,
$ans,
$resultsDisabled,
$showTotalScoreAndUserChoices,
$export = false
) {
if ($export) {
$answer = strip_tags_blacklist($answer, ['title', 'head']);
// Fix answers that contains this tags
$tags = [
'',
'',
'',
'',
];
$answer = str_replace($tags, '', $answer);
}
$studentChoiceInt = (int) $studentChoice;
$answerCorrectChoice = (int) $answerCorrect;
$hideStudentChoice = false;
$hide_expected_answer = false;
$status = '';
if ($exercise->showExpectedChoice()) {
$status = Display::label(get_lang('Incorrect'), 'danger');
if ($answerCorrect || ($answerCorrect && $studentChoiceInt === $answerCorrectChoice)) {
$status = Display::label(get_lang('Correct'), 'success');
}
}
$showComment = false;
switch ($resultsDisabled) {
case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
//case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
$hideStudentChoice = false;
$hide_expected_answer = true;
$status = Display::label(get_lang('Correct'), 'success');
$showComment = true;
if (!$answerCorrect && empty($studentChoice)) {
return '';
}
break;
case RESULT_DISABLE_SHOW_SCORE_ONLY:
if ($feedbackType == 0) {
$hide_expected_answer = true;
}
break;
case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
$hide_expected_answer = true;
if ($showTotalScoreAndUserChoices) {
$hide_expected_answer = false;
}
break;
}
$icon = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
$icon .= $studentChoice ? '_on' : '_off';
$icon .= '.png';
$iconAnswer = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
$iconAnswer .= $answerCorrect ? '_on' : '_off';
$iconAnswer .= '.png';
$studentChoiceClass = '';
if (in_array($resultsDisabled, [
RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
])
) {
if ($answerCorrect) {
$studentChoiceClass = 'success';
}
}
echo '';
if ($hideStudentChoice === false) {
echo '';
echo Display::return_icon($icon, null, null, ICON_SIZE_TINY);
echo ' | ';
}
if (!$hide_expected_answer) {
echo '';
echo Display::return_icon($iconAnswer, null, null, ICON_SIZE_TINY);
echo ' | ';
}
echo '';
echo $answer;
echo ' | ';
if ($exercise->showExpectedChoice()) {
echo '';
echo $status;
echo ' | ';
}
if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
$showComment = true;
}
if ($showComment) {
echo '';
$color = 'black';
if ($answerCorrect) {
$color = 'green';
}
if ($hide_expected_answer) {
$color = '';
}
$comment = ''.
Security::remove_XSS($answerComment).
'';
echo $comment;
echo ' | ';
} else {
echo ' | ';
}
echo '
';
}
/**
* Display the answers to a multiple choice question.
*
* @param Exercise $exercise
* @param int Answer type
* @param int Student choice
* @param string Textual answer
* @param string Comment on answer
* @param string Correct answer comment
* @param int Exercise ID
* @param int Question ID
* @param bool Whether to show the answer comment or not
*/
public static function display_multiple_answer_true_false(
$exercise,
$feedbackType,
$answerType,
$studentChoice,
$answer,
$answerComment,
$answerCorrect,
$id,
$questionId,
$ans,
$resultsDisabled,
$showTotalScoreAndUserChoices
) {
$hide_expected_answer = false;
$hideStudentChoice = false;
switch ($resultsDisabled) {
//case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
$hideStudentChoice = false;
$hide_expected_answer = true;
break;
case RESULT_DISABLE_SHOW_SCORE_ONLY:
if ($feedbackType == 0) {
$hide_expected_answer = true;
}
break;
case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
$hide_expected_answer = true;
if ($showTotalScoreAndUserChoices) {
$hide_expected_answer = false;
}
break;
}
$content = '';
if ($hideStudentChoice === false) {
$content .= '';
$course_id = api_get_course_int_id();
$new_options = Question::readQuestionOption($questionId, $course_id);
// Your choice
if (isset($new_options[$studentChoice])) {
$content .= get_lang($new_options[$studentChoice]['name']);
} else {
$content .= '-';
}
$content .= ' | ';
}
// Expected choice
if (!$hide_expected_answer) {
$content .= '';
if (isset($new_options[$answerCorrect])) {
$content .= get_lang($new_options[$answerCorrect]['name']);
} else {
$content .= '-';
}
$content .= ' | ';
}
$content .= '';
$content .= $answer;
$content .= ' | ';
if ($exercise->showExpectedChoice()) {
$status = Display::label(get_lang('Incorrect'), 'danger');
if (isset($new_options[$studentChoice])) {
if ($studentChoice == $answerCorrect) {
$status = Display::label(get_lang('Correct'), 'success');
}
}
$content .= '';
$content .= $status;
$content .= ' | ';
}
if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
$content .= '';
$color = 'black';
if (isset($new_options[$studentChoice]) || in_array(
$exercise->results_disabled,
[
RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
]
)
) {
if ($studentChoice == $answerCorrect) {
$color = 'green';
}
if ($hide_expected_answer) {
$color = '';
}
$content .= ''.nl2br($answerComment).'';
}
$content .= ' | ';
}
$content .= '
';
echo $content;
}
/**
* Display the answers to a multiple choice question.
*
* @param int $feedbackType
* @param int $studentChoice
* @param int $studentChoiceDegree
* @param string $answer
* @param string $answerComment
* @param int $answerCorrect
* @param int $questionId
* @param bool $inResultsDisabled
*/
public static function displayMultipleAnswerTrueFalseDegreeCertainty(
$feedbackType,
$studentChoice,
$studentChoiceDegree,
$answer,
$answerComment,
$answerCorrect,
$questionId,
$inResultsDisabled
) {
$hideExpectedAnswer = false;
if ($feedbackType == 0 && $inResultsDisabled == 2) {
$hideExpectedAnswer = true;
}
echo '';
$question = new MultipleAnswerTrueFalseDegreeCertainty();
$courseId = api_get_course_int_id();
$newOptions = Question::readQuestionOption($questionId, $courseId);
//Your choice
if (isset($newOptions[$studentChoice])) {
echo get_lang($newOptions[$studentChoice]['name']);
} else {
echo '-';
}
echo ' | ';
// Expected choice
if (!$hideExpectedAnswer) {
if (isset($newOptions[$answerCorrect])) {
echo get_lang($newOptions[$answerCorrect]['name']);
} else {
echo '-';
}
} else {
echo '-';
}
echo ' | ';
echo $answer;
echo ' | ';
if (isset($newOptions[$studentChoiceDegree])) {
echo $newOptions[$studentChoiceDegree]['name'];
}
echo ' | ';
$degreeInfo = $question->getResponseDegreeInfo(
$studentChoice,
$answerCorrect,
$newOptions[$studentChoiceDegree]['position']
);
echo '
'.
nl2br($degreeInfo['label']).
'
| ';
if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
echo '';
if (isset($newOptions[$studentChoice])) {
echo ''.nl2br($answerComment).'';
}
echo ' | ';
} else {
echo ' | ';
}
echo '
';
}
/**
* Display the answers to a multiple choice question.
*
* @param Exercise $exercise
* @param int Answer type
* @param int Student choice
* @param string Textual answer
* @param string Comment on answer
* @param string Correct answer comment
* @param int Exercise ID
* @param int Question ID
* @param bool Whether to show the answer comment or not
*/
public static function display_multiple_answer_combination_true_false(
$exercise,
$feedbackType,
$answerType,
$studentChoice,
$answer,
$answerComment,
$answerCorrect,
$id,
$questionId,
$ans,
$resultsDisabled,
$showTotalScoreAndUserChoices
) {
$hide_expected_answer = false;
$hideStudentChoice = false;
switch ($resultsDisabled) {
case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
$hideStudentChoice = true;
$hide_expected_answer = true;
break;
case RESULT_DISABLE_SHOW_SCORE_ONLY:
if ($feedbackType == 0) {
$hide_expected_answer = true;
}
break;
case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
$hide_expected_answer = true;
if ($showTotalScoreAndUserChoices) {
$hide_expected_answer = false;
}
break;
}
echo '';
if ($hideStudentChoice === false) {
echo '';
// Your choice
$question = new MultipleAnswerCombinationTrueFalse();
if (isset($question->options[$studentChoice])) {
echo $question->options[$studentChoice];
} else {
echo $question->options[2];
}
echo ' | ';
}
// Expected choice
if (!$hide_expected_answer) {
echo '';
if (isset($question->options[$answerCorrect])) {
echo $question->options[$answerCorrect];
} else {
echo $question->options[2];
}
echo ' | ';
}
echo '';
echo $answer;
echo ' | ';
if ($exercise->showExpectedChoice()) {
$status = '';
if (isset($studentChoice)) {
$status = Display::label(get_lang('Incorrect'), 'danger');
if ($studentChoice == $answerCorrect) {
$status = Display::label(get_lang('Correct'), 'success');
}
}
echo '';
echo $status;
echo ' | ';
}
if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
echo '';
//@todo replace this harcoded value
if ($studentChoice || in_array($resultsDisabled, [
RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER,
RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING,
])
) {
$color = 'black';
if ($studentChoice == $answerCorrect) {
$color = 'green';
}
if ($hide_expected_answer) {
$color = '';
}
echo ''.nl2br($answerComment).'';
}
echo ' | ';
} else {
echo ' | ';
}
echo '
';
}
/**
* @param $feedbackType
* @param $exe_id
* @param $questionId
* @param null $questionScore
* @param int $resultsDisabled
*/
public static function displayAnnotationAnswer(
$feedbackType,
$exe_id,
$questionId,
$questionScore = null,
$resultsDisabled = 0
) {
$comments = Event::get_comments($exe_id, $questionId);
if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
if ($questionScore <= 0 && empty($comments)) {
echo '
'.ExerciseLib::getNotCorrectedYetText();
}
}
}
}