exercise_show_functions.lib.php 14 KB

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