usertable.class.php 4.3 KB

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