hotspot_savescore.inc.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file saves every click in the hotspot tool into track_e_hotspots.
  6. *
  7. * @package chamilo.exercise
  8. *
  9. * @author Toon Keppens
  10. *
  11. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. api_protect_course_script(true);
  15. $courseCode = $_GET['coursecode'];
  16. $questionId = $_GET['questionId'];
  17. $coordinates = $_GET['coord'];
  18. $objExercise = Session::read('objExercise');
  19. $exerciseId = $objExercise->selectId();
  20. // Save clicking order
  21. $answerOrderId = count($_SESSION['exerciseResult'][$questionId]['ids']) + 1;
  22. if ($_GET['answerId'] == "0") {
  23. // click is NOT on a hotspot
  24. $hit = 0;
  25. $answerId = null;
  26. } else {
  27. // user clicked ON a hotspot
  28. $hit = 1;
  29. $answerId = api_substr($_GET['answerId'], 22, 2);
  30. // Save into session
  31. $_SESSION['exerciseResult'][$questionId][$answerId] = $hit;
  32. }
  33. //round-up the coordinates
  34. $coords = explode('/', $coordinates);
  35. $coordinates = '';
  36. foreach ($coords as $coord) {
  37. list($x, $y) = explode(';', $coord);
  38. $coordinates .= round($x).';'.round($y).'/';
  39. }
  40. $coordinates = substr($coordinates, 0, -1);
  41. $TBL_TRACK_E_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  42. // Save into db
  43. $params = [
  44. 'user_id' => api_get_user_id(),
  45. 'course_id' => $courseCode,
  46. 'quiz_id' => $exerciseId,
  47. 'question_id' => $questionId,
  48. 'answer_id' => $answerId,
  49. 'correct' => $hit,
  50. 'coordinate' => $coordinates,
  51. ];
  52. // Save insert id into session if users changes answer.
  53. $insert_id = Database::insert($TBL_TRACK_E_HOTSPOT, $params);
  54. $_SESSION['exerciseResult'][$questionId]['ids'][$answerOrderId] = $insert_id;