gradebooktable.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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_course_tutor() && api_is_allowed_to_create_course() && ($_SESSION['studentview']<>'studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false')) {
  42. $this->set_header($column++,'','','width="25px"');
  43. }
  44. $this->set_header($column++, get_lang('Type'),'','width="35px"');
  45. $this->set_header($column++, get_lang('Name'));
  46. $this->set_header($column++, get_lang('Description'));
  47. if (api_is_course_tutor() && api_is_allowed_to_create_course() && $_SESSION['studentview']<>'studentview' || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false')) {
  48. $this->set_header($column++, get_lang('Weight'),'','width="50px"');
  49. } else {
  50. if (empty($_GET['selectcat'])) {
  51. $this->set_header($column++, get_lang('Evaluation'));
  52. }
  53. else {
  54. $this->set_header($column++, get_lang('Weight'));
  55. }
  56. }
  57. $this->set_header($column++, get_lang('Date'),true, 'width="100px"');
  58. //admins get an edit column
  59. if (api_is_course_tutor() && api_is_allowed_to_create_course() && $_SESSION['studentview']<>'studentview' || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false')) {
  60. $this->set_header($column++, get_lang('Modify'), false, 'width="100"');
  61. //actions on multiple selected documents
  62. $this->set_form_actions(array (
  63. 'deleted' => get_lang('DeleteSelected'),
  64. 'setvisible' => get_lang('SetVisible'),
  65. 'setinvisible' => get_lang('SetInvisible')));
  66. } else {
  67. if (empty($_GET['selectcat'])) {
  68. $this->set_header($column++, get_lang('Certificates'),false);
  69. } else {
  70. $evals_links = array_merge($evals, $links);
  71. if(count($evals_links)>0) {
  72. $this->set_header($column++, get_lang('Results'), false);
  73. }
  74. }
  75. }
  76. }
  77. /**
  78. * Function used by SortableTable to get total number of items in the table
  79. */
  80. function get_total_number_of_items() {
  81. return $this->datagen->get_total_items_count();
  82. }
  83. /**
  84. * Function used by SortableTable to generate the data to display
  85. */
  86. function get_table_data($from = 1) {
  87. // determine sorting type
  88. $col_adjust = (api_is_allowed_to_create_course() ? 1 : 0);
  89. switch ($this->column) {
  90. // Type
  91. case (0 + $col_adjust) :
  92. $sorting = GradebookDataGenerator :: GDG_SORT_TYPE;
  93. break;
  94. case (1 + $col_adjust) :
  95. $sorting = GradebookDataGenerator :: GDG_SORT_NAME;
  96. break;
  97. case (2 + $col_adjust) :
  98. $sorting = GradebookDataGenerator :: GDG_SORT_DESCRIPTION;
  99. break;
  100. case (3 + $col_adjust) :
  101. $sorting = GradebookDataGenerator :: GDG_SORT_WEIGHT;
  102. break;
  103. case (4 + $col_adjust) :
  104. $sorting = GradebookDataGenerator :: GDG_SORT_DATE;
  105. break;
  106. }
  107. if ($this->direction == 'DESC') {
  108. $sorting |= GradebookDataGenerator :: GDG_SORT_DESC;
  109. } else {
  110. $sorting |= GradebookDataGenerator :: GDG_SORT_ASC;
  111. }
  112. $data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
  113. // generate the data to display
  114. $sortable_data = array();
  115. foreach ($data_array as $data) {
  116. $row = array ();
  117. $item = $data[0];
  118. $id = $item->get_id();
  119. if (empty($_GET['selectcat'])) {
  120. $certificate_min_score = $this->build_certificate_min_score($item);
  121. }
  122. //if the item is invisible, wrap it in a span with class invisible
  123. $invisibility_span_open = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '<span class="invisible">' : '';
  124. $invisibility_span_close = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '</span>' : '';
  125. if (api_is_course_tutor() && api_is_allowed_to_create_course() && ($_SESSION['studentview']<>'studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false')) {
  126. $row[] = $this->build_id_column ($item);
  127. }
  128. $row[] = $this->build_type_column ($item);
  129. $row[] = $invisibility_span_open . $this->build_name_link ($item) . $invisibility_span_close;
  130. $row[] = $invisibility_span_open . $data[2] . $invisibility_span_close;
  131. if (api_is_course_tutor() && api_is_allowed_to_create_course()) {
  132. $row[] = $invisibility_span_open . $data[3] . $invisibility_span_close;
  133. } else {
  134. if (empty($_GET['selectcat'])) {
  135. // generating the total score for a course
  136. $stud_id= api_get_user_id();
  137. $cats_course = Category :: load ($id, null, null, null, null, null, false);
  138. $alleval_course= $cats_course[0]->get_evaluations($stud_id,true);
  139. $alllink_course= $cats_course[0]->get_links($stud_id,true);
  140. $evals_links = array_merge($alleval_course, $alllink_course);
  141. $item_value=0;
  142. $item_total=0;
  143. for ($count=0; $count < count($evals_links); $count++) {
  144. $item = $evals_links[$count];
  145. $score = $item->calc_score($stud_id);
  146. $score_denom=($score[1]==0) ? 1 : $score[1];
  147. $item_value+=$score[0]/$score_denom*$item->get_weight();
  148. $item_total+=$item->get_weight();
  149. }
  150. $item_value = number_format($item_value, 2, '.', ' ');
  151. $cattotal = Category :: load($id);
  152. $scoretotal= $cattotal[0]->calc_score(api_get_user_id());
  153. $scoretotal_display = (isset($scoretotal)? $scoretotal[0].'/'.$scoretotal[1].'('.round(($scoretotal[0] / $scoretotal[1]) * 100) . ' %)': '-');
  154. $row[] = $item_value;
  155. } else {
  156. $row[] = $invisibility_span_open . $data[3] . $invisibility_span_close;
  157. }
  158. }
  159. $row[] = $invisibility_span_open . str_replace(' ','&nbsp;',$data[4]) . $invisibility_span_close;
  160. //admins get an edit column
  161. if (api_is_course_tutor() && api_is_allowed_to_create_course() && ($_SESSION['studentview']<>'studentview' || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false'))) {
  162. $cat=new Category();
  163. $show_message=$cat->show_message_resource_delete($item->get_course_code());
  164. if ($show_message===false) {
  165. $row[] = $this->build_edit_column ($item);
  166. }
  167. } else {
  168. //students get the results and certificates columns
  169. if (count($this->evals_links)>0) {
  170. $value_data=isset($data[5]) ? $data[5] : null;
  171. $row[] = $value_data;
  172. }
  173. if (empty($_GET['selectcat'])) {
  174. if (isset($certificate_min_score) && (int)$item_value >= (int)$certificate_min_score) {
  175. $certificates = '<a href="'.api_get_path(WEB_CODE_PATH) .'gradebook/index.php?export_certificate=yes&cat_id='.$id.'"><img src="'.api_get_path(WEB_CODE_PATH) . 'img/dokeos.gif" /></a>&nbsp;'.$scoretotal_display;
  176. } else {
  177. $certificates = '-';
  178. }
  179. $row[] = $certificates;
  180. }
  181. }
  182. $sortable_data[] = $row;
  183. }
  184. return $sortable_data;
  185. }
  186. // Other functions
  187. private function build_certificate_min_score ($item) {
  188. return $item->get_certificate_min_score();
  189. }
  190. private function build_id_column ($item) {
  191. switch ($item->get_item_type()) {
  192. // category
  193. case 'C' :
  194. return 'CATE' . $item->get_id();
  195. // evaluation
  196. case 'E' :
  197. return 'EVAL' . $item->get_id();
  198. // link
  199. case 'L' :
  200. return 'LINK' . $item->get_id();
  201. }
  202. }
  203. private function build_type_column ($item) {
  204. return build_type_icon_tag($item->get_icon_name());
  205. }
  206. private function build_name_link ($item) {
  207. switch ($item->get_item_type()) {
  208. // category
  209. case 'C' :
  210. $prms_uri='?selectcat=' . $item->get_id();
  211. if (isset($_GET['isStudentView'])) {
  212. if ( isset($is_student) || ( isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  213. $prms_uri=$prms_uri.'&amp;isStudentView='.$_GET['isStudentView'];
  214. }
  215. }
  216. $cat=new Category();
  217. $show_message=$cat->show_message_resource_delete($item->get_course_code());
  218. return '&nbsp;<a href="'.$_SESSION['gradebook_dest'].$prms_uri.'">'
  219. . $item->get_name()
  220. . '</a>'
  221. . ($item->is_course() ? ' &nbsp;[' . $item->get_course_code() . ']'.$show_message : '');
  222. // evaluation
  223. case 'E' :
  224. $cat=new Category();
  225. $dblib=new Database();
  226. $category_id=Security::remove_XSS($_GET['selectcat']);
  227. $course_id=$dblib->get_course_by_category($category_id);
  228. $show_message=$cat->show_message_resource_delete($course_id);
  229. // course/platform admin can go to the view_results page
  230. if (api_is_allowed_to_create_course() && $show_message===false) {
  231. return '&nbsp;'
  232. . '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">'
  233. . $item->get_name()
  234. . '</a>&nbsp;['.get_lang('Evaluation').']';
  235. } elseif (ScoreDisplay :: instance()->is_custom() && $show_message===false) {
  236. // students can go to the statistics page (if custom display enabled)
  237. return '&nbsp;'
  238. . '<a href="gradebook_statistics.php?selecteval=' . $item->get_id() . '">'
  239. . $item->get_name()
  240. . '</a>';
  241. } elseif ($show_message===false && !api_is_allowed_to_create_course() && !(ScoreDisplay :: instance()->is_custom())) {
  242. return '&nbsp;'
  243. . '<a href="gradebook_statistics.php?selecteval=' . $item->get_id() . '">'
  244. . $item->get_name()
  245. . '</a>';
  246. } else {
  247. return '['.get_lang('Evaluation').']&nbsp;&nbsp;'.$item->get_name().$show_message;
  248. }
  249. // link
  250. case 'L' :
  251. $cat=new Category();
  252. $dblib=new Database();
  253. $category_id=Security::remove_XSS($_GET['selectcat']);
  254. $course_id=$dblib->get_course_by_category($category_id);
  255. $show_message=$cat->show_message_resource_delete($course_id);
  256. $url = $item->get_link();
  257. if (isset($url) && $show_message===false) {
  258. $text = '&nbsp;<a href="' . $item->get_link() . '">'
  259. . $item->get_name()
  260. . '</a>';
  261. } else {
  262. $text = $item->get_name();
  263. }
  264. $text .= '&nbsp;[' . $item->get_type_name() . ']'.$show_message;
  265. $cc = $this->currentcat->get_course_code();
  266. if (empty($cc)) {
  267. $text .= '&nbsp;[<a href="'.api_get_path(REL_COURSE_PATH).$item->get_course_code().'/">'.$item->get_course_code().'</a>]';
  268. }
  269. return $text;
  270. }
  271. }
  272. private function build_edit_column ($item) {
  273. switch ($item->get_item_type()) {
  274. // category
  275. case 'C' :
  276. return build_edit_icons_cat($item, $this->currentcat->get_id());
  277. // evaluation
  278. case 'E' :
  279. return build_edit_icons_eval($item, $this->currentcat->get_id());
  280. // link
  281. case 'L' :
  282. return build_edit_icons_link($item, $this->currentcat->get_id());
  283. }
  284. }
  285. }