hotspot_actionscript.as.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  25. $picturePath = $documentPath.'/images';
  26. $pictureName = $objQuestion->getPictureFilename();
  27. $pictureSize = getimagesize($picturePath.'/'.$pictureName);
  28. $pictureWidth = $pictureSize[0];
  29. $pictureHeight = $pictureSize[1];
  30. $course_id = api_get_course_int_id();
  31. // Query db for answers
  32. if ($answer_type == HOT_SPOT_DELINEATION) {
  33. $sql = "SELECT iid, id, answer, hotspot_coordinates, hotspot_type, ponderation
  34. FROM $TBL_ANSWERS
  35. WHERE
  36. c_id = $course_id AND
  37. question_id = $questionId AND
  38. hotspot_type = 'delineation'
  39. ORDER BY iid";
  40. } else {
  41. $sql = "SELECT iid, id, answer, hotspot_coordinates, hotspot_type, ponderation
  42. FROM $TBL_ANSWERS
  43. WHERE c_id = $course_id AND question_id = $questionId
  44. ORDER BY position";
  45. }
  46. $result = Database::query($sql);
  47. $data = [];
  48. $data['type'] = 'user';
  49. $data['lang'] = [
  50. 'Square' => get_lang('Square'),
  51. 'Ellipse' => get_lang('Ellipse'),
  52. 'Polygon' => get_lang('Polygon'),
  53. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  54. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  55. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  56. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  57. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  58. 'ShowHotspots' => get_lang('ShowHotspots'),
  59. 'Triesleft' => get_lang('Triesleft'),
  60. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  61. 'NextAnswer' => get_lang('NextAnswer'),
  62. 'Delineation' => get_lang('Delineation'),
  63. 'CloseDelineation' => get_lang('CloseDelineation'),
  64. 'Oar' => get_lang('Oar'),
  65. 'ClosePolygon' => get_lang('ClosePolygon'),
  66. 'DelineationStatus1' => get_lang('DelineationStatus1'),
  67. ];
  68. $data['image'] = $objQuestion->selectPicturePath();
  69. $data['image_width'] = $pictureWidth;
  70. $data['image_height'] = $pictureHeight;
  71. $data['courseCode'] = $_course['path'];
  72. $data['hotspots'] = [];
  73. $data['answers'] = [];
  74. $nmbrTries = 0;
  75. while ($hotspot = Database::fetch_assoc($result)) {
  76. $hotSpot = [];
  77. $hotSpot['id'] = $hotspot['id'];
  78. $hotSpot['iid'] = $hotspot['iid'];
  79. $hotSpot['answer'] = $hotspot['answer'];
  80. // Square or rectancle
  81. if ($hotspot['hotspot_type'] == 'square') {
  82. $hotSpot['type'] = 'square';
  83. }
  84. // Circle or ovale
  85. if ($hotspot['hotspot_type'] == 'circle') {
  86. $hotSpot['type'] = 'circle';
  87. }
  88. // Polygon
  89. if ($hotspot['hotspot_type'] == 'poly') {
  90. $hotSpot['type'] = 'poly';
  91. }
  92. // Delineation
  93. if ($hotspot['hotspot_type'] == 'delineation') {
  94. $hotSpot['type'] = 'delineation';
  95. }
  96. // No error
  97. if ($hotspot['hotspot_type'] == 'noerror') {
  98. $hotSpot['type'] = 'noerror';
  99. }
  100. // This is a good answer, count + 1 for nmbr of clicks
  101. if ($hotspot['hotspot_type'] > 0) {
  102. $nmbrTries++;
  103. }
  104. $hotSpot['coord'] = $hotspot['hotspot_coordinates'];
  105. $data['hotspots'][] = $hotSpot;
  106. }
  107. $attemptList = Event::getAllExerciseEventByExeId($exerciseId);
  108. if (!empty($attemptList)) {
  109. if (isset($attemptList[$questionId])) {
  110. $questionAttempt = $attemptList[$questionId][0];
  111. if (!empty($questionAttempt['answer'])) {
  112. $coordinates = explode('|', $questionAttempt['answer']);
  113. foreach ($coordinates as $coordinate) {
  114. $data['answers'][] = Geometry::decodePoint($coordinate);
  115. }
  116. }
  117. }
  118. }
  119. $data['nmbrTries'] = $nmbrTries;
  120. $data['done'] = 'done';
  121. if (Session::has("hotspot_ordered$questionId")) {
  122. $tempHotspots = [];
  123. $hotspotOrdered = Session::read("hotspot_ordered$questionId");
  124. foreach ($hotspotOrdered as $hotspotOrder) {
  125. foreach ($data['hotspots'] as $hotspot) {
  126. if ($hotspot['id'] != $hotspotOrder) {
  127. continue;
  128. }
  129. $tempHotspots[] = $hotspot;
  130. }
  131. }
  132. $data['hotspots'] = $tempHotspots;
  133. Session::erase("hotspot_ordered$questionId");
  134. }
  135. header('Content-Type: application/json');
  136. echo json_encode($data);