hotspot_answers.as.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file generates the ActionScript variables code used by the
  5. * HotSpot .swf
  6. * @package chamilo.exercise
  7. * @author Toon Keppens, Julio Montoya adding hotspot "medical" support
  8. */
  9. include '../inc/global.inc.php';
  10. // Set vars
  11. $questionId = intval($_GET['modifyAnswers']);
  12. $exe_id = intval($_GET['exe_id']);
  13. $objQuestion = Question::read($questionId);
  14. $trackExerciseInfo = ExerciseLib::get_exercise_track_exercise_info($exe_id);
  15. $objExercise = new Exercise(api_get_course_int_id());
  16. $objExercise->read($trackExerciseInfo['exe_exo_id']);
  17. $em = Database::getManager();
  18. $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  19. $picturePath = $documentPath . '/images';
  20. $pictureName = $objQuestion->selectPicture();
  21. $pictureSize = getimagesize($picturePath . '/' . $objQuestion->selectPicture());
  22. $pictureWidth = $pictureSize[0];
  23. $pictureHeight = $pictureSize[1];
  24. $course_id = api_get_course_int_id();
  25. // Init
  26. $data = [];
  27. $data['type'] = 'solution';
  28. $data['lang'] = [
  29. 'Square' => get_lang('Square'),
  30. 'Ellipse' => get_lang('Ellipse'),
  31. 'Polygon' => get_lang('Polygon'),
  32. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  33. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  34. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  35. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  36. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  37. 'ShowHotspots' => get_lang('ShowHotspots'),
  38. 'Triesleft' => get_lang('Triesleft'),
  39. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  40. 'NextAnswer' => get_lang('NextAnswer'),
  41. 'Delineation' => get_lang('Delineation'),
  42. 'CloseDelineation' => get_lang('CloseDelineation'),
  43. 'Oar' => get_lang('Oar'),
  44. 'ClosePolygon' => get_lang('ClosePolygon'),
  45. 'DelineationStatus1' => get_lang('DelineationStatus1')
  46. ];
  47. $data['image'] = $objQuestion->selectPicturePath();
  48. $data['image_width'] = $pictureWidth;
  49. $data['image_height'] = $pictureHeight;
  50. $data['courseCode'] = $_course['path'];
  51. $data['hotspots'] = [];
  52. if ($objExercise->results_disabled != RESULT_DISABLE_SHOW_SCORE_ONLY) {
  53. $qb = $em->createQueryBuilder();
  54. $qb
  55. ->select('a')
  56. ->from('ChamiloCourseBundle:CQuizAnswer', 'a');
  57. if ($objQuestion->selectType() == HOT_SPOT_DELINEATION) {
  58. $qb
  59. ->where($qb->expr()->eq('a.cId', $course_id))
  60. ->andWhere($qb->expr()->eq('a.questionId', intval($questionId)))
  61. ->andWhere($qb->expr()->neq('a.hotspotType', 'noerror'));
  62. } else {
  63. $qb
  64. ->where($qb->expr()->eq('a.cId', $course_id))
  65. ->andWhere($qb->expr()->eq('a.questionId', intval($questionId)));
  66. }
  67. $result = $qb
  68. ->orderBy('a.id', 'ASC')
  69. ->getQuery()
  70. ->getResult();
  71. foreach ($result as $hotspotAnswer) {
  72. $hotSpot = [];
  73. $hotSpot['id'] = $hotspotAnswer->getId();
  74. $hotSpot['answer'] = $hotspotAnswer->getAnswer();
  75. switch ($hotspotAnswer->getHotspotType()) {
  76. case 'square':
  77. $hotSpot['type'] = 'square';
  78. break;
  79. case 'circle':
  80. $hotSpot['type'] = 'circle';
  81. break;
  82. case 'poly':
  83. $hotSpot['type'] = 'poly';
  84. break;
  85. case 'delineation':
  86. $hotSpot['type'] = 'delineation';
  87. break;
  88. case 'oar':
  89. $hotSpot['type'] = 'delineation';
  90. break;
  91. }
  92. $hotSpot['coord'] = $hotspotAnswer->getHotspotCoordinates();
  93. $data['hotspots'][] = $hotSpot;
  94. }
  95. }
  96. $data['answers'] = [];
  97. $rs = $em
  98. ->getRepository('ChamiloCoreBundle:TrackEHotspot')
  99. ->findBy(
  100. [
  101. 'hotspotQuestionId' => $questionId,
  102. 'cId' => $course_id,
  103. 'hotspotExeId' => $exe_id
  104. ],
  105. ['hotspotId' => 'ASC']
  106. );
  107. foreach ($rs as $row) {
  108. $data['answers'][] = $row->getHotspotCoordinate();
  109. }
  110. $data['done'] = 'done';
  111. header('Content-Type: application/json');
  112. echo json_encode($data);