gradebook_statistics.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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' => Category::getUrl().'selectcat='.$currentcat[0]->get_id(),
  19. 'name' => get_lang('ToolGradebook')
  20. );
  21. if (api_is_allowed_to_edit()) {
  22. $interbreadcrumb[] = array(
  23. 'url' => 'gradebook_view_result.php?selecteval='.Security::remove_XSS($_GET['selecteval']).'&'.api_get_cidreq(),
  24. 'name' => get_lang('ViewResult')
  25. );
  26. }
  27. $displayscore = ScoreDisplay :: instance();
  28. Display::display_header(get_lang('EvaluationStatistics'));
  29. DisplayGradebook::display_header_result(
  30. $eval[0],
  31. $currentcat[0]->get_id(),
  32. 0,
  33. 'statistics'
  34. );
  35. //Bad, Regular, Good - User definitions
  36. $displays = $displayscore->get_custom_score_display_settings();
  37. if (!$displayscore->is_custom() || empty($displays)) {
  38. if (api_is_platform_admin() || api_is_course_admin()) {
  39. echo Display::return_message(get_lang('PleaseEnableScoringSystem'), 'error', false);
  40. }
  41. } else {
  42. $allresults = Result::load(null, null, $eval[0]->get_id());
  43. $nr_items = array();
  44. foreach ($displays as $itemsdisplay) {
  45. $nr_items[$itemsdisplay['display']] = 0;
  46. }
  47. $resultcount = 0;
  48. foreach ($allresults as $result) {
  49. $score = $result->get_score();
  50. if (isset($score)) {
  51. $display = $displayscore->display_score(
  52. array($score, $eval[0]->get_max()),
  53. SCORE_CUSTOM,
  54. SCORE_ONLY_CUSTOM,
  55. true
  56. );
  57. $nr_items[$display]++;
  58. $resultcount++;
  59. }
  60. }
  61. $keys = array_keys($nr_items);
  62. // find the region with the most scores, this is 100% of the bar
  63. $highest_ratio = 0;
  64. foreach ($keys as $key) {
  65. if ($nr_items[$key] > $highest_ratio) {
  66. $highest_ratio = $nr_items[$key];
  67. }
  68. }
  69. // Generate table
  70. $stattable = '<table class="data_table" cellspacing="0" cellpadding="3">';
  71. $stattable .= '<tr><th>'.get_lang('ScoringSystem').'</th>';
  72. $stattable .= '<th>'.get_lang('Percentage').'</th>';
  73. $stattable .= '<th>'.get_lang('CountUsers').'</th>';
  74. //$stattable .= '<th>' . get_lang('Statistics') . '</th></tr>';
  75. $counter = 0;
  76. foreach ($keys as $key) {
  77. $bar = ($highest_ratio > 0 ? ($nr_items[$key] / $highest_ratio) * 100 : 0);
  78. $stattable .= '<tr class="row_'.($counter % 2 == 0 ? 'odd' : 'even').'">';
  79. $stattable .= '<td width="150">'.$key.'</td>';
  80. $stattable .= '<td width="550">'.Display::bar_progress($bar).'</td>';
  81. $stattable .= '<td align="right">'.$nr_items[$key].'</td>';
  82. $counter++;
  83. }
  84. $stattable .= '</tr></table>';
  85. echo $stattable;
  86. }
  87. Display :: display_footer();