exercicesMultiCourses.reports.php 2.8 KB

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