hotspot_actionscript.as.php 4.5 KB

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