current_courses.php 11 KB

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