current_courses.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Report for current courses followed by the user.
  5. *
  6. * @package chamilo.reporting
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = SECTION_TRACKING;
  11. $filename = 'reporting';
  12. if (!api_is_allowed_to_create_course()) {
  13. api_not_allowed(true);
  14. }
  15. $user_id = api_get_user_id();
  16. $my_courses = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  17. $array = [];
  18. $i = 0;
  19. $session_id = 0;
  20. if (!empty($my_courses)) {
  21. foreach ($my_courses as $course) {
  22. $course_code = $course['code'];
  23. $course_id = $course['real_id'];
  24. $course_info = api_get_course_info($course_code);
  25. //Only show open courses
  26. if ($course_info['visibility'] == 0) {
  27. continue;
  28. }
  29. $teachers = CourseManager::get_teacher_list_from_course_code($course_code);
  30. $teacher_list = [];
  31. if (!empty($teachers)) {
  32. foreach ($teachers as $teacher) {
  33. $teacher_list[] = $teacher['firstname'].' '.$teacher['lastname'];
  34. }
  35. }
  36. $tmp_students = CourseManager :: get_student_list_from_course_code($course_code, false);
  37. //Cleaning students only REAL students
  38. $students = [];
  39. foreach ($tmp_students as $student) {
  40. $user_info = api_get_user_info($student['user_id']);
  41. if ($user_info['status'] != STUDENT) {
  42. continue;
  43. }
  44. $students[] = $student['user_id'];
  45. }
  46. $t_lp = Database::get_course_table(TABLE_LP_MAIN);
  47. $sql_lp = "SELECT lp.name, lp.id FROM $t_lp lp
  48. WHERE c_id = $course_id AND lp.session_id = 0";
  49. $rs_lp = Database::query($sql_lp);
  50. $t_lpi = Database::get_course_table(TABLE_LP_ITEM);
  51. $t_news = Database::get_course_table(TABLE_ANNOUNCEMENT);
  52. $total_tools_list = Tracking::get_tools_most_used_by_course(
  53. $course_id,
  54. $session_id
  55. );
  56. $total_tools = 0;
  57. foreach ($total_tools_list as $tool) {
  58. $total_tools += $tool['count_access_tool'];
  59. }
  60. if (Database :: num_rows($rs_lp) > 0) {
  61. while ($learnpath = Database :: fetch_array($rs_lp)) {
  62. $lp_id = $learnpath['id'];
  63. $lp_items =
  64. $array[$i]['lp'] = '<a href="'.api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?cidReq='.$course_code.'&amp;action=view&amp;lp_id='.$lp_id.'" target="_blank">'.$learnpath['name'].'</a>';
  65. $array[$i]['teachers'] = '';
  66. if (!empty($teacher_list)) {
  67. $array[$i]['teachers'] = implode(', ', $teacher_list);
  68. }
  69. $array[$i]['course_name'] = $course['title'];
  70. $count_students_accessing = 0;
  71. $count_students_complete_all_activities = 0;
  72. $count_students_complete_all_activities_at_50 = 0;
  73. $total_time_spent = 0;
  74. $total_average_progress = 0;
  75. if (!empty($students)) {
  76. foreach ($students as $student_id) {
  77. $avg_student_progress = Tracking::get_avg_student_progress($student_id, $course_code, [$lp_id], $session_id);
  78. $myavg_temp = Tracking::get_avg_student_score($student_id, $course_code, [$lp_id], $session_id);
  79. $avg_progress_in_course = Tracking::get_avg_student_progress($student_id, $course_code, [$lp_id], $session_id);
  80. if (intval($avg_progress_in_course) == 100) {
  81. $count_students_complete_all_activities++;
  82. }
  83. if (intval($avg_progress_in_course) > 0 && intval($avg_progress_in_course) <= 50) {
  84. $count_students_complete_all_activities_at_50++;
  85. }
  86. $total_average_progress += $avg_progress_in_course;
  87. $time_spent = Tracking::get_time_spent_on_the_course($student_id, $course_id, $session_id);
  88. $total_time_spent += $time_spent;
  89. if (!empty($time_spent)) {
  90. $count_students_accessing++;
  91. }
  92. }
  93. //$total_tools += $nb_assignments + $messages + $links + $chat_last_connection + $documents;
  94. }
  95. $student_count = count($students);
  96. $array[$i]['count_students'] = $student_count;
  97. $array[$i]['count_students_accessing'] = 0;
  98. $array[$i]['count_students_accessing_percentage'] = 0;
  99. $array[$i]['count_students_complete_all_activities_at_50'] = 0;
  100. $array[$i]['count_students_complete_all_activities'] = 0;
  101. $array[$i]['average_percentage_activities_completed_per_student'] = 0;
  102. $array[$i]['total_time_spent'] = 0;
  103. $array[$i]['average_time_spent_per_student'] = 0;
  104. $array[$i]['total_time_spent'] = 0;
  105. $array[$i]['average_time_spent_per_student'] = 0;
  106. //$array[$i]['tools_used'] = 0;
  107. $array[$i]['learnpath_docs'] = 0;
  108. $array[$i]['learnpath_exercises'] = 0;
  109. $array[$i]['learnpath_links'] = 0;
  110. $array[$i]['learnpath_forums'] = 0;
  111. $array[$i]['learnpath_assignments'] = 0;
  112. //registering the number of each category of
  113. //items in learning path
  114. $sql_lpi = "SELECT lpi.item_type FROM $t_lpi lpi
  115. WHERE c_id = $course_id AND lpi.lp_id = $lp_id
  116. ORDER BY item_type";
  117. $res_lpi = Database::query($sql_lpi);
  118. while ($row_lpi = Database::fetch_array($res_lpi)) {
  119. switch ($row_lpi['item_type']) {
  120. case 'document':
  121. $array[$i]['learnpath_docs']++;
  122. break;
  123. case 'quiz':
  124. $array[$i]['learnpath_exercises']++;
  125. break;
  126. case 'link':
  127. $array[$i]['learnpath_links']++;
  128. break;
  129. case 'forum':
  130. case 'thread':
  131. $array[$i]['learnpath_forums']++;
  132. break;
  133. case 'student_publication':
  134. $array[$i]['learnpath_assignments']++;
  135. break;
  136. }
  137. }
  138. // Count announcements
  139. $array[$i]['total_announcements'] = 0;
  140. $sql_news = "SELECT count(id) FROM $t_news WHERE c_id = $course_id ";
  141. $res_news = Database::query($sql_news);
  142. while ($row_news = Database::fetch_array($res_news)) {
  143. $array[$i]['total_announcements'] = $row_news[0];
  144. }
  145. //@todo don't know what means this value
  146. $count_students_complete_all_activities_at_50 = 0;
  147. if (!empty($student_count)) {
  148. $array[$i]['count_students_accessing'] = $count_students_accessing;
  149. $array[$i]['count_students_accessing_percentage'] = round($count_students_accessing / $student_count * 100, 0);
  150. $array[$i]['count_students_complete_all_activities_at_50'] = $count_students_complete_all_activities;
  151. $array[$i]['count_students_complete_all_activities'] = round($count_students_complete_all_activities / $student_count * 100, 0);
  152. $array[$i]['average_percentage_activities_completed_per_student'] = round($count_students_complete_all_activities / $student_count * 100, 2);
  153. $array[$i]['total_time_spent'] = 0;
  154. $array[$i]['average_time_spent_per_student'] = 0;
  155. if (!empty($total_time_spent)) {
  156. $array[$i]['total_time_spent'] = api_time_to_hms($total_time_spent);
  157. $array[$i]['average_time_spent_per_student'] = api_time_to_hms($total_time_spent / $student_count);
  158. }
  159. //$array[$i]['tools_used'] = $total_tools;
  160. }
  161. $i++;
  162. }
  163. }
  164. }
  165. }
  166. $headers = [
  167. get_lang('Learning paths'),
  168. get_lang('Trainers'),
  169. get_lang('Courses'),
  170. get_lang('Number of learners'),
  171. get_lang('Number of learners accessing the course'),
  172. get_lang('Percentage of learners accessing the course'),
  173. get_lang('Number of learners who completed all activities (100% progress)'),
  174. get_lang('Percentage of learners who completed all activities (100% progress)'),
  175. get_lang('Average number of activities completed per learner'),
  176. get_lang('Total time spent in the course'),
  177. get_lang('Average time spent per learner in the course'),
  178. get_lang('Number of documents in learning path'),
  179. get_lang('Number of exercises in learning path'),
  180. get_lang('Number of links in learning path'),
  181. get_lang('Number of forums in learning path'),
  182. get_lang('Number of assignments in learning path'),
  183. get_lang('Number of announcements in course'),
  184. ];
  185. if (isset($_GET['export'])) {
  186. $list = [
  187. 0 => $headers,
  188. 1 => $array[0],
  189. ];
  190. Export::arrayToXls($list, $filename);
  191. exit;
  192. }
  193. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Reporting')];
  194. Display::display_header(get_lang('Current courses'));
  195. $table = new HTML_Table(['class' => 'data_table']);
  196. $row = 0;
  197. $column = 0;
  198. foreach ($headers as $header) {
  199. $table->setHeaderContents($row, $column, $header);
  200. $column++;
  201. }
  202. $row++;
  203. foreach ($array as $row_table) {
  204. $column = 0;
  205. foreach ($row_table as $cell) {
  206. $table->setCellContents($row, $column, $cell);
  207. //$table->updateCellAttributes($row, $column, 'align="center"');
  208. $column++;
  209. }
  210. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  211. $row++;
  212. }
  213. echo '<div class="actions">';
  214. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace">'.Display::return_icon('back.png', get_lang('Back'), [], 32).'</a>';
  215. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php?export=1">'.Display::return_icon('export_excel.png', get_lang('Current coursesReport'), [], 32).'</a> ';
  216. echo '</div>';
  217. echo '<div style="overflow:auto;">';
  218. echo $table->toHtml();
  219. echo '</div>';
  220. Display::display_footer();