gradebook_statistics.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. /**
  8. * Init
  9. */
  10. $language_file= array('gradebook','tracking');
  11. require_once '../inc/global.inc.php';
  12. require_once 'lib/be.inc.php';
  13. require_once 'lib/gradebook_functions.inc.php';
  14. require_once 'lib/fe/dataform.class.php';
  15. require_once 'lib/scoredisplay.class.php';
  16. require_once 'lib/fe/displaygradebook.php';
  17. api_block_anonymous_users();
  18. $eval= Evaluation :: load($_GET['selecteval']);
  19. if ($eval[0]->get_category_id() < 0) {
  20. // if category id is negative, then the evaluation's origin is a link
  21. $link= LinkFactory :: get_evaluation_link($eval[0]->get_id());
  22. $currentcat = Category :: load($link->get_category_id());
  23. } else {
  24. $currentcat = Category :: load($eval[0]->get_category_id());
  25. }
  26. $interbreadcrumb[]= array (
  27. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . $currentcat[0]->get_id(), 'name' => get_lang('ToolGradebook'));
  28. if (api_is_allowed_to_edit()) {
  29. $interbreadcrumb[]= array (
  30. 'url' => 'gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']),
  31. 'name' => get_lang('ViewResult'
  32. ));
  33. }
  34. $displayscore = ScoreDisplay :: instance();
  35. Display::display_header(get_lang('EvaluationStatistics'));
  36. DisplayGradebook::display_header_result($eval[0], $currentcat[0]->get_id(), 0, 'statistics');
  37. //Bad, Regular, Good - User definitions
  38. $displays = $displayscore->get_custom_score_display_settings();
  39. if (!$displayscore->is_custom() || empty($displays)) {
  40. if (api_is_platform_admin() || api_is_course_admin()) {
  41. Display :: display_error_message(get_lang('PleaseEnableScoringSystem'),false);
  42. }
  43. } else {
  44. $allresults = Result::load(null,null,$eval[0]->get_id());
  45. $nr_items = array();
  46. foreach ($displays as $itemsdisplay) {
  47. $nr_items[$itemsdisplay['display']] = 0;
  48. }
  49. $resultcount = 0;
  50. foreach ($allresults as $result) {
  51. $score = $result->get_score();
  52. if (isset($score)) {
  53. $display = $displayscore->display_score(array($score, $eval[0]->get_max()), SCORE_CUSTOM, SCORE_ONLY_CUSTOM, true);
  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();