gradebooktable.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. require_once (dirname(__FILE__).'/../../../inc/global.inc.php');
  18. require_once (dirname(__FILE__).'/../be.inc.php');
  19. /**
  20. * Table to display categories, evaluations and links
  21. * @author Stijn Konings
  22. * @author Bert Steppé (refactored, optimised)
  23. */
  24. class GradebookTable extends SortableTable
  25. {
  26. private $currentcat;
  27. private $datagen;
  28. private $evals_links;
  29. /**
  30. * Constructor
  31. */
  32. function GradebookTable ($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null) {
  33. parent :: SortableTable ('gradebooklist', null, null, (api_is_allowed_to_create_course()?1:0));
  34. $this->evals_links = array_merge($evals, $links);
  35. $this->currentcat = $currentcat;
  36. $this->datagen = new GradebookDataGenerator($cats, $evals, $links);
  37. if (isset($addparams)) {
  38. $this->set_additional_parameters($addparams);
  39. }
  40. $column= 0;
  41. if (api_is_allowed_to_create_course()) {
  42. $this->set_header($column++, '', false);
  43. }
  44. $this->set_header($column++, get_lang('Type'));
  45. $this->set_header($column++, get_lang('Name'));
  46. $this->set_header($column++, get_lang('Description'));
  47. $this->set_header($column++, get_lang('Weight'));
  48. $this->set_header($column++, get_lang('Date'),true, 'width="100"');
  49. //admins get an edit column
  50. if (api_is_allowed_to_create_course()) {
  51. $this->set_header($column++, get_lang('Modify'), false, 'width="100"');
  52. //actions on multiple selected documents
  53. $this->set_form_actions(array (
  54. 'deleted' => get_lang('DeleteSelected'),
  55. 'setvisible' => get_lang('SetVisible'),
  56. 'setinvisible' => get_lang('SetInvisible')));
  57. } else {
  58. $evals_links = array_merge($evals, $links);
  59. if(count($evals_links)>0) {
  60. $this->set_header($column++, get_lang('Results'), false);
  61. }
  62. //$this->set_header($column++, get_lang('Certificates'), false);
  63. }
  64. }
  65. /**
  66. * Function used by SortableTable to get total number of items in the table
  67. */
  68. function get_total_number_of_items() {
  69. return $this->datagen->get_total_items_count();
  70. }
  71. /**
  72. * Function used by SortableTable to generate the data to display
  73. */
  74. function get_table_data($from = 1) {
  75. // determine sorting type
  76. $col_adjust = (api_is_allowed_to_create_course() ? 1 : 0);
  77. switch ($this->column) {
  78. // Type
  79. case (0 + $col_adjust) :
  80. $sorting = GradebookDataGenerator :: GDG_SORT_TYPE;
  81. break;
  82. case (1 + $col_adjust) :
  83. $sorting = GradebookDataGenerator :: GDG_SORT_NAME;
  84. break;
  85. case (2 + $col_adjust) :
  86. $sorting = GradebookDataGenerator :: GDG_SORT_DESCRIPTION;
  87. break;
  88. case (3 + $col_adjust) :
  89. $sorting = GradebookDataGenerator :: GDG_SORT_WEIGHT;
  90. break;
  91. case (4 + $col_adjust) :
  92. $sorting = GradebookDataGenerator :: GDG_SORT_DATE;
  93. break;
  94. }
  95. if ($this->direction == 'DESC') {
  96. $sorting |= GradebookDataGenerator :: GDG_SORT_DESC;
  97. } else {
  98. $sorting |= GradebookDataGenerator :: GDG_SORT_ASC;
  99. }
  100. $data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
  101. // generate the data to display
  102. $sortable_data = array();
  103. foreach ($data_array as $data) {
  104. $row = array ();
  105. $item = $data[0];
  106. //if the item is invisible, wrap it in a span with class invisible
  107. $invisibility_span_open = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '<span class="invisible">' : '';
  108. $invisibility_span_close = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '</span>' : '';
  109. if (api_is_allowed_to_create_course()) {
  110. $row[] = $this->build_id_column ($item);
  111. }
  112. $row[] = $this->build_type_column ($item);
  113. $row[] = $invisibility_span_open . $this->build_name_link ($item) . $invisibility_span_close;
  114. $row[] = $invisibility_span_open . $data[2] . $invisibility_span_close;
  115. $row[] = $invisibility_span_open . $data[3] . $invisibility_span_close;
  116. $row[] = $invisibility_span_open . str_replace(' ','&nbsp;',$data[4]) . $invisibility_span_close;
  117. //admins get an edit column
  118. if (api_is_allowed_to_create_course()) {
  119. $row[] = $this->build_edit_column ($item);
  120. } else {
  121. //students get the results and certificates columns
  122. if (count($this->evals_links)>0) {
  123. $row[] = $data[5];
  124. }
  125. //$row[] = $data[6];
  126. }
  127. $sortable_data[] = $row;
  128. }
  129. return $sortable_data;
  130. }
  131. // Other functions
  132. private function build_id_column ($item) {
  133. switch ($item->get_item_type()) {
  134. // category
  135. case 'C' :
  136. return 'CATE' . $item->get_id();
  137. // evaluation
  138. case 'E' :
  139. return 'EVAL' . $item->get_id();
  140. // link
  141. case 'L' :
  142. return 'LINK' . $item->get_id();
  143. }
  144. }
  145. private function build_type_column ($item) {
  146. return build_type_icon_tag($item->get_icon_name());
  147. }
  148. private function build_name_link ($item) {
  149. switch ($item->get_item_type()) {
  150. // category
  151. case 'C' :
  152. return '&nbsp;<a href="'.$_SESSION['gradebook_dest'].'?selectcat=' . $item->get_id() . '">'
  153. . $item->get_name()
  154. . '</a>'
  155. . ($item->is_course() ? ' &nbsp;[' . $item->get_course_code() . ']' : '');
  156. // evaluation
  157. case 'E' :
  158. // course/platform admin can go to the view_results page
  159. if (api_is_allowed_to_create_course()) {
  160. return '&nbsp;'
  161. . '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">'
  162. . $item->get_name()
  163. . '</a>';
  164. } elseif (ScoreDisplay :: instance()->is_custom()) {
  165. // students can go to the statistics page (if custom display enabled)
  166. return '&nbsp;'
  167. . '<a href="gradebook_statistics.php?selecteval=' . $item->get_id() . '">'
  168. . $item->get_name()
  169. . '</a>';
  170. } else {
  171. return $item->get_name();
  172. }
  173. // link
  174. case 'L' :
  175. $url = $item->get_link();
  176. if (isset($url)) {
  177. $text = '&nbsp;<a href="' . $item->get_link() . '">'
  178. . $item->get_name()
  179. . '</a>';
  180. } else {
  181. $text = $item->get_name();
  182. }
  183. $text .= '&nbsp;[' . $item->get_type_name() . ']';
  184. $cc = $this->currentcat->get_course_code();
  185. if(empty($cc)) {
  186. $text .= '&nbsp;[<a href="'.api_get_path(REL_COURSE_PATH).$item->get_course_code().'/">'.$item->get_course_code().'</a>]';
  187. }
  188. return $text;
  189. }
  190. }
  191. private function build_edit_column ($item) {
  192. switch ($item->get_item_type()) {
  193. // category
  194. case 'C' :
  195. return build_edit_icons_cat($item, $this->currentcat->get_id());
  196. // evaluation
  197. case 'E' :
  198. return build_edit_icons_eval($item, $this->currentcat->get_id());
  199. // link
  200. case 'L' :
  201. return build_edit_icons_link($item, $this->currentcat->get_id());
  202. }
  203. }
  204. }