live_stats.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* See license terms in /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. $this_section = SECTION_COURSES;
  5. $exercise_id = (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) ? intval($_GET['exerciseId']) : 0;
  6. api_protect_course_script(true);
  7. if (!api_is_allowed_to_edit()) {
  8. api_not_allowed();
  9. }
  10. $objExercise = new Exercise();
  11. $result = $objExercise->read($exercise_id);
  12. if (!$result) {
  13. api_not_allowed(true);
  14. }
  15. $interbreadcrumb[] = [
  16. "url" => "exercise.php?".api_get_cidreq(),
  17. "name" => get_lang('Tests'),
  18. ];
  19. $interbreadcrumb[] = [
  20. "url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(),
  21. "name" => $objExercise->selectTitle(true),
  22. ];
  23. //Add the JS needed to use the jqgrid
  24. $htmlHeadXtra[] = api_get_jqgrid_js();
  25. // The header.
  26. Display::display_header(get_lang('Learners who\'re taking the exercise right now'));
  27. //jqgrid will use this URL to do the selects
  28. $minutes = 60;
  29. $url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=get_live_stats&exercise_id='.$objExercise->id.'&minutes='.$minutes;
  30. //The order is important you need to check the the $column variable in the model.ajax.php file
  31. $columns = [get_lang('First name'), get_lang('Last name'), get_lang('Time'), get_lang('Questions already answered'), get_lang('Score')];
  32. //Column config
  33. $column_model = [
  34. [
  35. 'name' => 'firstname',
  36. 'index' => 'firstname',
  37. 'width' => '100',
  38. 'align' => 'left',
  39. ],
  40. [
  41. 'name' => 'lastname',
  42. 'index' => 'lastname',
  43. 'width' => '100',
  44. 'align' => 'left',
  45. ],
  46. [
  47. 'name' => 'start_date',
  48. 'index' => 'start_date',
  49. 'width' => '100',
  50. 'align' => 'left',
  51. ],
  52. [
  53. 'name' => 'question',
  54. 'index' => 'count_questions',
  55. 'width' => '60',
  56. 'align' => 'left',
  57. 'sortable' => 'false',
  58. ],
  59. [
  60. 'name' => 'score',
  61. 'index' => 'score',
  62. 'width' => '50',
  63. 'align' => 'left',
  64. 'sortable' => 'false',
  65. ],
  66. ];
  67. //Autowidth
  68. $extra_params['autowidth'] = 'true';
  69. //height auto
  70. $extra_params['height'] = 'auto';
  71. ?>
  72. <script>
  73. function refreshGrid() {
  74. var grid = $("#live_stats");
  75. grid.trigger("reloadGrid");
  76. t = setTimeout("refreshGrid()", 10000);
  77. }
  78. $(function() {
  79. <?php
  80. echo Display::grid_js(
  81. 'live_stats',
  82. $url,
  83. $columns,
  84. $column_model,
  85. $extra_params,
  86. [],
  87. null,
  88. true
  89. );
  90. ?>
  91. refreshGrid();
  92. });
  93. </script>
  94. <?php
  95. $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">'.
  96. Display::return_icon('back.png', get_lang('Go back to the questions list'), '', ICON_SIZE_MEDIUM).'</a>';
  97. echo $actions = Display::div($actions, ['class' => 'actions']);
  98. echo Display::grid_html('live_stats');
  99. Display::display_footer();