usertable.class.php 4.3 KB

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