exercicesMultiCourses.reports.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // @deprecated? @todo check if this file is used
  3. $reports_template['exercicesMultiCourses'] = array(
  4. 'description' => 'Result of each test per student',
  5. 'getSQL' => 'reports_template_exercicesMultiCourses_getSQL',
  6. 'wizard' =>
  7. '
  8. <span id="exercicesMultiCourses" class="step">
  9. <span class="font_normal_07em_black">Result of each test per student</span><br />
  10. <!-- <label for="scoremin">Score min</label><br />
  11. <input class="input_field_25em" name="scoremin" id="scoremin" value="0"><br />
  12. <label for="scoremax">Score max</label><br />
  13. <input class="input_field_25em" name="scoremax" id="scoremax" value="0"><br />
  14. --> <label for="tattempt">How to treat Attempts</label><br />
  15. <select name="tattempt" id="tattempt">
  16. <!-- <option value="first">take only the first one</option>
  17. <option value="last">take only the last one</option>
  18. --> <option value="avg">take the average value</option>
  19. <option value="min">take the minimum value</option>
  20. <option value="max">take the maximum value</option>
  21. </select><br />
  22. <!-- <label name="gcourses">Do you want to group quiz per courses</label><br />
  23. <select name="gcourses" id="gcourses">
  24. <option value="nogroup">Do not group</option>
  25. <option value="average">group and take the average value</option>
  26. <option value="min">group and take the minimum value</option>
  27. <option value="max">group and take the maximum value</option>
  28. </select><br />
  29. --> <input type="hidden" class="link" value="format" />
  30. </span>
  31. ');
  32. function reports_template_exercicesMultiCourses_getSQL()
  33. {
  34. // foreach quiz
  35. $result = array();
  36. $columns = Database::query('select r.id as kid, c.title as course, '.
  37. 'r.child_name as test from '.
  38. Database::get_main_table(TABLE_MAIN_REPORTS_KEYS).' r, '.
  39. Database::get_main_table(TABLE_MAIN_COURSE).' c '.
  40. 'where r.course_id=c.id and r.tool_id='.
  41. reports_getToolId(TOOL_QUIZ).
  42. ' order by r.course_id, r.child_name');
  43. if (Database::num_rows($columns) == 0)
  44. die('<b>'.get_lang('no data found').'</b>');
  45. $query = 'select u.lastname Name, u.firstname Firstname';
  46. $columns = Database::store_result($columns);
  47. if ($_REQUEST['tattempt'] == 'min' || $_REQUEST['tattempt'] == 'max')
  48. $function = $_REQUEST['tattempt'];
  49. else
  50. $function = 'avg';
  51. foreach ($columns as $key => $column)
  52. $query .= ', '.$function.'(k'.$key.'.score) as `'.
  53. $column['course'].' - '.
  54. $column['test'].'` ';
  55. $query .= ' from '.Database::get_main_table(TABLE_MAIN_USER).' u ';
  56. foreach ($columns as $key => $column) // fixme sessions
  57. $query .= 'left outer join '.
  58. Database::get_main_table(TABLE_MAIN_REPORTS_VALUES).
  59. ' k'.$key.
  60. ' on k'.$key.'.key_id = '.$column['kid'].
  61. ' and k'.$key.'.user_id = u.user_id ';
  62. $query .= ' group by ';
  63. foreach ($columns as $key => $column) // grouping attempt
  64. $query .= 'k'.$key.'.attempt, ';
  65. $query = substr($query, 0, -2); // removing last ', ';
  66. return $query;
  67. }