resulttable.class.php 5.7 KB

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