hotspot_actionscript.as.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 iid, 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 iid";
  30. } else {
  31. $sql = "SELECT iid, id, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS
  32. WHERE c_id = $course_id AND question_id = ".intval($questionId)." ORDER BY iid";
  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['iid'] = $hotspot['iid'];
  68. $hotSpot['answer'] = $hotspot['answer'];
  69. // Square or rectancle
  70. if ($hotspot['hotspot_type'] == 'square' )
  71. {
  72. $hotSpot['type'] = 'square';
  73. }
  74. // Circle or ovale
  75. if ($hotspot['hotspot_type'] == 'circle')
  76. {
  77. $hotSpot['type'] = 'circle';
  78. }
  79. // Polygon
  80. if ($hotspot['hotspot_type'] == 'poly')
  81. {
  82. $hotSpot['type'] = 'poly';
  83. }
  84. // Delineation
  85. if ($hotspot['hotspot_type'] == 'delineation')
  86. {
  87. $hotSpot['type'] = 'delineation';
  88. }
  89. // No error
  90. if ($hotspot['hotspot_type'] == 'noerror')
  91. {
  92. $hotSpot['type'] = 'noerror';
  93. }
  94. // This is a good answer, count + 1 for nmbr of clicks
  95. if ($hotspot['hotspot_type'] > 0)
  96. {
  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->getAnswer())) {
  107. $coordinates = explode('|', $questionAttempt->getAnswer());
  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')) {
  117. $tempHotspots = [];
  118. $hotspotOrdered = Session::read('hotspot_ordered');
  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');
  129. }
  130. header('Content-Type: application/json');
  131. echo json_encode($data);