exercise_show_functions.lib.php 24 KB

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