current_courses.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 '../inc/global.inc.php';
  9. $this_section = SECTION_TRACKING;
  10. $filename = 'reporting.xls';
  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 WHERE c_id = $course_id AND lp.session_id = 0";
  47. $rs_lp = Database::query($sql_lp);
  48. $t_lpi = Database :: get_course_table(TABLE_LP_ITEM);
  49. $t_news = Database :: get_course_table(TABLE_ANNOUNCEMENT);
  50. $total_tools_list = Tracking::get_tools_most_used_by_course(
  51. $course_id,
  52. $session_id
  53. );
  54. $total_tools = 0;
  55. foreach($total_tools_list as $tool) {
  56. $total_tools += $tool['count_access_tool'];
  57. }
  58. if (Database :: num_rows($rs_lp) > 0) {
  59. while ($learnpath = Database :: fetch_array($rs_lp)) {
  60. $lp_id = $learnpath['id'];
  61. $lp_items =
  62. $array[$i]['lp'] = '<a href="'.api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?cidReq='.$course_code.'&amp;action=view&amp;lp_id='.$lp_id.'" target="_blank">'.$learnpath['name'].'</a>';
  63. $array[$i]['teachers'] = '';
  64. if (!empty($teacher_list)) {
  65. $array[$i]['teachers'] = implode(', ', $teacher_list);
  66. }
  67. $array[$i]['course_name'] = $course['title'];
  68. $count_students_accessing = 0;
  69. $count_students_complete_all_activities = 0;
  70. $count_students_complete_all_activities_at_50 = 0;
  71. $total_time_spent = 0;
  72. $total_average_progress = 0;
  73. if (!empty($students)) {
  74. foreach ($students as $student_id) {
  75. $avg_student_progress = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
  76. $myavg_temp = Tracking::get_avg_student_score($student_id, $course_code, array($lp_id), $session_id);
  77. $avg_progress_in_course = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
  78. if (intval($avg_progress_in_course) == 100) {
  79. $count_students_complete_all_activities++;
  80. }
  81. if (intval($avg_progress_in_course) > 0 && intval($avg_progress_in_course) <= 50) {
  82. $count_students_complete_all_activities_at_50 ++;
  83. }
  84. $total_average_progress +=$avg_progress_in_course;
  85. $time_spent = Tracking::get_time_spent_on_the_course($student_id, $course_id, $session_id);
  86. $total_time_spent += $time_spent;
  87. if (!empty($time_spent)) {
  88. $count_students_accessing++;
  89. }
  90. }
  91. //$total_tools += $nb_assignments + $messages + $links + $chat_last_connection + $documents;
  92. }
  93. $student_count = count($students);
  94. $array[$i]['count_students'] = $student_count;
  95. $array[$i]['count_students_accessing'] = 0;
  96. $array[$i]['count_students_accessing_percentage'] = 0;
  97. $array[$i]['count_students_complete_all_activities_at_50'] = 0;
  98. $array[$i]['count_students_complete_all_activities'] = 0;
  99. $array[$i]['average_percentage_activities_completed_per_student'] = 0;
  100. $array[$i]['total_time_spent'] = 0;
  101. $array[$i]['average_time_spent_per_student'] = 0;
  102. $array[$i]['total_time_spent'] = 0;
  103. $array[$i]['average_time_spent_per_student'] = 0;
  104. //$array[$i]['tools_used'] = 0;
  105. $array[$i]['learnpath_docs'] = 0;
  106. $array[$i]['learnpath_exercises'] = 0;
  107. $array[$i]['learnpath_links'] = 0;
  108. $array[$i]['learnpath_forums'] = 0;
  109. $array[$i]['learnpath_assignments'] = 0;
  110. //registering the number of each category of
  111. //items in learning path
  112. $sql_lpi = "SELECT lpi.item_type FROM $t_lpi lpi
  113. WHERE c_id = $course_id AND lpi.lp_id = $lp_id
  114. ORDER BY item_type";
  115. $res_lpi = Database::query($sql_lpi);
  116. while ($row_lpi = Database::fetch_array($res_lpi)) {
  117. switch($row_lpi['item_type']) {
  118. case 'document':
  119. $array[$i]['learnpath_docs']++;
  120. break;
  121. case 'quiz':
  122. $array[$i]['learnpath_exercises']++;
  123. break;
  124. case 'link':
  125. $array[$i]['learnpath_links']++;
  126. break;
  127. case 'forum':
  128. case 'thread':
  129. $array[$i]['learnpath_forums']++;
  130. break;
  131. case 'student_publication':
  132. $array[$i]['learnpath_assignments']++;
  133. break;
  134. }
  135. }
  136. // Count announcements
  137. $array[$i]['total_announcements'] = 0;
  138. $sql_news = "SELECT count(id) FROM $t_news WHERE c_id = $course_id ";
  139. $res_news = Database::query($sql_news);
  140. while ($row_news = Database::fetch_array($res_news)) {
  141. $array[$i]['total_announcements'] = $row_news[0];
  142. }
  143. //@todo don't know what means this value
  144. $count_students_complete_all_activities_at_50 = 0;
  145. if (!empty($student_count)) {
  146. $array[$i]['count_students_accessing'] = $count_students_accessing;
  147. $array[$i]['count_students_accessing_percentage'] = round($count_students_accessing / $student_count *100 , 0);
  148. $array[$i]['count_students_complete_all_activities_at_50'] = $count_students_complete_all_activities;
  149. $array[$i]['count_students_complete_all_activities'] = round($count_students_complete_all_activities / $student_count *100 , 0);;
  150. $array[$i]['average_percentage_activities_completed_per_student'] = round($count_students_complete_all_activities/$student_count*100,2);
  151. $array[$i]['total_time_spent'] = 0;
  152. $array[$i]['average_time_spent_per_student'] = 0;
  153. if (!empty($total_time_spent)) {
  154. $array[$i]['total_time_spent'] = api_time_to_hms($total_time_spent);
  155. $array[$i]['average_time_spent_per_student'] = api_time_to_hms($total_time_spent / $student_count);
  156. }
  157. //$array[$i]['tools_used'] = $total_tools;
  158. }
  159. $i++;
  160. }
  161. }
  162. }
  163. }
  164. $headers = array(
  165. get_lang('LearningPath'),
  166. get_lang('Teachers'),
  167. get_lang('Courses'),
  168. get_lang('NumberOfStudents'),
  169. get_lang('NumberStudentsAccessingCourse'),
  170. get_lang('PercentageStudentsAccessingCourse'),
  171. get_lang('NumberStudentsCompleteAllActivities'),
  172. get_lang('PercentageStudentsCompleteAllActivities'),
  173. get_lang('AverageOfActivitiesCompletedPerStudent'),
  174. get_lang('TotalTimeSpentInTheCourse'),
  175. get_lang('AverageTimePerStudentInCourse'),
  176. get_lang('NumberOfDocumentsInLearnpath'),
  177. get_lang('NumberOfExercisesInLearnpath'),
  178. get_lang('NumberOfLinksInLearnpath'),
  179. get_lang('NumberOfForumsInLearnpath'),
  180. get_lang('NumberOfAssignmentsInLearnpath'),
  181. get_lang('NumberOfAnnouncementsInCourse'),
  182. );
  183. if (isset($_GET['export'])) {
  184. global $charset;
  185. $spreadsheet = new PHPExcel();
  186. $spreadsheet->setActiveSheetIndex(0);
  187. $worksheet = $spreadsheet->getActiveSheet();
  188. $line = 0;
  189. $column = 0; //skip the first column (row titles)
  190. foreach ($headers as $header) {
  191. $worksheet->SetCellValueByColumnAndRow($line, $column, $header);
  192. $column++;
  193. }
  194. $line++;
  195. foreach ($array as $row) {
  196. $column = 0;
  197. foreach ($row as $item) {
  198. $worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($item)));
  199. $column++;
  200. }
  201. $line++;
  202. }
  203. $line++;
  204. $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
  205. $writer = new PHPExcel_Writer_Excel2007($spreadsheet);
  206. $writer->save($file);
  207. DocumentManager::file_send_for_download($file, true, $filename);
  208. exit;
  209. }
  210. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('MySpace'));
  211. Display::display_header(get_lang('CurrentCourses'));
  212. $table = new HTML_Table(array('class' => 'data_table'));
  213. $row = 0;
  214. $column = 0;
  215. foreach ($headers as $header) {
  216. $table->setHeaderContents($row, $column, $header);
  217. $column++;
  218. }
  219. $row++;
  220. foreach ($array as $row_table) {
  221. $column = 0;
  222. foreach ($row_table as $cell) {
  223. $table->setCellContents($row, $column, $cell);
  224. //$table->updateCellAttributes($row, $column, 'align="center"');
  225. $column++;
  226. }
  227. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  228. $row++;
  229. }
  230. echo '<div class="actions">';
  231. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace">'.Display::return_icon('back.png', get_lang('Back'), array(), 32).'</a>';
  232. 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> ';
  233. echo '</div>';
  234. echo '<div style="overflow:auto;">';
  235. echo $table->toHtml();
  236. echo '</div>';
  237. Display::display_footer();