current_courses.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. /**
  8. * Code
  9. */
  10. $language_file = array ('registration', 'index', 'tracking', 'exercice','admin');
  11. $cidReset = true;
  12. //require_once '../inc/global.inc.php';
  13. $this_section = SECTION_TRACKING;
  14. require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
  15. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  16. $filename = 'reporting.xls';
  17. if (!api_is_allowed_to_create_course()) {
  18. api_not_allowed(true);
  19. }
  20. $user_id = api_get_user_id();
  21. $my_courses = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  22. $array = array();
  23. $i = 0;
  24. $session_id = 0;
  25. if (!empty($my_courses)) {
  26. foreach ($my_courses as $course) {
  27. $course_code = $course['course_code'];
  28. $courseId = $course['real_id'];
  29. $course_info = api_get_course_info($course_code);
  30. //Only show open courses
  31. if ($course_info['visibility'] == 0) {
  32. continue;
  33. }
  34. $teachers = CourseManager::get_teacher_list_from_course_code($courseId);
  35. $teacher_list = array();
  36. //$teacher_list = array($course_info['titular']);
  37. if (!empty($teachers)) {
  38. foreach($teachers as $teacher) {
  39. $teacher_list[]= $teacher['firstname'].' '.$teacher['lastname'];
  40. }
  41. }
  42. $tmp_students = CourseManager :: get_student_list_from_course_code($courseId, false);
  43. //Cleaning students only REAL students
  44. $students = array();
  45. foreach ($tmp_students as $student) {
  46. $user_info = api_get_user_info($student['user_id']);
  47. if ($user_info['status'] != STUDENT) {
  48. continue;
  49. }
  50. $students[] = $student['user_id'];
  51. }
  52. $t_lp = Database :: get_course_table(TABLE_LP_MAIN);
  53. $sql_lp = "SELECT lp.name, lp.id FROM $t_lp lp WHERE c_id = $courseId AND lp.session_id = 0";
  54. $rs_lp = Database::query($sql_lp);
  55. $t_lpi = Database :: get_course_table(TABLE_LP_ITEM);
  56. $t_news = Database :: get_course_table(TABLE_ANNOUNCEMENT);
  57. $total_tools_list = Tracking::get_tools_most_used_by_course($courseId, $session_id);
  58. $total_tools = 0;
  59. foreach($total_tools_list as $tool) {
  60. $total_tools += $tool['count_access_tool'];
  61. }
  62. if (Database :: num_rows($rs_lp) > 0) {
  63. while ($learnpath = Database :: fetch_array($rs_lp)) {
  64. $lp_id = $learnpath['id'];
  65. $lp_items =
  66. $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>';
  67. $array[$i]['teachers'] = '';
  68. if (!empty($teacher_list)) {
  69. $array[$i]['teachers'] = implode(', ', $teacher_list);
  70. }
  71. $array[$i]['course_name'] = $course['title'];
  72. $count_students_accessing = 0;
  73. $count_students_complete_all_activities = 0;
  74. $count_students_complete_all_activities_at_50 = 0;
  75. $total_time_spent = 0;
  76. $total_average_progress = 0;
  77. if (!empty($students)) {
  78. foreach ($students as $student_id) {
  79. $avg_student_progress = Tracking::get_avg_student_progress($student_id, $courseId, array($lp_id), $session_id);
  80. $myavg_temp = Tracking::get_avg_student_score($student_id, $courseId, array($lp_id), $session_id);
  81. $avg_progress_in_course = Tracking::get_avg_student_progress($student_id, $courseId, array($lp_id), $session_id);
  82. if (intval($avg_progress_in_course) == 100) {
  83. $count_students_complete_all_activities++;
  84. }
  85. if (intval($avg_progress_in_course) > 0 && intval($avg_progress_in_course) <= 50) {
  86. $count_students_complete_all_activities_at_50 ++;
  87. }
  88. $total_average_progress +=$avg_progress_in_course;
  89. $time_spent = Tracking::get_time_spent_on_the_course($student_id, $courseId, $session_id);
  90. $total_time_spent += $time_spent;
  91. if (!empty($time_spent)) {
  92. $count_students_accessing++;
  93. }
  94. }
  95. //$total_tools += $nb_assignments + $messages + $links + $chat_last_connection + $documents;
  96. }
  97. $student_count = count($students);
  98. $array[$i]['count_students'] = $student_count;
  99. $array[$i]['count_students_accessing'] = 0;
  100. $array[$i]['count_students_accessing_percentage'] = 0;
  101. $array[$i]['count_students_complete_all_activities_at_50'] = 0;
  102. $array[$i]['count_students_complete_all_activities'] = 0;
  103. $array[$i]['average_percentage_activities_completed_per_student'] = 0;
  104. $array[$i]['total_time_spent'] = 0;
  105. $array[$i]['average_time_spent_per_student'] = 0;
  106. $array[$i]['total_time_spent'] = 0;
  107. $array[$i]['average_time_spent_per_student'] = 0;
  108. //$array[$i]['tools_used'] = 0;
  109. $array[$i]['learnpath_docs'] = 0;
  110. $array[$i]['learnpath_exercises'] = 0;
  111. $array[$i]['learnpath_links'] = 0;
  112. $array[$i]['learnpath_forums'] = 0;
  113. $array[$i]['learnpath_assignments'] = 0;
  114. //registering the number of each category of
  115. //items in learning path
  116. $sql_lpi = "SELECT lpi.item_type FROM $t_lpi lpi WHERE c_id = $courseId AND lpi.lp_id = $lp_id 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 = $courseId ";
  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 = array(
  167. get_lang('LearningPath'),
  168. get_lang('Teachers'),
  169. get_lang('Courses'),
  170. get_lang('NumberOfStudents'),
  171. get_lang('NumberStudentsAccessingCourse'),
  172. get_lang('PercentageStudentsAccessingCourse'),
  173. get_lang('NumberStudentsCompleteAllActivities'),
  174. get_lang('PercentageStudentsCompleteAllActivities'),
  175. get_lang('AverageOfActivitiesCompletedPerStudent'),
  176. get_lang('TotalTimeSpentInTheCourse'),
  177. get_lang('AverageTimePerStudentInCourse'),
  178. get_lang('NumberOfDocumentsInLearnpath'),
  179. get_lang('NumberOfExercisesInLearnpath'),
  180. get_lang('NumberOfLinksInLearnpath'),
  181. get_lang('NumberOfForumsInLearnpath'),
  182. get_lang('NumberOfAssignmentsInLearnpath'),
  183. get_lang('NumberOfAnnouncementsInCourse'),
  184. );
  185. if (isset($_GET['export'])) {
  186. global $charset;
  187. $workbook = new Spreadsheet_Excel_Writer();
  188. $workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
  189. $workbook->send($filename);
  190. $workbook->setVersion(8); // BIFF8
  191. $worksheet =& $workbook->addWorksheet('Report');
  192. //$worksheet->setInputEncoding(api_get_system_encoding());
  193. $worksheet->setInputEncoding($charset);
  194. $line = 0;
  195. $column = 0; //skip the first column (row titles)
  196. foreach($headers as $header) {
  197. $worksheet->write($line,$column, $header);
  198. $column++;
  199. }
  200. $line++;
  201. foreach ($array as $row) {
  202. $column = 0;
  203. foreach ($row as $item) {
  204. $worksheet->write($line,$column,html_entity_decode(strip_tags($item)));
  205. $column++;
  206. }
  207. $line++;
  208. }
  209. $line++;
  210. $workbook->close();
  211. exit;
  212. }
  213. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('MySpace'));
  214. Display::display_header(get_lang('CurrentCourses'));
  215. if (!class_exists('HTML_Table')) {
  216. require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php';
  217. }
  218. $table = new HTML_Table(array('class' => 'data_table'));
  219. $row = 0;
  220. $column = 0;
  221. foreach ($headers as $header) {
  222. $table->setHeaderContents($row, $column, $header);
  223. $column++;
  224. }
  225. $row++;
  226. foreach ($array as $row_table) {
  227. $column = 0;
  228. foreach ($row_table as $cell) {
  229. $table->setCellContents($row, $column, $cell);
  230. //$table->updateCellAttributes($row, $column, 'align="center"');
  231. $column++;
  232. }
  233. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  234. $row++;
  235. }
  236. echo '<div class="actions">';
  237. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace">'.Display::return_icon('back.png', get_lang('Back'), array(), 32).'</a>';
  238. 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> ';
  239. echo '</div>';
  240. echo '<div style="overflow:auto;">';
  241. echo $table->toHtml();
  242. echo '</div>';
  243. Display::display_footer();