exercise_show_functions.lib.php 25 KB

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