annotation_user.php 2.1 KB

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