gradebook_statistics.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. api_block_anonymous_users();
  8. $eval= Evaluation :: load($_GET['selecteval']);
  9. if ($eval[0]->get_category_id() < 0) {
  10. // if category id is negative, then the evaluation's origin is a link
  11. $link= LinkFactory :: get_evaluation_link($eval[0]->get_id());
  12. $currentcat = Category :: load($link->get_category_id());
  13. } else {
  14. $currentcat = Category :: load($eval[0]->get_category_id());
  15. }
  16. $interbreadcrumb[]= array (
  17. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . $currentcat[0]->get_id(), 'name' => get_lang('ToolGradebook'));
  18. if (api_is_allowed_to_edit()) {
  19. $interbreadcrumb[]= array (
  20. 'url' => 'gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']).'&'.api_get_cidreq(),
  21. 'name' => get_lang('ViewResult')
  22. );
  23. }
  24. $displayscore = ScoreDisplay :: instance();
  25. Display::display_header(get_lang('EvaluationStatistics'));
  26. DisplayGradebook::display_header_result(
  27. $eval[0],
  28. $currentcat[0]->get_id(),
  29. 0,
  30. 'statistics'
  31. );
  32. //Bad, Regular, Good - User definitions
  33. $displays = $displayscore->get_custom_score_display_settings();
  34. if (!$displayscore->is_custom() || empty($displays)) {
  35. if (api_is_platform_admin() || api_is_course_admin()) {
  36. Display :: display_error_message(get_lang('PleaseEnableScoringSystem'), false);
  37. }
  38. } else {
  39. $allresults = Result::load(null,null,$eval[0]->get_id());
  40. $nr_items = array();
  41. foreach ($displays as $itemsdisplay) {
  42. $nr_items[$itemsdisplay['display']] = 0;
  43. }
  44. $resultcount = 0;
  45. foreach ($allresults as $result) {
  46. $score = $result->get_score();
  47. if (isset($score)) {
  48. $display = $displayscore->display_score(
  49. array($score, $eval[0]->get_max()),
  50. SCORE_CUSTOM,
  51. SCORE_ONLY_CUSTOM,
  52. true
  53. );
  54. $nr_items[$display]++;
  55. $resultcount++;
  56. }
  57. }
  58. $keys = array_keys($nr_items);
  59. // find the region with the most scores, this is 100% of the bar
  60. $highest_ratio = 0;
  61. foreach ($keys as $key) {
  62. if ($nr_items[$key] > $highest_ratio) {
  63. $highest_ratio = $nr_items[$key];
  64. }
  65. }
  66. // Generate table
  67. $stattable= '<table class="data_table" cellspacing="0" cellpadding="3">';
  68. $stattable .= '<tr><th>' . get_lang('ScoringSystem') . '</th>';
  69. $stattable .= '<th>' . get_lang('Percentage') . '</th>';
  70. $stattable .= '<th>' . get_lang('CountUsers') . '</th>';
  71. //$stattable .= '<th>' . get_lang('Statistics') . '</th></tr>';
  72. $counter=0;
  73. foreach ($keys as $key) {
  74. $bar = ($highest_ratio > 0?($nr_items[$key] / $highest_ratio) * 100:0);
  75. $stattable .= '<tr class="row_' . ($counter % 2 == 0 ? 'odd' : 'even') . '">';
  76. $stattable .= '<td width="150">' . $key . '</td>';
  77. $stattable .= '<td width="550">'.Display::bar_progress($bar).'</td>';
  78. $stattable .= '<td align="right">' . $nr_items[$key] . '</td>';
  79. $counter++;
  80. }
  81. $stattable .= '</tr></table>';
  82. echo $stattable;
  83. }
  84. Display :: display_footer();