resulttable.class.php 6.5 KB

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