courseArticulate.reports.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. $extraFieldType = \Chamilo\CoreBundle\Entity\ExtraField::USER_FIELD_TYPE;
  21. // Custom Field
  22. foreach (array("tags" => "tags") as $k => $v) { // FIXME
  23. $query = 'select ufv.value as "'.$v.'" ';
  24. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  25. $query .= 'left join'.Database::get_main_table(TABLE_EXTRA_FIELD).' uf ';
  26. $query .= ' on uf.variable ="'.$k.'" ';
  27. $query .= 'left outer join '.Database::get_main_table(TABLE_EXTRA_FIELD_VALUES).' ufv ';
  28. $query .= ' on ufv.item_id = u.user_id and ufv.field_id = uf.id ';
  29. $query .= 'where ufv.extra_field_type = '.$extraFieldType.' AND u.user_id in ('.reports_getVisibilitySQL().') ';
  30. $query .= ' order by u.user_id ';
  31. $queries[] = $query;
  32. }
  33. // Stored Value
  34. $sv = array();
  35. foreach ($sv as $k => $v) {
  36. if (!isset($v['sql']))
  37. $v['sql'] = 'FIELD';
  38. $sqlField = str_replace('FIELD', 'sv.sv_value', $v['sql']);
  39. $query = 'select '.$sqlField.' as "'.$v['title'].'" ';
  40. // $query = 'select sec_to_time(sv.sv_value) as "'.$v.'" ';
  41. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  42. $query .= ' left outer join '.Database::get_main_table(TABLE_TRACK_STORED_VALUES).' sv ';
  43. $query .= 'on sv.user_id = u.user_id and sv_key = "'.$k.'" ';
  44. $query .= ' where u.user_id in ('.reports_getVisibilitySQL().') ';
  45. $query .= ' group by u.user_id ';
  46. $query .= ' order by u.user_id ';
  47. $queries[] = $query;
  48. }
  49. // first and last connection
  50. $query = 'select min(tel.login_date) as "First connection", max(tel.logout_date) as "Latest connection" ';
  51. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  52. $query .= 'left outer join '.Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN).' tel ';
  53. $query .= ' on tel.login_user_id = u.user_id ';
  54. $query .= ' where u.user_id in ('.reports_getVisibilitySQL().') ';
  55. $query .= ' group by u.user_id ';
  56. $query .= ' order by u.user_id ';
  57. $queries[] = $query;
  58. // SCORM Data
  59. $scormData = array();
  60. $course_list = CourseManager::get_courses_list();
  61. foreach ($course_list as $code => $details) {
  62. $courseId = $details['id'];
  63. $list = Database::query('SELECT l.id as lid, l.name as lname, li.id as liid, li.title as lititle '.
  64. ' FROM '.Database::get_course_table(TABLE_LP_MAIN).' l, '.Database::get_course_table(TABLE_LP_ITEM).' li '.
  65. ' WHERE l.c_id = '.$courseId.' AND li.c_id = '.$courseId.' AND l.id = li.lp_id');
  66. while ($lpItem = Database::fetch_assoc($list)) {
  67. $scormData[] = array(
  68. //'coursedb' => $details['db_name'],
  69. 'lid' => $lpItem['lid'],
  70. 'liid' => $lpItem['liid'],
  71. 'target_view_count' => 1,
  72. 'target_indicator' => 'score',
  73. 'title' => $details['title'].'/'.$lpItem['lname'].'/'.$lpItem['lititle'].'/1/score',
  74. 'sql' => 'FIELD');
  75. $scormData[] = array(
  76. //'coursedb' => $details['db_name'],
  77. 'lid' => $lpItem['lid'],
  78. 'liid' => $lpItem['liid'],
  79. 'target_view_count' => 2,
  80. 'target_indicator' => 'score',
  81. 'title' => $details['title'].'/'.$lpItem['lname'].'/'.$lpItem['lititle'].'/2/score',
  82. 'sql' => 'FIELD');
  83. $scormData[] = array(
  84. //'coursedb' => $details['db_name'],
  85. 'lid' => $lpItem['lid'],
  86. 'liid' => $lpItem['liid'],
  87. 'target_view_count' => null,
  88. 'target_indicator' => 'score',
  89. 'title' => $details['title'].'/'.$lpItem['lname'].'/'.$lpItem['lititle'].'/all/score',
  90. 'sql' => 'avg(FIELD)');
  91. }
  92. }
  93. foreach ($scormData as $v) {
  94. if (!isset($v['sql'])) {
  95. $v['sql'] = 'FIELD';
  96. }
  97. $sqlField = str_replace('FIELD', $v['target_indicator'], $v['sql']);
  98. $query = 'select '.$sqlField.' as "'.$v['title'].'" ';
  99. $query .= 'from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  100. $query .= 'left outer join '.Database::get_course_table(TABLE_LP_VIEW).' lv ';
  101. $query .= ' on u.user_id = lv.user_id and lv.lp_id = '.$v['lid'];
  102. $query .= ' left outer join '.Database::get_course_table(TABLE_LP_ITEM_VIEW).' liv ';
  103. $query .= ' on lv.id = liv.lp_view_id ';
  104. if ($v['target_view_count'])
  105. $query .= ' and liv.view_count = '.$v['target_view_count'];
  106. $query .= ' and liv.lp_item_id = '.$v['liid'].' ';
  107. $query .= ' where u.user_id in ('.reports_getVisibilitySQL().') ';
  108. $query .= ' group by u.user_id ';
  109. $query .= ' order by u.user_id ';
  110. $queries[] = $query;
  111. }
  112. return $queries;
  113. }