block_course.class.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * This file is part of course block plugin for dashboard,
  4. * it should be required inside dashboard controller for showing it into dashboard interface from plattform
  5. * @package chamilo.dashboard
  6. * @author Christian Fasanando
  7. */
  8. /**
  9. * required files for getting data
  10. */
  11. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  13. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'thematic.lib.php';
  15. /**
  16. * This class is used like controller for this course block plugin,
  17. * the class name must be registered inside path.info file (e.g: controller = "BlockCourse"), so dashboard controller will be instantiate it
  18. * @package chamilo.dashboard
  19. */
  20. class BlockCourse extends Block {
  21. private $user_id;
  22. private $courses;
  23. private $path;
  24. private $permission = array(DRH);
  25. /**
  26. * Constructor
  27. */
  28. public function __construct ($user_id) {
  29. $this->user_id = $user_id;
  30. $this->path = 'block_course';
  31. if ($this->is_block_visible_for_user($user_id)) {
  32. /*if (api_is_platform_admin()) {
  33. $this->courses = CourseManager::get_real_course_list();
  34. } else {*/
  35. $this->courses = CourseManager::get_courses_followed_by_drh($user_id);
  36. //}
  37. }
  38. }
  39. /**
  40. * This method check if a user is allowed to see the block inside dashboard interface
  41. * @param int User id
  42. * @return bool Is block visible for user
  43. */
  44. public function is_block_visible_for_user($user_id) {
  45. $user_info = api_get_user_info($user_id);
  46. $user_status = $user_info['status'];
  47. $is_block_visible_for_user = false;
  48. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  49. $is_block_visible_for_user = true;
  50. }
  51. return $is_block_visible_for_user;
  52. }
  53. /**
  54. * This method return content html containing information about courses and its position for showing it inside dashboard interface
  55. * it's important to use the name 'get_block' for beeing used from dashboard controller
  56. * @return array column and content html
  57. */
  58. public function get_block() {
  59. global $charset;
  60. $column = 2;
  61. $data = array();
  62. $content = '';
  63. $data_table = '';
  64. $content = $this->get_content_html();
  65. $html = '
  66. <li class="widget color-green" id="intro">
  67. <div class="widget-head">
  68. <h3>'.get_lang('CoursesInformation').'</h3>
  69. <div class="widget-actions"><a onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">'.Display::return_icon('close.gif',get_lang('Close')).'</a></div>
  70. </div>
  71. <div class="widget-content">
  72. '.$content.'
  73. </div>
  74. </li>
  75. ';
  76. $data['column'] = $column;
  77. $data['content_html'] = $html;
  78. return $data;
  79. }
  80. /**
  81. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  82. * @return string content html
  83. */
  84. public function get_content_html() {
  85. $course_data = $this->get_course_information_data();
  86. $content = '<div style="margin:10px;">';
  87. $content .= '<h3><font color="#000">'.get_lang('YourCourseList').'</font></h3>';
  88. if (!empty($course_data)) {
  89. $data_table = '<table class="data_table" width:"95%">';
  90. $data_table .= '<tr>
  91. <th>'.get_lang('CourseTitle').'</th>
  92. <th width="20%">'.get_lang('NbStudents').'</th>
  93. <th width="20%">'.get_lang('AvgTimeSpentInTheCourse').'</th>
  94. <th width="20%">'.get_lang('ThematicAdvance').'</th>
  95. </tr>';
  96. $i = 1;
  97. foreach ($course_data as $course) {
  98. if ($i%2 == 0) {
  99. $class_tr = 'row_odd';
  100. } else {
  101. $class_tr = 'row_even';
  102. }
  103. $data_table .= '<tr class="'.$class_tr.'">';
  104. if (!isset($course[2])) {
  105. $course[2] = '0:00:00';
  106. }
  107. foreach ($course as $cell) {
  108. $data_table .= '<td align="right">'.$cell.'</td>';
  109. }
  110. $data_table .= '</tr>';
  111. $i++;
  112. }
  113. $data_table .= '</table>';
  114. } else {
  115. $data_table .= get_lang('ThereIsNoInformationAboutYourCourses');
  116. }
  117. $content .= $data_table;
  118. if (!empty($course_data)) {
  119. $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php">'.get_lang('SeeMore').'</a></div>';
  120. }
  121. $content .= '</div>';
  122. return $content;
  123. }
  124. /**
  125. * Get number of courses
  126. * @return int
  127. */
  128. function get_number_of_courses() {
  129. return count($this->courses);
  130. }
  131. /**
  132. * Get course information data
  133. * @return array
  134. */
  135. function get_course_information_data() {
  136. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  137. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  138. $a_course_students = array();
  139. $course_data = array();
  140. $courses = $this->courses;
  141. $thematic = new Thematic();
  142. foreach ($courses as $row_course) {
  143. $course_code = $row_course['code'];
  144. $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0;
  145. // students directly subscribed to the course
  146. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status=".STUDENT." AND course_rel_user.course_code='$course_code'";
  147. $rs = Database::query($sql);
  148. $users = array();
  149. while ($row = Database::fetch_array($rs)) {
  150. $users[] = $row['user_id'];
  151. }
  152. if (count($users) > 0) {
  153. $nb_students_in_course = count($users);
  154. $avg_time_spent_in_course = api_time_to_hms(Tracking::get_time_spent_on_the_course($users, $course_code)/$nb_students_in_course);
  155. } else {
  156. $avg_time_spent_in_course = null;
  157. }
  158. $tematic_advance_progress = 0;
  159. $tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, 0);
  160. if (!empty($tematic_advance)) {
  161. $tematic_advance_progress = '<a title="'.get_lang('GoToThematicAdvance').'" href="'.api_get_path(WEB_CODE_PATH).'course_progress/index.php?cidReq='.$course_code.'&action=thematic_details">'.$tematic_advance.'%</a>';
  162. } else {
  163. $tematic_advance_progress = '0%';
  164. }
  165. $table_row = array();
  166. $table_row[] = $row_course['title'];
  167. $table_row[] = $nb_students_in_course;
  168. $table_row[] = $avg_time_spent_in_course;
  169. $table_row[] = $tematic_advance_progress;
  170. $course_data[] = $table_row;
  171. }
  172. return $course_data;
  173. }
  174. }
  175. ?>