current_courses.php 10.0 KB

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