hotspot_answers.as.php 5.4 KB

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