courseTime.reports.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. $reports_template['courseTime'] = array(
  4. 'description' => 'Time spent by students in each courses',
  5. 'getSQL' => 'reports_template_courseTime_getSQL',
  6. 'wizard' =>
  7. '
  8. <span id="courseTime" class="step">
  9. <span class="font_normal_07em_black">This test does not need any particular settings</span><br />
  10. <input type="hidden" class="link" value="format" />
  11. </span>
  12. ');*/
  13. function reports_template_courseTime_getSQL() {
  14. // fetch columns
  15. $result = array();
  16. $query = 'select r.id as kid, c.title as course '.
  17. 'from '.
  18. Database::get_main_table(TABLE_MAIN_REPORTS_KEYS).' r, '.
  19. Database::get_main_table(TABLE_MAIN_COURSE).' c '.
  20. 'where r.course_id=c.id and r.tool_id is null and r.child_id is null'.
  21. ' order by c.title';
  22. $columns = Database::query($query);
  23. if (Database::num_rows($columns) == 0)
  24. die('<b>'.get_lang('no data found: '.$query).'</b>');
  25. $columns = Database::store_result($columns);
  26. // fetch data
  27. $query = 'select u.lastname Name, u.firstname Firstname';
  28. foreach ($columns as $key => $column)
  29. $query .= ', sec_to_time(k'.$key.'.report_time) as `'.
  30. $column['course'].'` ';
  31. $query .= ' from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  32. foreach ($columns as $key => $column) // fixme sessions
  33. $query .= 'left outer join '.
  34. Database::get_main_table(TABLE_MAIN_REPORTS_VALUES).
  35. ' k'.$key.
  36. ' on k'.$key.'.key_id = '.$column['kid'].
  37. ' and k'.$key.'.user_id = u.user_id ';
  38. return $query;
  39. }