resulttable.class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. function get_total_number_of_items () {
  56. return $this->datagen->get_total_results_count();
  57. }
  58. /**
  59. * Function used by SortableTable to generate the data to display
  60. */
  61. function get_table_data ($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) {
  62. $is_western_name_order = api_is_western_name_order();
  63. $scoredisplay = ScoreDisplay :: instance();
  64. // determine sorting type
  65. $col_adjust = $this->iscourse == '1' ? 1 : 0;
  66. switch ($this->column) {
  67. // first name or last name
  68. case (0 + $col_adjust):
  69. if ($is_western_name_order) {
  70. $sorting = ResultsDataGenerator :: RDG_SORT_FIRSTNAME;
  71. } else {
  72. $sorting = ResultsDataGenerator :: RDG_SORT_LASTNAME;
  73. }
  74. break;
  75. // first name or last name
  76. case (1 + $col_adjust):
  77. if ($is_western_name_order) {
  78. $sorting = ResultsDataGenerator :: RDG_SORT_LASTNAME;
  79. } else {
  80. $sorting = ResultsDataGenerator :: RDG_SORT_FIRSTNAME;
  81. }
  82. break;
  83. //Score
  84. case (2 + $col_adjust):
  85. $sorting = ResultsDataGenerator :: RDG_SORT_SCORE;
  86. break;
  87. case (3 + $col_adjust):
  88. $sorting = ResultsDataGenerator :: RDG_SORT_MASK;
  89. break;
  90. }
  91. if ($this->direction == 'DESC') {
  92. $sorting |= ResultsDataGenerator :: RDG_SORT_DESC;
  93. } else {
  94. $sorting |= ResultsDataGenerator :: RDG_SORT_ASC;
  95. }
  96. $data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
  97. // generate the data to display
  98. $sortable_data = array();
  99. foreach ($data_array as $item) {
  100. $row = array ();
  101. if ($this->iscourse == '1') {
  102. $row[] = $item['result_id'];
  103. }
  104. if ($is_western_name_order) {
  105. $row[] = $item['firstname'];
  106. $row[] = $item['lastname'];
  107. } else {
  108. $row[] = $item['lastname'];
  109. $row[] = $item['firstname'];
  110. }
  111. $row[] = Display::bar_progress($item['percentage_score'], false, $item['score']);
  112. //$row[] = Display::bar_progress($item['percentage_score'], true);
  113. if ($scoredisplay->is_custom()) {
  114. $row[] = $item['display'];
  115. }
  116. if (!$this->forprint) {
  117. $row[] = $this->build_edit_column ($item);
  118. }
  119. $sortable_data[] = $row;
  120. }
  121. return $sortable_data;
  122. }
  123. private function build_edit_column ($item)
  124. {
  125. $status=CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
  126. $locked_status = $this->evaluation->get_locked();
  127. if (api_is_allowed_to_edit(null, true) && $locked_status == 0) {
  128. //api_is_course_admin()
  129. $edit_column = '<a href="' . api_get_self() . '?editres=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id().'&'.api_get_cidreq().'">'.
  130. Display::return_icon('edit.png', get_lang('Modify'),'','22').'</a>';
  131. $edit_column .= ' <a href="' . api_get_self() . '?delete_mark=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id().'&'.api_get_cidreq().'">'.
  132. Display::return_icon('delete.png', get_lang('Delete'),'','22').'</a>';
  133. }
  134. if ($this->evaluation->get_course_code() == null) {
  135. $edit_column.= '&nbsp;<a href="' . api_get_self() . '?resultdelete=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '" onclick="return confirmationuser();">
  136. <img src="../img/delete.gif" border="0" title="' . get_lang('Delete') . '" alt="" /></a>';
  137. $edit_column.= '&nbsp;<a href="user_stats.php?userid=' . $item['id'] . '&selecteval=' . $this->evaluation->get_id() . '&'.api_get_cidreq().'">
  138. <img src="../img/statistics.gif" width="17px" border="0" title="' . get_lang('Statistics') . '" alt="" /></a>';
  139. }
  140. // Evaluation's origin is a link
  141. if ($this->evaluation->get_category_id() < 0) {
  142. $link = LinkFactory :: get_evaluation_link ($this->evaluation->get_id());
  143. $doc_url = $link->get_view_url($item['id']);
  144. if ($doc_url != null) {
  145. $edit_column .= '&nbsp;<a href="'. $doc_url . '" target="_blank">'
  146. .'<img src="'. api_get_path(WEB_CODE_PATH) . 'img/link.gif" border="0" title="' . get_lang('OpenDocument') . '" alt="" />'
  147. .'</a>';
  148. }
  149. }
  150. return $edit_column;
  151. }
  152. }