annotation_user.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $pictureSize = getimagesize($picturePath.'/'.$objQuestion->getPictureFilename());
  12. $pictureWidth = $pictureSize[0];
  13. $pictureHeight = $pictureSize[1];
  14. $data = [
  15. 'use' => 'user',
  16. 'image' => [
  17. 'path' => $objQuestion->selectPicturePath(),
  18. 'width' => $pictureSize[0],
  19. 'height' => $pictureSize[1]
  20. ],
  21. 'answers' => [
  22. 'paths' => [],
  23. 'texts' => []
  24. ]
  25. ];
  26. $attemptList = Event::getAllExerciseEventByExeId($exerciseId);
  27. if (!empty($attemptList) && isset($attemptList[$questionId])) {
  28. $questionAttempt = $attemptList[$questionId][0];
  29. if (!empty($questionAttempt['answer'])) {
  30. $answers = explode('|', $questionAttempt['answer']);
  31. foreach ($answers as $answer) {
  32. $parts = explode(')(', $answer);
  33. $type = array_shift($parts);
  34. switch ($type) {
  35. case 'P':
  36. $points = [];
  37. foreach ($parts as $partPoint) {
  38. $points[] = Geometry::decodePoint($partPoint);
  39. }
  40. $data['answers']['paths'][] = $points;
  41. break;
  42. case 'T':
  43. $text = [
  44. 'text' => array_shift($parts)
  45. ];
  46. $data['answers']['texts'][] = $text + Geometry::decodePoint($parts[0]);
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. header('Content-Type: application/json');
  53. echo json_encode($data);