usertable.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. /**
  8. * Init
  9. */
  10. require_once dirname(__FILE__).'/../../../inc/global.inc.php';
  11. require_once dirname(__FILE__).'/../be.inc.php';
  12. /**
  13. * Table to display flat view of a student's evaluations and links
  14. * @author Stijn Konings
  15. * @author Bert Steppé (refactored, optimised, use of caching, datagenerator class)
  16. * @package chamilo.gradebook
  17. */
  18. class UserTable extends SortableTable
  19. {
  20. private $userid;
  21. private $datagen;
  22. /**
  23. * Constructor
  24. */
  25. function UserTable ($userid, $evals = array(), $links = array(), $addparams = null) {
  26. parent :: __construct ('userlist', null, null, 0);
  27. $this->userid = $userid;
  28. $this->datagen = new UserDataGenerator($userid, $evals, $links);
  29. if (isset($addparams)) {
  30. $this->set_additional_parameters($addparams);
  31. }
  32. $column = 0;
  33. $this->set_header($column++, get_lang('Type'));
  34. $this->set_header($column++, get_lang('Evaluation'));
  35. $this->set_header($column++, get_lang('Course'));
  36. $this->set_header($column++, get_lang('Category'));
  37. $this->set_header($column++, get_lang('EvaluationAverage'));
  38. $this->set_header($column++, get_lang('Result'));
  39. $scoredisplay = ScoreDisplay :: instance();
  40. if ($scoredisplay->is_custom()) {
  41. $this->set_header($column++, get_lang('Display'));
  42. }
  43. }
  44. /**
  45. * Function used by SortableTable to get total number of items in the table
  46. */
  47. function get_total_number_of_items () {
  48. return $this->datagen->get_total_items_count();
  49. }
  50. /**
  51. * Function used by SortableTable to generate the data to display
  52. */
  53. function get_table_data ($from = 1) {
  54. $scoredisplay = ScoreDisplay :: instance();
  55. // determine sorting type
  56. switch ($this->column) {
  57. // Type
  58. case 0:
  59. $sorting = UserDataGenerator :: UDG_SORT_TYPE;
  60. break;
  61. case 1:
  62. $sorting = UserDataGenerator :: UDG_SORT_NAME;
  63. break;
  64. case 2:
  65. $sorting = UserDataGenerator :: UDG_SORT_COURSE;
  66. break;
  67. case 3:
  68. $sorting = UserDataGenerator :: UDG_SORT_CATEGORY;
  69. break;
  70. case 4:
  71. $sorting = UserDataGenerator :: UDG_SORT_AVERAGE;
  72. break;
  73. case 5:
  74. $sorting = UserDataGenerator :: UDG_SORT_SCORE;
  75. break;
  76. case 6:
  77. $sorting = UserDataGenerator :: UDG_SORT_MASK;
  78. break;
  79. }
  80. if ($this->direction == 'DESC') {
  81. $sorting |= UserDataGenerator :: UDG_SORT_DESC;
  82. } else {
  83. $sorting |= UserDataGenerator :: UDG_SORT_ASC;
  84. }
  85. $data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
  86. // generate the data to display
  87. $sortable_data = array();
  88. foreach ($data_array as $data) {
  89. if ($data[2]!="") {//filter by course removed
  90. $row = array ();
  91. $row[] = $this->build_type_column ($data[0]);
  92. $row[] = $this->build_name_link ($data[0]);
  93. $row[] = $data[2];
  94. $row[] = $data[3];
  95. $row[] = $data[4];
  96. $row[] = $data[5];
  97. if ($scoredisplay->is_custom())
  98. $row[] = $data[6];
  99. $sortable_data[] = $row;
  100. }
  101. }
  102. return $sortable_data;
  103. }
  104. // Other functions
  105. private function build_type_column ($item) {
  106. return build_type_icon_tag($item->get_icon_name());
  107. }
  108. private function build_name_link ($item) {
  109. switch ($item->get_item_type()) {
  110. // evaluation
  111. case 'E' :
  112. return '&nbsp;'
  113. . '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">'
  114. . $item->get_name()
  115. . '</a>';
  116. // link
  117. case 'L' :
  118. return '&nbsp;<a href="' . $item->get_link() . '">'
  119. . $item->get_name()
  120. . '</a>'
  121. . '&nbsp;[' . $item->get_type_name() . ']';
  122. }
  123. }
  124. }