exercise_show_functions.lib.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. <?php
  2. /* See license terms in /license.txt */
  3. /**
  4. * EVENTS LIBRARY.
  5. *
  6. * This is the events library for Chamilo.
  7. * Functions of this library are used to record informations when some kind
  8. * of event occur. Each event has his own types of informations then each event
  9. * use its own function.
  10. *
  11. * @package chamilo.library
  12. *
  13. * @todo convert queries to use Database API
  14. */
  15. /**
  16. * Class.
  17. *
  18. * @package chamilo.library
  19. */
  20. class ExerciseShowFunctions
  21. {
  22. /**
  23. * Shows the answer to a fill-in-the-blanks question, as HTML.
  24. *
  25. * @param int $feedbackType
  26. * @param string $answer
  27. * @param int $id Exercise ID
  28. * @param int $questionId Question ID
  29. * @param int $resultsDisabled
  30. * @param string $originalStudentAnswer
  31. * @param bool $showTotalScoreAndUserChoices
  32. */
  33. public static function display_fill_in_blanks_answer(
  34. $feedbackType,
  35. $answer,
  36. $id,
  37. $questionId,
  38. $resultsDisabled,
  39. $originalStudentAnswer = '',
  40. $showTotalScoreAndUserChoices
  41. ) {
  42. $answerHTML = FillBlanks::getHtmlDisplayForAnswer(
  43. $answer,
  44. $feedbackType,
  45. $resultsDisabled,
  46. $showTotalScoreAndUserChoices
  47. );
  48. if (empty($id)) {
  49. echo '<tr><td>';
  50. echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
  51. echo '</td></tr>';
  52. } else {
  53. echo '<tr><td>';
  54. echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
  55. echo '</td>';
  56. echo '</tr>';
  57. }
  58. }
  59. /**
  60. * Shows the answer to a calculated question, as HTML.
  61. *
  62. * @param Exercise $exercise
  63. * @param string Answer text
  64. * @param int Exercise ID
  65. * @param int Question ID
  66. */
  67. public static function display_calculated_answer(
  68. $exercise,
  69. $feedback_type,
  70. $answer,
  71. $id,
  72. $questionId,
  73. $resultsDisabled,
  74. $showTotalScoreAndUserChoices,
  75. $expectedChoice = '',
  76. $choice = '',
  77. $status = ''
  78. ) {
  79. if ($exercise->showExpectedChoice()) {
  80. if (empty($id)) {
  81. echo '<tr><td>'.Security::remove_XSS($answer).'</td>';
  82. echo '<td>'.Security::remove_XSS($choice).'</td>';
  83. echo '<td>'.Security::remove_XSS($expectedChoice).'</td>';
  84. echo '<td>'.Security::remove_XSS($status).'</td>';
  85. echo '</tr>';
  86. } else {
  87. echo '<tr><td>';
  88. echo Security::remove_XSS($answer);
  89. echo '</td><td>';
  90. echo Security::remove_XSS($choice);
  91. echo '</td><td>';
  92. echo Security::remove_XSS($expectedChoice);
  93. echo '</td><td>';
  94. echo Security::remove_XSS($status);
  95. echo '</td>';
  96. echo '</tr>';
  97. }
  98. } else {
  99. if (empty($id)) {
  100. echo '<tr><td>'.Security::remove_XSS($answer).'</td></tr>';
  101. } else {
  102. echo '<tr><td>';
  103. echo Security::remove_XSS($answer);
  104. echo '</tr>';
  105. }
  106. }
  107. }
  108. /**
  109. * Shows the answer to a free-answer question, as HTML.
  110. *
  111. * @param string Answer text
  112. * @param int Exercise ID
  113. * @param int Question ID
  114. */
  115. public static function display_free_answer(
  116. $feedback_type,
  117. $answer,
  118. $exe_id,
  119. $questionId,
  120. $questionScore = null,
  121. $resultsDisabled = 0
  122. ) {
  123. $comments = Event::get_comments($exe_id, $questionId);
  124. if (!empty($answer)) {
  125. echo '<tr><td>';
  126. echo Security::remove_XSS($answer);
  127. echo '</td></tr>';
  128. }
  129. if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  130. if ($questionScore > 0 || !empty($comments)) {
  131. } else {
  132. echo '<tr>';
  133. echo Display::tag('td', ExerciseLib::getNotCorrectedYetText(), []);
  134. echo '</tr>';
  135. }
  136. }
  137. }
  138. /**
  139. * @param $feedback_type
  140. * @param $answer
  141. * @param $id
  142. * @param $questionId
  143. * @param null $fileUrl
  144. * @param int $resultsDisabled
  145. * @param int $questionScore
  146. */
  147. public static function display_oral_expression_answer(
  148. $feedback_type,
  149. $answer,
  150. $id,
  151. $questionId,
  152. $fileUrl = null,
  153. $resultsDisabled = 0,
  154. $questionScore = 0
  155. ) {
  156. if (isset($fileUrl)) {
  157. echo '
  158. <tr>
  159. <td><audio src="'.$fileUrl.'" controls></audio></td>
  160. </tr>
  161. ';
  162. }
  163. if (empty($id)) {
  164. echo '<tr>';
  165. if (!empty($answer)) {
  166. echo Display::tag('td', Security::remove_XSS($answer), ['width' => '55%']);
  167. }
  168. echo '</tr>';
  169. if (!$questionScore && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  170. echo '<tr>';
  171. echo Display::tag('td', ExerciseLib::getNotCorrectedYetText(), ['width' => '45%']);
  172. echo '</tr>';
  173. } else {
  174. echo '<tr><td>&nbsp;</td></tr>';
  175. }
  176. } else {
  177. echo '<tr>';
  178. echo '<td>';
  179. if (!empty($answer)) {
  180. echo Security::remove_XSS($answer);
  181. }
  182. echo '</td>';
  183. echo '</tr>';
  184. }
  185. }
  186. /**
  187. * Displays the answer to a hotspot question.
  188. *
  189. * @param int $feedback_type
  190. * @param int $answerId
  191. * @param string $answer
  192. * @param string $studentChoice
  193. * @param string $answerComment
  194. * @param int $resultsDisabled
  195. * @param int $orderColor
  196. * @param bool $showTotalScoreAndUserChoices
  197. */
  198. public static function display_hotspot_answer(
  199. $feedback_type,
  200. $answerId,
  201. $answer,
  202. $studentChoice,
  203. $answerComment,
  204. $resultsDisabled,
  205. $orderColor,
  206. $showTotalScoreAndUserChoices
  207. ) {
  208. $hide_expected_answer = false;
  209. switch ($resultsDisabled) {
  210. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  211. if ($feedback_type == 0) {
  212. $hide_expected_answer = true;
  213. }
  214. break;
  215. case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
  216. case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
  217. $hide_expected_answer = true;
  218. if ($showTotalScoreAndUserChoices) {
  219. $hide_expected_answer = false;
  220. }
  221. break;
  222. }
  223. $hotspot_colors = [
  224. '', // $i starts from 1 on next loop (ugly fix)
  225. '#4271B5',
  226. '#FE8E16',
  227. '#45C7F0',
  228. '#BCD631',
  229. '#D63173',
  230. '#D7D7D7',
  231. '#90AFDD',
  232. '#AF8640',
  233. '#4F9242',
  234. '#F4EB24',
  235. '#ED2024',
  236. '#3B3B3B',
  237. '#F7BDE2',
  238. ];
  239. $content = '<table class="data_table"><tr>';
  240. $content .= '<td class="text-center" width="5%">';
  241. $content .= '<span class="fa fa-square fa-fw fa-2x" aria-hidden="true" style="color:'.
  242. $hotspot_colors[$orderColor].'"></span>';
  243. $content .= '</td>';
  244. $content .= '<td class="text-left" width="25%">';
  245. $content .= "$answerId - $answer";
  246. $content .= '</td>';
  247. $content .= '<td class="text-left" width="10%">';
  248. if (!$hide_expected_answer) {
  249. $status = Display::label(get_lang('Incorrect'), 'danger');
  250. if ($studentChoice) {
  251. $status = Display::label(get_lang('Correct'), 'success');
  252. } else {
  253. if ($resultsDisabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
  254. return '';
  255. }
  256. }
  257. $content .= $status;
  258. }
  259. $content .= '</td>';
  260. if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  261. $content .= '<td class="text-left" width="60%">';
  262. if ($studentChoice) {
  263. $content .= '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
  264. }
  265. $content .= '</td>';
  266. } else {
  267. $content .= '<td class="text-left" width="60%">&nbsp;</td>';
  268. }
  269. $content .= '</tr>';
  270. echo $content;
  271. }
  272. /**
  273. * Display the answers to a multiple choice question.
  274. *
  275. * @param Exercise $exercise
  276. * @param int $feedbackType Feedback type
  277. * @param int $answerType Answer type
  278. * @param int $studentChoice Student choice
  279. * @param string $answer Textual answer
  280. * @param string $answerComment Comment on answer
  281. * @param string $answerCorrect Correct answer comment
  282. * @param int $id Exercise ID
  283. * @param int $questionId Question ID
  284. * @param bool $ans Whether to show the answer comment or not
  285. * @param bool $resultsDisabled
  286. * @param bool $showTotalScoreAndUserChoices
  287. * @param bool $export
  288. */
  289. public static function display_unique_or_multiple_answer(
  290. $exercise,
  291. $feedbackType,
  292. $answerType,
  293. $studentChoice,
  294. $answer,
  295. $answerComment,
  296. $answerCorrect,
  297. $id,
  298. $questionId,
  299. $ans,
  300. $resultsDisabled,
  301. $showTotalScoreAndUserChoices,
  302. $export = false
  303. ) {
  304. if ($export) {
  305. $answer = strip_tags_blacklist($answer, ['title', 'head']);
  306. // Fix answers that contains this tags
  307. $tags = [
  308. '<html>',
  309. '</html>',
  310. '<body>',
  311. '</body>',
  312. ];
  313. $answer = str_replace($tags, '', $answer);
  314. }
  315. $studentChoiceInt = (int) $studentChoice;
  316. $answerCorrectChoice = (int) $answerCorrect;
  317. $hideStudentChoice = false;
  318. $hide_expected_answer = false;
  319. $status = '';
  320. if ($exercise->showExpectedChoice()) {
  321. $status = Display::label(get_lang('Incorrect'), 'danger');
  322. if ($studentChoiceInt === $answerCorrectChoice) {
  323. $status = Display::label(get_lang('Correct'), 'success');
  324. }
  325. }
  326. $showComment = false;
  327. switch ($resultsDisabled) {
  328. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
  329. $hideStudentChoice = true;
  330. $hide_expected_answer = true;
  331. $status = Display::label(get_lang('Correct'), 'success');
  332. $showComment = true;
  333. if (!$answerCorrect) {
  334. return '';
  335. }
  336. break;
  337. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  338. if ($feedbackType == 0) {
  339. $hide_expected_answer = true;
  340. }
  341. break;
  342. case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
  343. case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
  344. $hide_expected_answer = true;
  345. if ($showTotalScoreAndUserChoices) {
  346. $hide_expected_answer = false;
  347. }
  348. break;
  349. }
  350. $icon = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
  351. $icon .= $studentChoice ? '_on' : '_off';
  352. $icon .= '.png';
  353. $iconAnswer = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
  354. $iconAnswer .= $answerCorrect ? '_on' : '_off';
  355. $iconAnswer .= '.png';
  356. echo '<tr>';
  357. if ($hideStudentChoice === false) {
  358. echo '<td width="5%">';
  359. echo Display::return_icon($icon, null, null, ICON_SIZE_TINY);
  360. echo '</td>';
  361. }
  362. if (!$hide_expected_answer) {
  363. echo '<td width="5%">';
  364. echo Display::return_icon($iconAnswer, null, null, ICON_SIZE_TINY);
  365. echo '</td>';
  366. }
  367. echo '<td width="40%">';
  368. echo $answer;
  369. echo '</td>';
  370. if ($exercise->showExpectedChoice()) {
  371. echo '<td width="20%">';
  372. echo $status;
  373. echo '</td>';
  374. }
  375. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM && $studentChoice) {
  376. $showComment = true;
  377. if (!$answerCorrect && $resultsDisabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
  378. $showComment = false;
  379. }
  380. }
  381. if ($showComment) {
  382. echo '<td width="20%">';
  383. $color = 'black';
  384. if ($answerCorrect) {
  385. $color = 'green';
  386. }
  387. if ($hide_expected_answer) {
  388. $color = '';
  389. }
  390. $comment = '<span style="font-weight: bold; color: '.$color.';">'.
  391. Security::remove_XSS($answerComment).
  392. '</span>';
  393. echo $comment;
  394. echo '</td>';
  395. } else {
  396. echo '<td>&nbsp;</td>';
  397. }
  398. echo '</tr>';
  399. }
  400. /**
  401. * Display the answers to a multiple choice question.
  402. *
  403. * @param Exercise $exercise
  404. * @param int Answer type
  405. * @param int Student choice
  406. * @param string Textual answer
  407. * @param string Comment on answer
  408. * @param string Correct answer comment
  409. * @param int Exercise ID
  410. * @param int Question ID
  411. * @param bool Whether to show the answer comment or not
  412. */
  413. public static function display_multiple_answer_true_false(
  414. $exercise,
  415. $feedbackType,
  416. $answerType,
  417. $studentChoice,
  418. $answer,
  419. $answerComment,
  420. $answerCorrect,
  421. $id,
  422. $questionId,
  423. $ans,
  424. $resultsDisabled,
  425. $showTotalScoreAndUserChoices
  426. ) {
  427. $hide_expected_answer = false;
  428. $hideStudentChoice = false;
  429. switch ($resultsDisabled) {
  430. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
  431. $hideStudentChoice = true;
  432. $hide_expected_answer = true;
  433. break;
  434. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  435. if ($feedbackType == 0) {
  436. $hide_expected_answer = true;
  437. }
  438. break;
  439. case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
  440. case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
  441. $hide_expected_answer = true;
  442. if ($showTotalScoreAndUserChoices) {
  443. $hide_expected_answer = false;
  444. }
  445. break;
  446. }
  447. $content = '<tr>';
  448. if ($hideStudentChoice === false) {
  449. $content .= '<td width="5%">';
  450. $course_id = api_get_course_int_id();
  451. $new_options = Question::readQuestionOption($questionId, $course_id);
  452. // Your choice
  453. if (isset($new_options[$studentChoice])) {
  454. $content .= get_lang($new_options[$studentChoice]['name']);
  455. } else {
  456. $content .= '-';
  457. }
  458. $content .= '</td>';
  459. }
  460. // Expected choice
  461. if (!$hide_expected_answer) {
  462. $content .= '<td width="5%">';
  463. if (isset($new_options[$answerCorrect])) {
  464. $content .= get_lang($new_options[$answerCorrect]['name']);
  465. } else {
  466. $content .= '-';
  467. }
  468. $content .= '</td>';
  469. }
  470. $content .= '<td width="40%">';
  471. $content .= $answer;
  472. $content .= '</td>';
  473. if ($exercise->showExpectedChoice()) {
  474. $status = Display::label(get_lang('Incorrect'), 'danger');
  475. if (isset($new_options[$studentChoice])) {
  476. if ($studentChoice == $answerCorrect) {
  477. $status = Display::label(get_lang('Correct'), 'success');
  478. }
  479. }
  480. $content .= '<td width="20%">';
  481. $content .= $status;
  482. $content .= '</td>';
  483. }
  484. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
  485. $content .= '<td width="20%">';
  486. $color = 'black';
  487. if (isset($new_options[$studentChoice]) || $resultsDisabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
  488. if ($studentChoice == $answerCorrect) {
  489. $color = 'green';
  490. }
  491. if ($hide_expected_answer) {
  492. $color = '';
  493. }
  494. $content .= '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
  495. }
  496. $content .= '</td>';
  497. }
  498. $content .= '</tr>';
  499. echo $content;
  500. }
  501. /**
  502. * Display the answers to a multiple choice question.
  503. *
  504. * @param int $feedbackType
  505. * @param int $studentChoice
  506. * @param int $studentChoiceDegree
  507. * @param string $answer
  508. * @param string $answerComment
  509. * @param int $answerCorrect
  510. * @param int $questionId
  511. * @param bool $inResultsDisabled
  512. */
  513. public static function displayMultipleAnswerTrueFalseDegreeCertainty(
  514. $feedbackType,
  515. $studentChoice,
  516. $studentChoiceDegree,
  517. $answer,
  518. $answerComment,
  519. $answerCorrect,
  520. $questionId,
  521. $inResultsDisabled
  522. ) {
  523. $hideExpectedAnswer = false;
  524. if ($feedbackType == 0 && $inResultsDisabled == 2) {
  525. $hideExpectedAnswer = true;
  526. }
  527. echo '<tr><td width="5%">';
  528. $question = new MultipleAnswerTrueFalseDegreeCertainty();
  529. $courseId = api_get_course_int_id();
  530. $newOptions = Question::readQuestionOption($questionId, $courseId);
  531. //Your choice
  532. if (isset($newOptions[$studentChoice])) {
  533. echo get_lang($newOptions[$studentChoice]['name']);
  534. } else {
  535. echo '-';
  536. }
  537. echo '</td><td width="5%">';
  538. // Expected choice
  539. if (!$hideExpectedAnswer) {
  540. if (isset($newOptions[$answerCorrect])) {
  541. echo get_lang($newOptions[$answerCorrect]['name']);
  542. } else {
  543. echo '-';
  544. }
  545. } else {
  546. echo '-';
  547. }
  548. echo '</td><td width="20%">';
  549. echo $answer;
  550. echo '</td><td width="5%" style="text-align:center;">';
  551. if (isset($newOptions[$studentChoiceDegree])) {
  552. echo $newOptions[$studentChoiceDegree]['name'];
  553. }
  554. echo '</td>';
  555. $degreeInfo = $question->getResponseDegreeInfo(
  556. $studentChoice,
  557. $answerCorrect,
  558. $newOptions[$studentChoiceDegree]['position']
  559. );
  560. echo '
  561. <td width="15%">
  562. <div style="text-align:center;color: '.$degreeInfo['color'].';
  563. background-color: '.$degreeInfo['background-color'].';
  564. line-height:30px;height:30px;width: 100%;margin:auto;"
  565. title="'.$degreeInfo['description'].'">'.
  566. nl2br($degreeInfo['label']).
  567. '</div>
  568. </td>';
  569. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
  570. echo '<td width="20%">';
  571. if (isset($newOptions[$studentChoice])) {
  572. echo '<span style="font-weight: bold; color: black;">'.nl2br($answerComment).'</span>';
  573. }
  574. echo '</td>';
  575. } else {
  576. echo '<td>&nbsp;</td>';
  577. }
  578. echo '</tr>';
  579. }
  580. /**
  581. * Display the answers to a multiple choice question.
  582. *
  583. * @param Exercise $exercise
  584. * @param int Answer type
  585. * @param int Student choice
  586. * @param string Textual answer
  587. * @param string Comment on answer
  588. * @param string Correct answer comment
  589. * @param int Exercise ID
  590. * @param int Question ID
  591. * @param bool Whether to show the answer comment or not
  592. */
  593. public static function display_multiple_answer_combination_true_false(
  594. $exercise,
  595. $feedbackType,
  596. $answerType,
  597. $studentChoice,
  598. $answer,
  599. $answerComment,
  600. $answerCorrect,
  601. $id,
  602. $questionId,
  603. $ans,
  604. $resultsDisabled,
  605. $showTotalScoreAndUserChoices
  606. ) {
  607. $hide_expected_answer = false;
  608. $hideStudentChoice = false;
  609. switch ($resultsDisabled) {
  610. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
  611. $hideStudentChoice = true;
  612. $hide_expected_answer = true;
  613. break;
  614. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  615. if ($feedbackType == 0) {
  616. $hide_expected_answer = true;
  617. }
  618. break;
  619. case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
  620. case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
  621. $hide_expected_answer = true;
  622. if ($showTotalScoreAndUserChoices) {
  623. $hide_expected_answer = false;
  624. }
  625. break;
  626. }
  627. echo '<tr>';
  628. if ($hideStudentChoice === false) {
  629. echo '<td width="5%">';
  630. // Your choice
  631. $question = new MultipleAnswerCombinationTrueFalse();
  632. if (isset($question->options[$studentChoice])) {
  633. echo $question->options[$studentChoice];
  634. } else {
  635. echo $question->options[2];
  636. }
  637. echo '</td>';
  638. }
  639. // Expected choice
  640. if (!$hide_expected_answer) {
  641. echo '<td width="5%">';
  642. if (isset($question->options[$answerCorrect])) {
  643. echo $question->options[$answerCorrect];
  644. } else {
  645. echo $question->options[2];
  646. }
  647. echo '</td>';
  648. }
  649. echo '<td width="40%">';
  650. echo $answer;
  651. echo '</td>';
  652. if ($exercise->showExpectedChoice()) {
  653. $status = '';
  654. if (isset($studentChoice)) {
  655. $status = Display::label(get_lang('Incorrect'), 'danger');
  656. if ($studentChoice == $answerCorrect) {
  657. $status = Display::label(get_lang('Correct'), 'success');
  658. }
  659. }
  660. echo '<td width="20%">';
  661. echo $status;
  662. echo '</td>';
  663. }
  664. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
  665. echo '<td width="20%">';
  666. //@todo replace this harcoded value
  667. if ($studentChoice || $resultsDisabled == RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER) {
  668. $color = 'black';
  669. if ($studentChoice == $answerCorrect) {
  670. $color = 'green';
  671. }
  672. if ($hide_expected_answer) {
  673. $color = '';
  674. }
  675. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
  676. }
  677. echo '</td>';
  678. } else {
  679. echo '<td>&nbsp;</td>';
  680. }
  681. echo '</tr>';
  682. }
  683. /**
  684. * @param $feedbackType
  685. * @param $exe_id
  686. * @param $questionId
  687. * @param null $questionScore
  688. * @param int $resultsDisabled
  689. */
  690. public static function displayAnnotationAnswer(
  691. $feedbackType,
  692. $exe_id,
  693. $questionId,
  694. $questionScore = null,
  695. $resultsDisabled = 0
  696. ) {
  697. $comments = Event::get_comments($exe_id, $questionId);
  698. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
  699. if ($questionScore <= 0 && empty($comments)) {
  700. echo '<br />'.ExerciseLib::getNotCorrectedYetText();
  701. }
  702. }
  703. }
  704. }