resulttable.class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ResultTable
  5. * Table to display results for an evaluation
  6. * @author Stijn Konings
  7. * @author Bert Steppé
  8. * @package chamilo.gradebook
  9. */
  10. class ResultTable extends SortableTable
  11. {
  12. private $datagen;
  13. private $evaluation;
  14. private $allresults;
  15. private $iscourse;
  16. /**
  17. * Constructor
  18. */
  19. public function __construct($evaluation, $results = array(), $iscourse, $addparams = null, $forprint = false)
  20. {
  21. parent:: __construct(
  22. 'resultlist',
  23. null,
  24. null,
  25. (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1
  26. );
  27. $this->datagen = new ResultsDataGenerator($evaluation, $results, true);
  28. $this->evaluation = $evaluation;
  29. $this->iscourse = $iscourse;
  30. $this->forprint = $forprint;
  31. if (isset($addparams)) {
  32. $this->set_additional_parameters($addparams);
  33. }
  34. $scoredisplay = ScoreDisplay::instance();
  35. $column = 0;
  36. if ($this->iscourse == '1') {
  37. $this->set_header($column++, '', false);
  38. $this->set_form_actions(array(
  39. 'delete' => get_lang('Delete')
  40. ));
  41. }
  42. if (api_is_western_name_order()) {
  43. $this->set_header($column++, get_lang('FirstName'));
  44. $this->set_header($column++, get_lang('LastName'));
  45. } else {
  46. $this->set_header($column++, get_lang('LastName'));
  47. $this->set_header($column++, get_lang('FirstName'));
  48. }
  49. $this->set_header($column++, get_lang('Score'));
  50. if ($scoredisplay->is_custom()) {
  51. $this->set_header($column++, get_lang('Display'));
  52. }
  53. if (!$this->forprint) {
  54. $this->set_header($column++, get_lang('Modify'), false);
  55. }
  56. }
  57. /**
  58. * Function used by SortableTable to get total number of items in the table
  59. */
  60. public function get_total_number_of_items()
  61. {
  62. return $this->datagen->get_total_results_count();
  63. }
  64. /**
  65. * Function used by SortableTable to generate the data to display
  66. */
  67. public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) {
  68. $is_western_name_order = api_is_western_name_order();
  69. $scoredisplay = ScoreDisplay::instance();
  70. // determine sorting type
  71. $col_adjust = $this->iscourse == '1' ? 1 : 0;
  72. switch ($this->column) {
  73. // first name or last name
  74. case (0 + $col_adjust):
  75. if ($is_western_name_order) {
  76. $sorting = ResultsDataGenerator::RDG_SORT_FIRSTNAME;
  77. } else {
  78. $sorting = ResultsDataGenerator::RDG_SORT_LASTNAME;
  79. }
  80. break;
  81. // first name or last name
  82. case (1 + $col_adjust):
  83. if ($is_western_name_order) {
  84. $sorting = ResultsDataGenerator::RDG_SORT_LASTNAME;
  85. } else {
  86. $sorting = ResultsDataGenerator::RDG_SORT_FIRSTNAME;
  87. }
  88. break;
  89. //Score
  90. case (2 + $col_adjust):
  91. $sorting = ResultsDataGenerator::RDG_SORT_SCORE;
  92. break;
  93. case (3 + $col_adjust):
  94. $sorting = ResultsDataGenerator::RDG_SORT_MASK;
  95. break;
  96. }
  97. if ($this->direction == 'DESC') {
  98. $sorting |= ResultsDataGenerator::RDG_SORT_DESC;
  99. } else {
  100. $sorting |= ResultsDataGenerator::RDG_SORT_ASC;
  101. }
  102. $data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
  103. // generate the data to display
  104. $sortable_data = array();
  105. foreach ($data_array as $item) {
  106. $row = array();
  107. if ($this->iscourse == '1') {
  108. $row[] = $item['result_id'];
  109. }
  110. if ($is_western_name_order) {
  111. $row[] = $item['firstname'];
  112. $row[] = $item['lastname'];
  113. } else {
  114. $row[] = $item['lastname'];
  115. $row[] = $item['firstname'];
  116. }
  117. $row[] = Display::bar_progress($item['percentage_score'], false, $item['score']);
  118. //$row[] = Display::bar_progress($item['percentage_score'], true);
  119. if ($scoredisplay->is_custom()) {
  120. $row[] = $item['display'];
  121. }
  122. if (!$this->forprint) {
  123. $row[] = $this->build_edit_column($item);
  124. }
  125. $sortable_data[] = $row;
  126. }
  127. return $sortable_data;
  128. }
  129. private function build_edit_column($item)
  130. {
  131. $locked_status = $this->evaluation->get_locked();
  132. if (api_is_allowed_to_edit(null, true) && $locked_status == 0) {
  133. //api_is_course_admin()
  134. $edit_column = '<a href="'.api_get_self().'?editres='.$item['result_id'].'&selecteval='.$this->evaluation->get_id().'&'.api_get_cidreq().'">'.
  135. Display::return_icon('edit.png', get_lang('Modify'), '', '22').'</a>';
  136. $edit_column .= ' <a href="'.api_get_self().'?delete_mark='.$item['result_id'].'&selecteval='.$this->evaluation->get_id().'&'.api_get_cidreq().'">'.
  137. Display::return_icon('delete.png', get_lang('Delete'), '', '22').'</a>';
  138. }
  139. if ($this->evaluation->get_course_code() == null) {
  140. $edit_column .= '&nbsp;<a href="'.api_get_self().'?resultdelete='.$item['result_id'].'&selecteval='.$this->evaluation->get_id().'" onclick="return confirmationuser();">';
  141. $edit_column .= Display::return_icon('delete.png', get_lang('Delete'));
  142. $edit_column .= '</a>';
  143. $edit_column .= '&nbsp;<a href="user_stats.php?userid='.$item['id'].'&selecteval='.$this->evaluation->get_id().'&'.api_get_cidreq().'">';
  144. $edit_column .= Display::return_icon('statistics.gif', get_lang('Statistics'));
  145. $edit_column .= '</a>';
  146. }
  147. // Evaluation's origin is a link
  148. if ($this->evaluation->get_category_id() < 0) {
  149. $link = LinkFactory::get_evaluation_link($this->evaluation->get_id());
  150. $doc_url = $link->get_view_url($item['id']);
  151. if ($doc_url != null) {
  152. $edit_column .= '&nbsp;<a href="'.$doc_url.'" target="_blank">';
  153. $edit_column .= Display::return_icon('link.gif', get_lang('OpenDocument')).'</a>';
  154. }
  155. }
  156. return $edit_column;
  157. }
  158. }