exercise_show_functions.lib.php 14 KB

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