annotation_user.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. session_cache_limiter("none");
  5. require_once __DIR__.'/../inc/global.inc.php';
  6. $questionId = isset($_GET['question_id']) ? intval($_GET['question_id']) : 0;
  7. $exerciseId = isset($_GET['exe_id']) ? intval($_GET['exe_id']) : 0;
  8. $objQuestion = Question::read($questionId);
  9. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  10. $picturePath = $documentPath.'/images';
  11. $pictureName = $objQuestion->selectPicture();
  12. $pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
  13. $pictureWidth = $pictureSize[0];
  14. $pictureHeight = $pictureSize[1];
  15. $data = [
  16. 'use' => 'user',
  17. 'image' => [
  18. 'path' => $objQuestion->selectPicturePath(),
  19. 'width' => $pictureSize[0],
  20. 'height' => $pictureSize[1]
  21. ],
  22. 'answers' => [
  23. 'paths' => [],
  24. 'texts' => []
  25. ]
  26. ];
  27. $attemptList = Event::getAllExerciseEventByExeId($exerciseId);
  28. if (!empty($attemptList) && isset($attemptList[$questionId])) {
  29. $questionAttempt = $attemptList[$questionId][0];
  30. if (!empty($questionAttempt['answer'])) {
  31. $answers = explode('|', $questionAttempt['answer']);
  32. foreach ($answers as $answer) {
  33. $parts = explode(')(', $answer);
  34. $type = array_shift($parts);
  35. switch ($type) {
  36. case 'P':
  37. $points = [];
  38. foreach ($parts as $partPoint) {
  39. $points[] = Geometry::decodePoint($partPoint);
  40. }
  41. $data['answers']['paths'][] = $points;
  42. break;
  43. case 'T':
  44. $text = [
  45. 'text' => array_shift($parts)
  46. ];
  47. $data['answers']['texts'][] = $text + Geometry::decodePoint($parts[0]);
  48. break;
  49. }
  50. }
  51. }
  52. }
  53. header('Content-Type: application/json');
  54. echo json_encode($data);