exercise_show_functions.lib.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. * @todo convert queries to use Database API
  13. */
  14. /**
  15. * Class
  16. * @package chamilo.library
  17. */
  18. class ExerciseShowFunctions
  19. {
  20. /**
  21. * Shows the answer to a fill-in-the-blanks question, as HTML
  22. * Display in the student result page, with score and comm
  23. * @param string Answer text
  24. * @param int Exercise ID
  25. * @param int Question ID
  26. * @return void
  27. */
  28. static function display_fill_in_blanks_answer($feedbackType, $answer, $id, $questionId, $inResultsDisabled, $originalStudentAnswer = '')
  29. {
  30. $answerHTML = FillBlanks::getHtmlDisplayForAsnwer($answer, $inResultsDisabled);
  31. if (strpos($originalStudentAnswer, 'font color') !== false) {
  32. $answerHTML = $originalStudentAnswer;
  33. }
  34. if (empty($id)) {
  35. echo '<tr><td>';
  36. echo Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY);
  37. echo '</td></tr>';
  38. } else {
  39. ?>
  40. <tr>
  41. <td>
  42. <?php echo nl2br(Security::remove_XSS($answerHTML, COURSEMANAGERLOWSECURITY)); ?>
  43. </td>
  44. <?php
  45. if (!api_is_allowed_to_edit(null,true) && $feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  46. <td>
  47. <?php
  48. $comm = get_comments($id,$questionId);
  49. ?>
  50. </td>
  51. <?php } ?>
  52. </tr>
  53. <?php
  54. }
  55. }
  56. /**
  57. * Shows the answer to a calculated question, as HTML
  58. * @param string Answer text
  59. * @param int Exercise ID
  60. * @param int Question ID
  61. * @return void
  62. */
  63. static function display_calculated_answer($feedback_type, $answer, $id, $questionId)
  64. {
  65. if (empty($id)) {
  66. echo '<tr><td>'. (Security::remove_XSS($answer)).'</td></tr>';
  67. } else {
  68. ?>
  69. <tr>
  70. <td>
  71. <?php
  72. echo (Security::remove_XSS($answer));
  73. ?>
  74. </td>
  75. <?php
  76. if (!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  77. <td>
  78. <?php
  79. $comm = get_comments($id,$questionId);
  80. ?>
  81. </td>
  82. <?php } ?>
  83. </tr>
  84. <?php
  85. }
  86. }
  87. /**
  88. * Shows the answer to a free-answer question, as HTML
  89. * @param string Answer text
  90. * @param int Exercise ID
  91. * @param int Question ID
  92. * @return void
  93. */
  94. static function display_free_answer($feedback_type, $answer, $exe_id, $questionId, $questionScore = null)
  95. {
  96. $comments = get_comments($exe_id, $questionId);
  97. if (!empty($answer)) {
  98. echo '<tr><td>';
  99. echo nl2br(Security::remove_XSS($answer));
  100. echo '</td></tr>';
  101. }
  102. if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  103. if ($questionScore > 0 || !empty($comments)) {
  104. } else {
  105. echo '<tr>';
  106. echo Display::tag('td', Display::return_message(get_lang('notCorrectedYet')), array());
  107. echo '</tr>';
  108. }
  109. }
  110. }
  111. static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $nano = null)
  112. {
  113. if (isset($nano)) {
  114. echo $nano->show_audio_file();
  115. }
  116. if (empty($id)) {
  117. echo '<tr>';
  118. echo Display::tag('td', nl2br(Security::remove_XSS($answer)), array('width'=>'55%'));
  119. echo '</tr>';
  120. if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  121. echo '<tr>';
  122. echo Display::tag('td',get_lang('notCorrectedYet'), array('width'=>'45%'));
  123. echo '</tr>';
  124. } else {
  125. echo '<tr><td>&nbsp;</td></tr>';
  126. }
  127. } else {
  128. echo '<tr>';
  129. echo '<td>';
  130. if (!empty($answer)) {
  131. echo nl2br(Security::remove_XSS($answer));
  132. }
  133. echo '</td>';
  134. if (!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  135. echo '<td>';
  136. $comm = get_comments($id,$questionId);
  137. echo '</td>';
  138. }
  139. echo '</tr>';
  140. }
  141. }
  142. /**
  143. * Displays the answer to a hotspot question
  144. *
  145. * @param int $answerId
  146. * @param string $answer
  147. * @param string $studentChoice
  148. * @param string $answerComment
  149. */
  150. static function display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment, $in_results_disabled) {
  151. $hide_expected_answer = false;
  152. if ($feedback_type == 0 && $in_results_disabled == 2) {
  153. $hide_expected_answer = true;
  154. }
  155. $hotspot_colors = array(
  156. "", // $i starts from 1 on next loop (ugly fix)
  157. "#4271B5",
  158. "#FE8E16",
  159. "#45C7F0",
  160. "#BCD631",
  161. "#D63173",
  162. "#D7D7D7",
  163. "#90AFDD",
  164. "#AF8640",
  165. "#4F9242",
  166. "#F4EB24",
  167. "#ED2024",
  168. "#3B3B3B",
  169. "#F7BDE2");
  170. ?>
  171. <table class="data_table">
  172. <tr>
  173. <td width="100px" valign="top" align="left">
  174. <div style="width:100%;">
  175. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  176. <div style="float:left; padding-left:5px;">
  177. <?php echo $answerId; ?>
  178. </div>
  179. <div><?php echo '&nbsp;'.$answer ?></div>
  180. </div>
  181. </td>
  182. <td width="50px" style="padding-right:15px" valign="top" align="left">
  183. <?php
  184. if (!$hide_expected_answer) {
  185. $my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault');
  186. echo $my_choice;
  187. }
  188. ?>
  189. </td>
  190. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  191. <td valign="top" align="left" >
  192. <?php
  193. if ($studentChoice) {
  194. echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
  195. }
  196. ?>
  197. </td>
  198. <?php } else { ?>
  199. <td>&nbsp;</td>
  200. <?php } ?>
  201. </tr>
  202. <?php
  203. }
  204. /**
  205. * Display the answers to a multiple choice question
  206. *
  207. * @param integer Answer type
  208. * @param integer Student choice
  209. * @param string Textual answer
  210. * @param string Comment on answer
  211. * @param string Correct answer comment
  212. * @param integer Exercise ID
  213. * @param integer Question ID
  214. * @param boolean Whether to show the answer comment or not
  215. * @return void
  216. */
  217. static function display_unique_or_multiple_answer(
  218. $feedback_type,
  219. $answerType,
  220. $studentChoice,
  221. $answer,
  222. $answerComment,
  223. $answerCorrect,
  224. $id,
  225. $questionId,
  226. $ans,
  227. $in_results_disabled
  228. ) {
  229. $hide_expected_answer = false;
  230. if ($feedback_type == 0 && $in_results_disabled == 2) {
  231. $hide_expected_answer = true;
  232. }
  233. ?>
  234. <tr>
  235. <td width="5%">
  236. <img src="../img/<?php echo (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION))) ? 'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  237. border="0" alt="" />
  238. </td>
  239. <td width="5%">
  240. <?php if (!$hide_expected_answer) { ?>
  241. <img src="../img/<?php echo (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION))) ? 'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif" border="0" alt=" " />
  242. <?php }
  243. else {
  244. echo "-";
  245. }?>
  246. </td>
  247. <td width="40%">
  248. <?php
  249. echo $answer;
  250. ?>
  251. </td>
  252. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  253. <td width="20%">
  254. <?php
  255. if ($studentChoice) {
  256. if ($answerCorrect) {
  257. $color = 'green';
  258. //echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
  259. } else {
  260. $color = 'black';
  261. //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
  262. }
  263. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
  264. } else {
  265. if ($answerCorrect) {
  266. //echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
  267. } else {
  268. //echo '<span style="font-weight: normal; color: #000;">'.nl2br($answerComment).'</span>';
  269. }
  270. }
  271. ?>
  272. </td>
  273. <?php
  274. if ($ans==1) {
  275. $comm = get_comments($id,$questionId);
  276. }
  277. ?>
  278. <?php } else { ?>
  279. <td>&nbsp;</td>
  280. <?php } ?>
  281. </tr>
  282. <?php
  283. }
  284. /**
  285. * Display the answers to a multiple choice question
  286. *
  287. * @param integer Answer type
  288. * @param integer Student choice
  289. * @param string Textual answer
  290. * @param string Comment on answer
  291. * @param string Correct answer comment
  292. * @param integer Exercise ID
  293. * @param integer Question ID
  294. * @param boolean Whether to show the answer comment or not
  295. * @return void
  296. */
  297. static function display_multiple_answer_true_false(
  298. $feedback_type,
  299. $answerType,
  300. $studentChoice,
  301. $answer,
  302. $answerComment,
  303. $answerCorrect,
  304. $id,
  305. $questionId,
  306. $ans,
  307. $in_results_disabled
  308. ) {
  309. $hide_expected_answer = false;
  310. if ($feedback_type == 0 && $in_results_disabled == 2) {
  311. $hide_expected_answer = true;
  312. }
  313. ?>
  314. <tr>
  315. <td width="5%">
  316. <?php
  317. $question = new MultipleAnswerTrueFalse();
  318. $course_id = api_get_course_int_id();
  319. $new_options = Question::readQuestionOption($questionId, $course_id);
  320. //Your choice
  321. if (isset($new_options[$studentChoice])) {
  322. echo get_lang($new_options[$studentChoice]['name']);
  323. } else {
  324. echo '-';
  325. }
  326. ?>
  327. </td>
  328. <td width="5%">
  329. <?php
  330. //Expected choice
  331. if (!$hide_expected_answer) {
  332. if (isset($new_options[$answerCorrect])) {
  333. echo get_lang($new_options[$answerCorrect]['name']);
  334. } else {
  335. echo '-';
  336. }
  337. } else {
  338. echo '-';
  339. }
  340. ?>
  341. </td>
  342. <td width="40%">
  343. <?php echo $answer; ?>
  344. </td>
  345. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  346. <td width="20%">
  347. <?php
  348. $color = "black";
  349. if (isset($new_options[$studentChoice])) {
  350. if ($studentChoice == $answerCorrect) {
  351. $color = "green";
  352. }
  353. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
  354. }
  355. ?>
  356. </td>
  357. <?php
  358. if ($ans==1) {
  359. $comm = get_comments($id, $questionId);
  360. }
  361. ?>
  362. <?php } else { ?>
  363. <td>&nbsp;</td>
  364. <?php } ?>
  365. </tr>
  366. <?php
  367. }
  368. /**
  369. * Display the answers to a multiple choice question
  370. *
  371. * @param integer Answer type
  372. * @param integer Student choice
  373. * @param string Textual answer
  374. * @param string Comment on answer
  375. * @param string Correct answer comment
  376. * @param integer Exercise ID
  377. * @param integer Question ID
  378. * @param boolean Whether to show the answer comment or not
  379. * @return void
  380. */
  381. static function display_multiple_answer_combination_true_false(
  382. $feedback_type,
  383. $answerType,
  384. $studentChoice,
  385. $answer,
  386. $answerComment,
  387. $answerCorrect,
  388. $id,
  389. $questionId,
  390. $ans,
  391. $in_results_disabled
  392. ) {
  393. $hide_expected_answer = false;
  394. if ($feedback_type == 0 && $in_results_disabled == 2) {
  395. $hide_expected_answer = true;
  396. }
  397. ?>
  398. <tr>
  399. <td width="5%">
  400. <?php
  401. //Your choice
  402. $question = new MultipleAnswerCombinationTrueFalse();
  403. if (isset($question->options[$studentChoice])) {
  404. echo $question->options[$studentChoice];
  405. } else {
  406. echo $question->options[2];
  407. }
  408. ?>
  409. </td>
  410. <td width="5%">
  411. <?php
  412. //Expected choice
  413. if (!$hide_expected_answer) {
  414. if (isset($question->options[$answerCorrect])) {
  415. echo $question->options[$answerCorrect];
  416. } else {
  417. echo $question->options[2];
  418. }
  419. }
  420. else {
  421. echo '-';
  422. }
  423. ?>
  424. </td>
  425. <td width="40%">
  426. <?php
  427. //my answer
  428. echo $answer;
  429. ?>
  430. </td>
  431. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  432. <td width="20%">
  433. <?php
  434. //@todo replace this harcoded value
  435. if ($studentChoice) {
  436. $color = "black";
  437. if ($studentChoice == $answerCorrect) {
  438. $color = "green";
  439. }
  440. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
  441. }
  442. if ($studentChoice == 2 || $studentChoice == '') {
  443. //echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
  444. } else {
  445. if ($studentChoice == $answerCorrect) {
  446. //echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
  447. } else {
  448. //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
  449. }
  450. }
  451. ?>
  452. </td>
  453. <?php
  454. if ($ans==1) {
  455. $comm = get_comments($id,$questionId);
  456. }
  457. ?>
  458. <?php } else { ?>
  459. <td>&nbsp;</td>
  460. <?php } ?>
  461. </tr>
  462. <?php
  463. }
  464. }