exercise_show_functions.lib.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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 (in_array($resultsDisabled, [
  254. RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER_AND_RANKING,
  255. RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
  256. ])
  257. ) {
  258. return '';
  259. }
  260. }
  261. $content .= $status;
  262. }
  263. $content .= '</td>';
  264. if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  265. $content .= '<td class="text-left" width="60%">';
  266. if ($studentChoice) {
  267. $content .= '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
  268. }
  269. $content .= '</td>';
  270. } else {
  271. $content .= '<td class="text-left" width="60%">&nbsp;</td>';
  272. }
  273. $content .= '</tr>';
  274. echo $content;
  275. }
  276. /**
  277. * Display the answers to a multiple choice question.
  278. *
  279. * @param Exercise $exercise
  280. * @param int $feedbackType Feedback type
  281. * @param int $answerType Answer type
  282. * @param int $studentChoice Student choice
  283. * @param string $answer Textual answer
  284. * @param string $answerComment Comment on answer
  285. * @param string $answerCorrect Correct answer comment
  286. * @param int $id Exercise ID
  287. * @param int $questionId Question ID
  288. * @param bool $ans Whether to show the answer comment or not
  289. * @param bool $resultsDisabled
  290. * @param bool $showTotalScoreAndUserChoices
  291. * @param bool $export
  292. */
  293. public static function display_unique_or_multiple_answer(
  294. $exercise,
  295. $feedbackType,
  296. $answerType,
  297. $studentChoice,
  298. $answer,
  299. $answerComment,
  300. $answerCorrect,
  301. $id,
  302. $questionId,
  303. $ans,
  304. $resultsDisabled,
  305. $showTotalScoreAndUserChoices,
  306. $export = false
  307. ) {
  308. if ($export) {
  309. $answer = strip_tags_blacklist($answer, ['title', 'head']);
  310. // Fix answers that contains this tags
  311. $tags = [
  312. '<html>',
  313. '</html>',
  314. '<body>',
  315. '</body>',
  316. ];
  317. $answer = str_replace($tags, '', $answer);
  318. }
  319. $studentChoiceInt = (int) $studentChoice;
  320. $answerCorrectChoice = (int) $answerCorrect;
  321. $hideStudentChoice = false;
  322. $hide_expected_answer = false;
  323. $status = '';
  324. if ($exercise->showExpectedChoice()) {
  325. $status = Display::label(get_lang('Incorrect'), 'danger');
  326. if ($answerCorrect || ($answerCorrect && $studentChoiceInt === $answerCorrectChoice)) {
  327. $status = Display::label(get_lang('Correct'), 'success');
  328. }
  329. }
  330. $showComment = false;
  331. switch ($resultsDisabled) {
  332. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER_AND_RANKING:
  333. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
  334. $hideStudentChoice = false;
  335. $hide_expected_answer = true;
  336. $status = Display::label(get_lang('Correct'), 'success');
  337. $showComment = true;
  338. if (!$answerCorrect && empty($studentChoice)) {
  339. return '';
  340. }
  341. break;
  342. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  343. if ($feedbackType == 0) {
  344. $hide_expected_answer = true;
  345. }
  346. break;
  347. case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
  348. case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
  349. $hide_expected_answer = true;
  350. if ($showTotalScoreAndUserChoices) {
  351. $hide_expected_answer = false;
  352. }
  353. break;
  354. }
  355. $icon = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
  356. $icon .= $studentChoice ? '_on' : '_off';
  357. $icon .= '.png';
  358. $iconAnswer = in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION]) ? 'radio' : 'checkbox';
  359. $iconAnswer .= $answerCorrect ? '_on' : '_off';
  360. $iconAnswer .= '.png';
  361. $studentChoiceClass = '';
  362. if (in_array($resultsDisabled, [
  363. RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER_AND_RANKING,
  364. RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
  365. ])
  366. ) {
  367. if ($answerCorrect) {
  368. $studentChoiceClass = 'success';
  369. }
  370. }
  371. echo '<tr class="'.$studentChoiceClass.'">';
  372. if ($hideStudentChoice === false) {
  373. echo '<td width="5%">';
  374. echo Display::return_icon($icon, null, null, ICON_SIZE_TINY);
  375. echo '</td>';
  376. }
  377. if (!$hide_expected_answer) {
  378. echo '<td width="5%">';
  379. echo Display::return_icon($iconAnswer, null, null, ICON_SIZE_TINY);
  380. echo '</td>';
  381. }
  382. echo '<td width="40%">';
  383. echo $answer;
  384. echo '</td>';
  385. if ($exercise->showExpectedChoice()) {
  386. echo '<td width="20%">';
  387. echo $status;
  388. echo '</td>';
  389. }
  390. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM && $studentChoice) {
  391. $showComment = true;
  392. }
  393. if ($showComment) {
  394. echo '<td width="20%">';
  395. $color = 'black';
  396. if ($answerCorrect) {
  397. $color = 'green';
  398. }
  399. if ($hide_expected_answer) {
  400. $color = '';
  401. }
  402. $comment = '<span style="font-weight: bold; color: '.$color.';">'.
  403. Security::remove_XSS($answerComment).
  404. '</span>';
  405. echo $comment;
  406. echo '</td>';
  407. } else {
  408. echo '<td>&nbsp;</td>';
  409. }
  410. echo '</tr>';
  411. }
  412. /**
  413. * Display the answers to a multiple choice question.
  414. *
  415. * @param Exercise $exercise
  416. * @param int Answer type
  417. * @param int Student choice
  418. * @param string Textual answer
  419. * @param string Comment on answer
  420. * @param string Correct answer comment
  421. * @param int Exercise ID
  422. * @param int Question ID
  423. * @param bool Whether to show the answer comment or not
  424. */
  425. public static function display_multiple_answer_true_false(
  426. $exercise,
  427. $feedbackType,
  428. $answerType,
  429. $studentChoice,
  430. $answer,
  431. $answerComment,
  432. $answerCorrect,
  433. $id,
  434. $questionId,
  435. $ans,
  436. $resultsDisabled,
  437. $showTotalScoreAndUserChoices
  438. ) {
  439. $hide_expected_answer = false;
  440. $hideStudentChoice = false;
  441. switch ($resultsDisabled) {
  442. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER_AND_RANKING:
  443. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
  444. $hideStudentChoice = false;
  445. $hide_expected_answer = true;
  446. break;
  447. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  448. if ($feedbackType == 0) {
  449. $hide_expected_answer = true;
  450. }
  451. break;
  452. case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
  453. case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
  454. $hide_expected_answer = true;
  455. if ($showTotalScoreAndUserChoices) {
  456. $hide_expected_answer = false;
  457. }
  458. break;
  459. }
  460. $content = '<tr>';
  461. if ($hideStudentChoice === false) {
  462. $content .= '<td width="5%">';
  463. $course_id = api_get_course_int_id();
  464. $new_options = Question::readQuestionOption($questionId, $course_id);
  465. // Your choice
  466. if (isset($new_options[$studentChoice])) {
  467. $content .= get_lang($new_options[$studentChoice]['name']);
  468. } else {
  469. $content .= '-';
  470. }
  471. $content .= '</td>';
  472. }
  473. // Expected choice
  474. if (!$hide_expected_answer) {
  475. $content .= '<td width="5%">';
  476. if (isset($new_options[$answerCorrect])) {
  477. $content .= get_lang($new_options[$answerCorrect]['name']);
  478. } else {
  479. $content .= '-';
  480. }
  481. $content .= '</td>';
  482. }
  483. $content .= '<td width="40%">';
  484. $content .= $answer;
  485. $content .= '</td>';
  486. if ($exercise->showExpectedChoice()) {
  487. $status = Display::label(get_lang('Incorrect'), 'danger');
  488. if (isset($new_options[$studentChoice])) {
  489. if ($studentChoice == $answerCorrect) {
  490. $status = Display::label(get_lang('Correct'), 'success');
  491. }
  492. }
  493. $content .= '<td width="20%">';
  494. $content .= $status;
  495. $content .= '</td>';
  496. }
  497. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
  498. $content .= '<td width="20%">';
  499. $color = 'black';
  500. if (isset($new_options[$studentChoice]) || in_array($exercise->results_disabled, [
  501. RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER_AND_RANKING,
  502. RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
  503. ])
  504. ) {
  505. if ($studentChoice == $answerCorrect) {
  506. $color = 'green';
  507. }
  508. if ($hide_expected_answer) {
  509. $color = '';
  510. }
  511. $content .= '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
  512. }
  513. $content .= '</td>';
  514. }
  515. $content .= '</tr>';
  516. echo $content;
  517. }
  518. /**
  519. * Display the answers to a multiple choice question.
  520. *
  521. * @param int $feedbackType
  522. * @param int $studentChoice
  523. * @param int $studentChoiceDegree
  524. * @param string $answer
  525. * @param string $answerComment
  526. * @param int $answerCorrect
  527. * @param int $questionId
  528. * @param bool $inResultsDisabled
  529. */
  530. public static function displayMultipleAnswerTrueFalseDegreeCertainty(
  531. $feedbackType,
  532. $studentChoice,
  533. $studentChoiceDegree,
  534. $answer,
  535. $answerComment,
  536. $answerCorrect,
  537. $questionId,
  538. $inResultsDisabled
  539. ) {
  540. $hideExpectedAnswer = false;
  541. if ($feedbackType == 0 && $inResultsDisabled == 2) {
  542. $hideExpectedAnswer = true;
  543. }
  544. echo '<tr><td width="5%">';
  545. $question = new MultipleAnswerTrueFalseDegreeCertainty();
  546. $courseId = api_get_course_int_id();
  547. $newOptions = Question::readQuestionOption($questionId, $courseId);
  548. //Your choice
  549. if (isset($newOptions[$studentChoice])) {
  550. echo get_lang($newOptions[$studentChoice]['name']);
  551. } else {
  552. echo '-';
  553. }
  554. echo '</td><td width="5%">';
  555. // Expected choice
  556. if (!$hideExpectedAnswer) {
  557. if (isset($newOptions[$answerCorrect])) {
  558. echo get_lang($newOptions[$answerCorrect]['name']);
  559. } else {
  560. echo '-';
  561. }
  562. } else {
  563. echo '-';
  564. }
  565. echo '</td><td width="20%">';
  566. echo $answer;
  567. echo '</td><td width="5%" style="text-align:center;">';
  568. if (isset($newOptions[$studentChoiceDegree])) {
  569. echo $newOptions[$studentChoiceDegree]['name'];
  570. }
  571. echo '</td>';
  572. $degreeInfo = $question->getResponseDegreeInfo(
  573. $studentChoice,
  574. $answerCorrect,
  575. $newOptions[$studentChoiceDegree]['position']
  576. );
  577. echo '
  578. <td width="15%">
  579. <div style="text-align:center;color: '.$degreeInfo['color'].';
  580. background-color: '.$degreeInfo['background-color'].';
  581. line-height:30px;height:30px;width: 100%;margin:auto;"
  582. title="'.$degreeInfo['description'].'">'.
  583. nl2br($degreeInfo['label']).
  584. '</div>
  585. </td>';
  586. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
  587. echo '<td width="20%">';
  588. if (isset($newOptions[$studentChoice])) {
  589. echo '<span style="font-weight: bold; color: black;">'.nl2br($answerComment).'</span>';
  590. }
  591. echo '</td>';
  592. } else {
  593. echo '<td>&nbsp;</td>';
  594. }
  595. echo '</tr>';
  596. }
  597. /**
  598. * Display the answers to a multiple choice question.
  599. *
  600. * @param Exercise $exercise
  601. * @param int Answer type
  602. * @param int Student choice
  603. * @param string Textual answer
  604. * @param string Comment on answer
  605. * @param string Correct answer comment
  606. * @param int Exercise ID
  607. * @param int Question ID
  608. * @param bool Whether to show the answer comment or not
  609. */
  610. public static function display_multiple_answer_combination_true_false(
  611. $exercise,
  612. $feedbackType,
  613. $answerType,
  614. $studentChoice,
  615. $answer,
  616. $answerComment,
  617. $answerCorrect,
  618. $id,
  619. $questionId,
  620. $ans,
  621. $resultsDisabled,
  622. $showTotalScoreAndUserChoices
  623. ) {
  624. $hide_expected_answer = false;
  625. $hideStudentChoice = false;
  626. switch ($resultsDisabled) {
  627. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER_AND_RANKING:
  628. case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
  629. $hideStudentChoice = true;
  630. $hide_expected_answer = true;
  631. break;
  632. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  633. if ($feedbackType == 0) {
  634. $hide_expected_answer = true;
  635. }
  636. break;
  637. case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
  638. case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
  639. $hide_expected_answer = true;
  640. if ($showTotalScoreAndUserChoices) {
  641. $hide_expected_answer = false;
  642. }
  643. break;
  644. }
  645. echo '<tr>';
  646. if ($hideStudentChoice === false) {
  647. echo '<td width="5%">';
  648. // Your choice
  649. $question = new MultipleAnswerCombinationTrueFalse();
  650. if (isset($question->options[$studentChoice])) {
  651. echo $question->options[$studentChoice];
  652. } else {
  653. echo $question->options[2];
  654. }
  655. echo '</td>';
  656. }
  657. // Expected choice
  658. if (!$hide_expected_answer) {
  659. echo '<td width="5%">';
  660. if (isset($question->options[$answerCorrect])) {
  661. echo $question->options[$answerCorrect];
  662. } else {
  663. echo $question->options[2];
  664. }
  665. echo '</td>';
  666. }
  667. echo '<td width="40%">';
  668. echo $answer;
  669. echo '</td>';
  670. if ($exercise->showExpectedChoice()) {
  671. $status = '';
  672. if (isset($studentChoice)) {
  673. $status = Display::label(get_lang('Incorrect'), 'danger');
  674. if ($studentChoice == $answerCorrect) {
  675. $status = Display::label(get_lang('Correct'), 'success');
  676. }
  677. }
  678. echo '<td width="20%">';
  679. echo $status;
  680. echo '</td>';
  681. }
  682. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
  683. echo '<td width="20%">';
  684. //@todo replace this harcoded value
  685. if ($studentChoice || in_array($resultsDisabled, [
  686. RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER_AND_RANKING,
  687. RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER
  688. ])
  689. ) {
  690. $color = 'black';
  691. if ($studentChoice == $answerCorrect) {
  692. $color = 'green';
  693. }
  694. if ($hide_expected_answer) {
  695. $color = '';
  696. }
  697. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
  698. }
  699. echo '</td>';
  700. } else {
  701. echo '<td>&nbsp;</td>';
  702. }
  703. echo '</tr>';
  704. }
  705. /**
  706. * @param $feedbackType
  707. * @param $exe_id
  708. * @param $questionId
  709. * @param null $questionScore
  710. * @param int $resultsDisabled
  711. */
  712. public static function displayAnnotationAnswer(
  713. $feedbackType,
  714. $exe_id,
  715. $questionId,
  716. $questionScore = null,
  717. $resultsDisabled = 0
  718. ) {
  719. $comments = Event::get_comments($exe_id, $questionId);
  720. if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
  721. if ($questionScore <= 0 && empty($comments)) {
  722. echo '<br />'.ExerciseLib::getNotCorrectedYetText();
  723. }
  724. }
  725. }
  726. }