gradebook_statistics.php 3.2 KB

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