hotspot_answers.as.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. require_once __DIR__.'/../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->getPictureFilename();
  23. $pictureSize = getimagesize($picturePath.'/'.$pictureName);
  24. $pictureWidth = $pictureSize[0];
  25. $pictureHeight = $pictureSize[1];
  26. $course_id = api_get_course_int_id();
  27. $data = [];
  28. $data['type'] = 'solution';
  29. $data['lang'] = [
  30. 'Square' => get_lang('Square'),
  31. 'Ellipse' => get_lang('Ellipse'),
  32. 'Polygon' => get_lang('Polygon'),
  33. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  34. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  35. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  36. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  37. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  38. 'ShowHotspots' => get_lang('ShowHotspots'),
  39. 'Triesleft' => get_lang('Triesleft'),
  40. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  41. 'NextAnswer' => get_lang('NextAnswer'),
  42. 'Delineation' => get_lang('Delineation'),
  43. 'CloseDelineation' => get_lang('CloseDelineation'),
  44. 'Oar' => get_lang('Oar'),
  45. 'ClosePolygon' => get_lang('ClosePolygon'),
  46. 'DelineationStatus1' => get_lang('DelineationStatus1')
  47. ];
  48. $data['image'] = $objQuestion->selectPicturePath();
  49. $data['image_width'] = $pictureWidth;
  50. $data['image_height'] = $pictureHeight;
  51. $data['courseCode'] = $_course['path'];
  52. $data['hotspots'] = [];
  53. $showTotalScoreAndUserChoicesInLastAttempt = true;
  54. if ($objExercise->selectResultsDisabled() == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
  55. $showOnlyScore = true;
  56. $showResults = true;
  57. if ($objExercise->attempts > 0) {
  58. $attempts = Event::getExerciseResultsByUser(
  59. api_get_user_id(),
  60. $objExercise->id,
  61. api_get_course_int_id(),
  62. api_get_session_id(),
  63. $trackExerciseInfo['orig_lp_id'],
  64. $trackExerciseInfo['orig_lp_item_id'],
  65. 'desc'
  66. );
  67. $numberAttempts = count($attempts);
  68. $showTotalScoreAndUserChoicesInLastAttempt = false;
  69. if ($numberAttempts >= $objExercise->attempts) {
  70. $showResults = true;
  71. $showOnlyScore = false;
  72. $showTotalScoreAndUserChoicesInLastAttempt = true;
  73. }
  74. }
  75. }
  76. $hideExpectedAnswer = false;
  77. if ($objExercise->selectFeedbackType() == 0 && $objExercise->selectResultsDisabled() == 2) {
  78. $hideExpectedAnswer = true;
  79. }
  80. if ($objExercise->selectResultsDisabled() == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
  81. $hideExpectedAnswer = $showTotalScoreAndUserChoicesInLastAttempt ? false : true;
  82. }
  83. if (!$hideExpectedAnswer) {
  84. $qb = $em->createQueryBuilder();
  85. $qb
  86. ->select('a')
  87. ->from('ChamiloCourseBundle:CQuizAnswer', 'a');
  88. if ($objQuestion->selectType() == HOT_SPOT_DELINEATION) {
  89. $qb
  90. ->where($qb->expr()->eq('a.cId', $course_id))
  91. ->andWhere($qb->expr()->eq('a.questionId', intval($questionId)))
  92. ->andWhere($qb->expr()->neq('a.hotspotType', 'noerror'))
  93. ->orderBy('a.id', 'ASC');
  94. } else {
  95. $qb
  96. ->where($qb->expr()->eq('a.cId', $course_id))
  97. ->andWhere($qb->expr()->eq('a.questionId', intval($questionId)))
  98. ->orderBy('a.position', 'ASC');
  99. }
  100. $result = $qb->getQuery()->getResult();
  101. /** @var CQuizAnswer $hotSpotAnswer */
  102. foreach ($result as $hotSpotAnswer) {
  103. $hotSpot = [];
  104. $hotSpot['id'] = $hotSpotAnswer->getIid();
  105. $hotSpot['answer'] = $hotSpotAnswer->getAnswer();
  106. switch ($hotSpotAnswer->getHotspotType()) {
  107. case 'square':
  108. $hotSpot['type'] = 'square';
  109. break;
  110. case 'circle':
  111. $hotSpot['type'] = 'circle';
  112. break;
  113. case 'poly':
  114. $hotSpot['type'] = 'poly';
  115. break;
  116. case 'delineation':
  117. $hotSpot['type'] = 'delineation';
  118. break;
  119. case 'oar':
  120. $hotSpot['type'] = 'delineation';
  121. break;
  122. }
  123. $hotSpot['coord'] = $hotSpotAnswer->getHotspotCoordinates();
  124. $data['hotspots'][] = $hotSpot;
  125. }
  126. }
  127. $data['answers'] = [];
  128. $rs = $em
  129. ->getRepository('ChamiloCoreBundle:TrackEHotspot')
  130. ->findBy(
  131. [
  132. 'hotspotQuestionId' => $questionId,
  133. 'cId' => $course_id,
  134. 'hotspotExeId' => $exe_id
  135. ],
  136. ['hotspotAnswerId' => 'ASC']
  137. );
  138. /** @var TrackEHotspot $row */
  139. foreach ($rs as $row) {
  140. $data['answers'][] = $row->getHotspotCoordinate();
  141. }
  142. $data['done'] = 'done';
  143. header('Content-Type: application/json');
  144. echo json_encode($data);