resulttable.class.php 5.5 KB

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