block_course.class.php 6.3 KB

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