hotspot_actionscript_admin.as.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. require_once __DIR__.'/../inc/global.inc.php';
  12. api_protect_course_script(false);
  13. $isAllowedToEdit = api_is_allowed_to_edit(null, true);
  14. if (!$isAllowedToEdit) {
  15. api_not_allowed(true);
  16. exit;
  17. }
  18. $_course = api_get_course_info();
  19. $questionId = isset($_GET['modifyAnswers']) ? (int) $_GET['modifyAnswers'] : 0;
  20. $objQuestion = Question::read($questionId);
  21. $picture = $objQuestion->getPicture();
  22. $pictureName = $objQuestion->getPictureFilename();
  23. $pictureWidth = $picture->getResourceNode()->getResourceFile()->getWidth();
  24. $pictureHeight = $picture->getResourceNode()->getResourceFile()->getHeight();
  25. $data = [];
  26. $data['type'] = 'admin';
  27. $data['lang'] = [
  28. 'Square' => get_lang('Square'),
  29. 'Ellipse' => get_lang('Ellipse'),
  30. 'Polygon' => get_lang('Polygon'),
  31. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  32. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  33. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  34. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  35. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  36. 'ShowHotspots' => get_lang('ShowHotspots'),
  37. 'Triesleft' => get_lang('Triesleft'),
  38. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  39. 'NextAnswer' => get_lang('NextAnswer'),
  40. 'Delineation' => get_lang('Delineation'),
  41. 'CloseDelineation' => get_lang('CloseDelineation'),
  42. 'Oar' => get_lang('Oar'),
  43. 'ClosePolygon' => get_lang('ClosePolygon'),
  44. 'DelineationStatus1' => get_lang('DelineationStatus1'),
  45. ];
  46. $data['image'] = $objQuestion->selectPicturePath();
  47. $data['image_width'] = $pictureWidth;
  48. $data['image_height'] = $pictureHeight;
  49. $data['courseCode'] = $_course['path'];
  50. $data['hotspots'] = [];
  51. $i = 0;
  52. $nmbrTries = 0;
  53. $answer_type = $objQuestion->type;
  54. $answers = Session::read('tmp_answers');
  55. $nbrAnswers = count($answers['answer']);
  56. for ($i = 1; $i <= $nbrAnswers; $i++) {
  57. $hotSpot = [];
  58. $hotSpot['id'] = null;
  59. $hotSpot['answer'] = $answers['answer'][$i];
  60. if ($answer_type == HOT_SPOT_DELINEATION) {
  61. if ($i == 1) {
  62. $hotSpot['type'] = 'delineation';
  63. } else {
  64. $hotSpot['type'] = 'oar';
  65. }
  66. } else {
  67. // Square or rectancle
  68. if ($answers['hotspot_type'][$i] == 'square') {
  69. $hotSpot['type'] = 'square';
  70. }
  71. // Circle or ovale
  72. if ($answers['hotspot_type'][$i] == 'circle') {
  73. $hotSpot['type'] = 'circle';
  74. }
  75. // Polygon
  76. if ($answers['hotspot_type'][$i] == 'poly') {
  77. $hotSpot['type'] = 'poly';
  78. }
  79. /*// Delineation
  80. if ($answers['hotspot_type'][$i] == 'delineation')
  81. {
  82. $output .= "&hotspot_".$i."_type=delineation";
  83. }*/
  84. }
  85. // This is a good answer, count + 1 for nmbr of clicks
  86. if ($answers['weighting'][$i] > 0) {
  87. $nmbrTries++;
  88. }
  89. $hotSpot['coord'] = $answers['hotspot_coordinates'][$i];
  90. $data['hotspots'][] = $hotSpot;
  91. }
  92. // Output
  93. $data['nmbrTries'] = $nmbrTries;
  94. $data['done'] = 'done';
  95. header('Content-Type: application/json');
  96. echo json_encode($data);