hotspot_actionscript.as.php 4.7 KB

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