hotspot_savescore.inc.php 1.6 KB

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