courseArticulate.reports.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. $reports_template['CourseArticulate'] = array(
  3. 'description' => 'CourseArticulate',
  4. 'getSQL' => 'reports_template_CourseArticulate_getSQL',
  5. 'wizard' =>
  6. '
  7. <span id="CourseArticulate" class="step">
  8. <span class="font_normal_07em_black">This report does not need any particular settings</span><br />
  9. <input type="hidden" class="link" value="format" />
  10. </span>
  11. ');
  12. function reports_template_CourseArticulate_getSQL() {
  13. // settings
  14. // Nom, prenom
  15. $query = 'select u.lastname as "Last name", u.firstname as "First name" ';
  16. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  17. $query .= ' where u.user_id in ('.reports_getVisibilitySQL().') ';
  18. $query .= ' order by u.user_id ';
  19. $queries[0] = $query;
  20. // Custom Field
  21. foreach (array("tags" => "tags") as $k => $v) { // FIXME
  22. $query = 'select ufv.field_value as "'.$v.'" ';
  23. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  24. $query .= 'left join'.Database::get_main_table(TABLE_MAIN_USER_FIELD).' uf ';
  25. $query .= ' on uf.field_variable="'.$k.'" ';
  26. $query .= 'left outer join '.Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES).' ufv ';
  27. $query .= ' on ufv.user_id = u.user_id and ufv.field_id = uf.id ';
  28. $query .= 'where u.user_id in ('.reports_getVisibilitySQL().') ';
  29. $query .= ' order by u.user_id ';
  30. $queries[] = $query;
  31. }
  32. // Stored Value
  33. $sv = array();
  34. foreach ($sv as $k => $v) {
  35. if (!isset($v['sql']))
  36. $v['sql'] = 'FIELD';
  37. $sqlField = str_replace('FIELD', 'sv.sv_value', $v['sql']);
  38. $query = 'select '.$sqlField.' as "'.$v['title'].'" ';
  39. // $query = 'select sec_to_time(sv.sv_value) as "'.$v.'" ';
  40. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  41. $query .= ' left outer join '.Database::get_main_table(TABLE_TRACK_STORED_VALUES).' sv ';
  42. $query .= 'on sv.user_id = u.user_id and sv_key = "'.$k.'" ';
  43. $query .= ' where u.user_id in ('.reports_getVisibilitySQL().') ';
  44. $query .= ' group by u.user_id ';
  45. $query .= ' order by u.user_id ';
  46. $queries[] = $query;
  47. }
  48. // first and last connection
  49. $query = 'select min(tel.login_date) as "First connection", max(tel.logout_date) as "Latest connection" ';
  50. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  51. $query .= 'left outer join '.Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN).' tel ';
  52. $query .= ' on tel.login_user_id = u.user_id ';
  53. $query .= ' where u.user_id in ('.reports_getVisibilitySQL().') ';
  54. $query .= ' group by u.user_id ';
  55. $query .= ' order by u.user_id ';
  56. $queries[] = $query;
  57. // SCORM Data
  58. $scormData = array();
  59. $course_list = CourseManager::get_real_course_list();
  60. foreach ($course_list as $code => $details) {
  61. $list = Database::query('SELECT l.id as lid, l.name as lname, li.id as liid, li.title as lititle '.
  62. ' FROM '.Database::get_course_table(TABLE_LP_MAIN).' l, '.Database::get_course_table(TABLE_LP_ITEM).' li '.
  63. ' WHERE l.c_id = '.$details['real_id'].' AND li.c_id = '.$details['real_id'].' AND l.id = li.lp_id');
  64. while ($lpItem = Database::fetch_assoc($list)) {
  65. $scormData[] = array('coursedb' => $details['db_name'],
  66. 'lid' => $lpItem['lid'],
  67. 'liid' => $lpItem['liid'],
  68. 'target_view_count' => 1,
  69. 'target_indicator' => 'score',
  70. 'title' => $details['title'].'/'.$lpItem['lname'].'/'.$lpItem['lititle'].'/1/score',
  71. 'sql' => 'FIELD');
  72. $scormData[] = array('coursedb' => $details['db_name'],
  73. 'lid' => $lpItem['lid'],
  74. 'liid' => $lpItem['liid'],
  75. 'target_view_count' => 2,
  76. 'target_indicator' => 'score',
  77. 'title' => $details['title'].'/'.$lpItem['lname'].'/'.$lpItem['lititle'].'/2/score',
  78. 'sql' => 'FIELD');
  79. $scormData[] = array('coursedb' => $details['db_name'],
  80. 'lid' => $lpItem['lid'],
  81. 'liid' => $lpItem['liid'],
  82. 'target_view_count' => null,
  83. 'target_indicator' => 'score',
  84. 'title' => $details['title'].'/'.$lpItem['lname'].'/'.$lpItem['lititle'].'/all/score',
  85. 'sql' => 'avg(FIELD)');
  86. }
  87. }
  88. foreach($scormData as $v) {
  89. if (!isset($v['sql']))
  90. $v['sql'] = 'FIELD';
  91. $sqlField = str_replace('FIELD', $v['target_indicator'], $v['sql']);
  92. $query = 'select '.$sqlField.' as "'.$v['title'].'" ';
  93. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  94. $query .= 'left outer join '.Database::get_course_table(TABLE_LP_VIEW, $details['db_name']).' lv ';
  95. $query .= ' on u.user_id = lv.user_id and lv.lp_id = '.$v['lid'];
  96. $query .= ' left outer join '.Database::get_course_table(TABLE_LP_ITEM_VIEW, $details['db_name']).' liv ';
  97. $query .= ' on lv.id = liv.lp_view_id ';
  98. if ($v['target_view_count'])
  99. $query .= ' and liv.view_count = '.$v['target_view_count'];
  100. $query .= ' and liv.lp_item_id = '.$v['liid'].' ';
  101. $query .= ' where u.user_id in ('.reports_getVisibilitySQL().') ';
  102. $query .= ' group by u.user_id ';
  103. $query .= ' order by u.user_id ';
  104. $queries[] = $query;
  105. }
  106. return $queries;
  107. }