gradebook_statistics.php 3.3 KB

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