gradebook_statistics.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once '../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($eval[0], $currentcat[0]->get_id(), 0, 'statistics');
  28. //Bad, Regular, Good - User definitions
  29. $displays = $displayscore->get_custom_score_display_settings();
  30. if (!$displayscore->is_custom() || empty($displays)) {
  31. if (api_is_platform_admin() || api_is_course_admin()) {
  32. Display :: display_error_message(get_lang('PleaseEnableScoringSystem'),false);
  33. }
  34. } else {
  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_CUSTOM, SCORE_ONLY_CUSTOM, true);
  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= '<table class="data_table" cellspacing="0" cellpadding="3">';
  59. $stattable .= '<tr><th>' . get_lang('ScoringSystem') . '</th>';
  60. $stattable .= '<th>' . get_lang('Percentage') . '</th>';
  61. $stattable .= '<th>' . get_lang('CountUsers') . '</th>';
  62. //$stattable .= '<th>' . get_lang('Statistics') . '</th></tr>';
  63. $counter=0;
  64. foreach ($keys as $key) {
  65. $bar = ($highest_ratio > 0?($nr_items[$key] / $highest_ratio) * 100:0);
  66. $stattable .= '<tr class="row_' . ($counter % 2 == 0 ? 'odd' : 'even') . '">';
  67. $stattable .= '<td width="150">' . $key . '</td>';
  68. $stattable .= '<td width="550">'.Display::bar_progress($bar).'</td>';
  69. $stattable .= '<td align="right">' . $nr_items[$key] . '</td>';
  70. $counter++;
  71. }
  72. $stattable .= '</tr></table>';
  73. echo $stattable;
  74. }
  75. Display :: display_footer();