gradebook_statistics.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php // $Id: $
  2. /* For licensing terms, see /license.txt */
  3. $language_file= 'gradebook';
  4. //$cidReset= true;
  5. require_once ('../inc/global.inc.php');
  6. require_once ('lib/be.inc.php');
  7. require_once ('lib/gradebook_functions.inc.php');
  8. require_once ('lib/fe/dataform.class.php');
  9. require_once ('lib/scoredisplay.class.php');
  10. require_once ('lib/fe/displaygradebook.php');
  11. api_block_anonymous_users();
  12. $eval= Evaluation :: load($_GET['selecteval']);
  13. if ($eval[0]->get_category_id() < 0) {
  14. // if category id is negative, then the evaluation's origin is a link
  15. $link= LinkFactory :: get_evaluation_link($eval[0]->get_id());
  16. $currentcat= Category :: load($link->get_category_id());
  17. } else {
  18. $currentcat= Category :: load($eval[0]->get_category_id());
  19. }
  20. $interbreadcrumb[]= array (
  21. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . $currentcat[0]->get_id(), 'name' => get_lang('ToolGradebook'));
  22. if (api_is_allowed_to_create_course()){
  23. $interbreadcrumb[]= array (
  24. 'url' => 'gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']),
  25. 'name' => get_lang('ViewResult'
  26. ));
  27. }
  28. $displayscore= ScoreDisplay :: instance();
  29. Display :: display_header(get_lang('EvaluationStatistics'));
  30. DisplayGradebook :: display_header_result($eval[0], $currentcat[0]->get_id(), 0, 0);
  31. if (!$displayscore->is_custom()) {
  32. //Display :: display_error_message(get_lang('PleaseEnableScoringSystem'),false);
  33. } else {
  34. $displays= $displayscore->get_custom_score_display_settings();
  35. $allresults = Result :: load(null,null,$eval[0]->get_id());
  36. $nr_items = array();
  37. foreach ($displays as $itemsdisplay) {
  38. $nr_items[$itemsdisplay['display']] = 0;
  39. }
  40. $resultcount = 0;
  41. foreach ($allresults as $result) {
  42. $score = $result->get_score();
  43. if (isset($score)) {
  44. $display = $displayscore->display_score(array($score, $eval[0]->get_max()),SCORE_DIV | SCORE_IGNORE_SPLIT, SCORE_ONLY_CUSTOM);
  45. $nr_items[$display] ++;
  46. $resultcount ++;
  47. }
  48. }
  49. $keys = array_keys($nr_items);
  50. // find the region with the most scores, this is 100% of the bar
  51. $highest_ratio = 0;
  52. foreach ($keys as $key) {
  53. if ($nr_items[$key] > $highest_ratio){
  54. $highest_ratio = $nr_items[$key];
  55. }
  56. }
  57. // generate table
  58. $stattable= '<br><table class="data_table" cellspacing="0" cellpadding="3">';
  59. $stattable .= '<tr><th colspan="4">' . get_lang('Statistics') . '</th></tr>';
  60. $counter=0;
  61. foreach ($keys as $key) {
  62. $bar = ($highest_ratio > 0?($nr_items[$key] / $highest_ratio) * 100:0);
  63. $stattable .= '<tr class="row_' . ($counter % 2 == 0 ? 'odd' : 'even') . '">';
  64. $stattable .= '<td width="150">' . $key . '</td>';
  65. $stattable .= '<td width="550"><img src="../img/bar_1u.gif" width="' . $bar . '%" height="10"/></td>';
  66. $stattable .= '<td align="right">' . $nr_items[$key] . '</td>';
  67. $stattable .= '<td align="right"> ' . ($resultcount > 0 ?round(($nr_items[$key] / $resultcount) * 100,2):0) . '%</td>';
  68. $counter++;
  69. }
  70. $stattable .= '</tr></table>';
  71. echo $stattable;
  72. }
  73. Display :: display_footer();