hotspot_actionscript.as.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file generates the ActionScript variables code used by the HotSpot .swf.
  6. *
  7. * @package chamilo.exercise
  8. *
  9. * @author Toon Keppens
  10. *
  11. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  12. */
  13. session_cache_limiter('none');
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. api_protect_course_script(true);
  16. $_course = api_get_course_info();
  17. require api_get_path(LIBRARY_PATH).'geometry.lib.php';
  18. // set vars
  19. $questionId = intval($_GET['modifyAnswers']);
  20. $exerciseId = isset($_GET['exe_id']) ? intval($_GET['exe_id']) : 0;
  21. $objQuestion = Question::read($questionId);
  22. $answer_type = $objQuestion->selectType(); //very important
  23. $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
  24. $picture = $objQuestion->getPicture();
  25. $pictureName = $objQuestion->getPictureFilename();
  26. $pictureWidth = $picture->getResourceNode()->getResourceFile()->getWidth();
  27. $pictureHeight = $picture->getResourceNode()->getResourceFile()->getHeight();
  28. $course_id = api_get_course_int_id();
  29. // Query db for answers
  30. if ($answer_type == HOT_SPOT_DELINEATION) {
  31. $sql = "SELECT iid, id, answer, hotspot_coordinates, hotspot_type, ponderation
  32. FROM $TBL_ANSWERS
  33. WHERE
  34. c_id = $course_id AND
  35. question_id = $questionId AND
  36. hotspot_type = 'delineation'
  37. ORDER BY iid";
  38. } else {
  39. $sql = "SELECT iid, id, answer, hotspot_coordinates, hotspot_type, ponderation
  40. FROM $TBL_ANSWERS
  41. WHERE c_id = $course_id AND question_id = $questionId
  42. ORDER BY position";
  43. }
  44. $result = Database::query($sql);
  45. $data = [];
  46. $data['type'] = 'user';
  47. $data['lang'] = [
  48. 'Square' => get_lang('Square'),
  49. 'Ellipse' => get_lang('Ellipse'),
  50. 'Polygon' => get_lang('Polygon'),
  51. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  52. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  53. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  54. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  55. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  56. 'ShowHotspots' => get_lang('ShowHotspots'),
  57. 'Triesleft' => get_lang('Triesleft'),
  58. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  59. 'NextAnswer' => get_lang('NextAnswer'),
  60. 'Delineation' => get_lang('Delineation'),
  61. 'CloseDelineation' => get_lang('CloseDelineation'),
  62. 'Oar' => get_lang('Oar'),
  63. 'ClosePolygon' => get_lang('ClosePolygon'),
  64. 'DelineationStatus1' => get_lang('DelineationStatus1'),
  65. ];
  66. $data['image'] = $objQuestion->selectPicturePath();
  67. $data['image_width'] = $pictureWidth;
  68. $data['image_height'] = $pictureHeight;
  69. $data['courseCode'] = $_course['path'];
  70. $data['hotspots'] = [];
  71. $data['answers'] = [];
  72. $nmbrTries = 0;
  73. while ($hotspot = Database::fetch_assoc($result)) {
  74. $hotSpot = [];
  75. $hotSpot['id'] = $hotspot['id'];
  76. $hotSpot['iid'] = $hotspot['iid'];
  77. $hotSpot['answer'] = $hotspot['answer'];
  78. // Square or rectancle
  79. if ($hotspot['hotspot_type'] == 'square') {
  80. $hotSpot['type'] = 'square';
  81. }
  82. // Circle or ovale
  83. if ($hotspot['hotspot_type'] == 'circle') {
  84. $hotSpot['type'] = 'circle';
  85. }
  86. // Polygon
  87. if ($hotspot['hotspot_type'] == 'poly') {
  88. $hotSpot['type'] = 'poly';
  89. }
  90. // Delineation
  91. if ($hotspot['hotspot_type'] == 'delineation') {
  92. $hotSpot['type'] = 'delineation';
  93. }
  94. // No error
  95. if ($hotspot['hotspot_type'] == 'noerror') {
  96. $hotSpot['type'] = 'noerror';
  97. }
  98. // This is a good answer, count + 1 for nmbr of clicks
  99. if ($hotspot['hotspot_type'] > 0) {
  100. $nmbrTries++;
  101. }
  102. $hotSpot['coord'] = $hotspot['hotspot_coordinates'];
  103. $data['hotspots'][] = $hotSpot;
  104. }
  105. $attemptList = Event::getAllExerciseEventByExeId($exerciseId);
  106. if (!empty($attemptList)) {
  107. if (isset($attemptList[$questionId])) {
  108. $questionAttempt = $attemptList[$questionId][0];
  109. if (!empty($questionAttempt['answer'])) {
  110. $coordinates = explode('|', $questionAttempt['answer']);
  111. foreach ($coordinates as $coordinate) {
  112. $data['answers'][] = Geometry::decodePoint($coordinate);
  113. }
  114. }
  115. }
  116. }
  117. $data['nmbrTries'] = $nmbrTries;
  118. $data['done'] = 'done';
  119. if (Session::has("hotspot_ordered$questionId")) {
  120. $tempHotspots = [];
  121. $hotspotOrdered = Session::read("hotspot_ordered$questionId");
  122. foreach ($hotspotOrdered as $hotspotOrder) {
  123. foreach ($data['hotspots'] as $hotspot) {
  124. if ($hotspot['id'] != $hotspotOrder) {
  125. continue;
  126. }
  127. $tempHotspots[] = $hotspot;
  128. }
  129. }
  130. $data['hotspots'] = $tempHotspots;
  131. Session::erase("hotspot_ordered$questionId");
  132. }
  133. header('Content-Type: application/json');
  134. echo json_encode($data);