block_teacher.class.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * This file is part of teacher 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).'usermanager.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  13. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  14. /**
  15. * This class is used like controller for teacher block plugin,
  16. * the class name must be registered inside path.info file (e.g: controller = "BlockTeacher"), so dashboard controller will be instantiate it
  17. * @package chamilo.dashboard
  18. */
  19. class BlockTeacher extends Block {
  20. private $user_id;
  21. private $teachers;
  22. private $path;
  23. private $permission = array(DRH);
  24. /**
  25. * Controller
  26. */
  27. public function __construct ($user_id) {
  28. $this->user_id = $user_id;
  29. $this->path = 'block_teacher';
  30. if ($this->is_block_visible_for_user($user_id)) {
  31. /*if (api_is_platform_admin()) {
  32. $this->teachers = UserManager::get_user_list(array('status' => COURSEMANAGER));
  33. } else {*/
  34. $this->teachers = UserManager::get_users_followed_by_drh($user_id, COURSEMANAGER);
  35. //}
  36. }
  37. }
  38. /**
  39. * This method check if a user is allowed to see the block inside dashboard interface
  40. * @param int User id
  41. * @return bool Is block visible for user
  42. */
  43. public function is_block_visible_for_user($user_id) {
  44. $user_info = api_get_user_info($user_id);
  45. $user_status = $user_info['status'];
  46. $is_block_visible_for_user = false;
  47. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  48. $is_block_visible_for_user = true;
  49. }
  50. return $is_block_visible_for_user;
  51. }
  52. /**
  53. * This method return content html containing information about teachers and its position for showing it inside dashboard interface
  54. * it's important to use the name 'get_block' for beeing used from dashboard controller
  55. * @return array column and content html
  56. */
  57. public function get_block() {
  58. global $charset;
  59. $column = 1;
  60. $data = array();
  61. /*if (api_is_platform_admin()) {
  62. $teacher_content_html = $this->get_teachers_content_html_for_platform_admin();
  63. } else if (api_is_drh()) {*/
  64. $teacher_content_html = $this->get_teachers_content_html_for_drh();
  65. //}
  66. $html = '
  67. <li class="widget color-blue" id="intro">
  68. <div class="widget-head">
  69. <h3>'.get_lang('TeachersInformationsList').'</h3>
  70. <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>
  71. </div>
  72. <div class="widget-content">
  73. '.$teacher_content_html.'
  74. </div>
  75. </li>
  76. ';
  77. $data['column'] = $column;
  78. $data['content_html'] = $html;
  79. return $data;
  80. }
  81. /**
  82. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  83. * @return string content html
  84. */
  85. public function get_teachers_content_html_for_platform_admin() {
  86. $teachers = $this->teachers;
  87. $content = '';
  88. $content = '<div style="margin:10px;">';
  89. $content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>';
  90. if (count($teachers) > 0) {
  91. $teachers_table = '<table class="data_table" width:"95%">';
  92. $teachers_table .= '
  93. <tr>
  94. <th>'.get_lang('User').'</th>
  95. <th>'.get_lang('TimeSpentOnThePlatform').'</th>
  96. <th>'.get_lang('LastConnexion').'</th>
  97. </tr>
  98. ';
  99. $i = 1;
  100. foreach ($teachers as $teacher) {
  101. $teacher_id = $teacher['user_id'];
  102. $firstname = $teacher['firstname'];
  103. $lastname = $teacher['lastname'];
  104. $username = $teacher['username'];
  105. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id));
  106. $last_connection = Tracking :: get_last_connection_date($teacher_id);
  107. if ($i%2 == 0) $class_tr = 'row_odd';
  108. else $class_tr = 'row_even';
  109. $teachers_table .= '
  110. <tr class="'.$class_tr.'">
  111. <td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>
  112. <td align="right">'.$time_on_platform.'</td>
  113. <td align="right">'.$last_connection.'</td>
  114. </tr>
  115. ';
  116. $i++;
  117. }
  118. $teachers_table .= '</table>';
  119. } else {
  120. $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
  121. }
  122. $content .= $teachers_table;
  123. if (count($teachers) > 0) {
  124. $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin">'.get_lang('SeeMore').'</a></div>';
  125. }
  126. $content .= '</div>';
  127. return $content;
  128. }
  129. public function get_teachers_content_html_for_drh() {
  130. $teachers = $this->teachers;
  131. $content = '';
  132. $content = '<div style="margin:10px;">';
  133. $content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>';
  134. if (count($teachers) > 0) {
  135. $a_last_week = get_last_week();
  136. $last_week = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
  137. $teachers_table = '<table class="data_table" width:"95%">';
  138. $teachers_table .= '
  139. <tr>
  140. <th>'.get_lang('User').'</th>
  141. <th>'.get_lang('TimeSpentLastWeek').'<br />'.$last_week.'</th>
  142. </tr>
  143. ';
  144. $i = 1;
  145. foreach ($teachers as $teacher) {
  146. $teacher_id = $teacher['user_id'];
  147. $firstname = $teacher['firstname'];
  148. $lastname = $teacher['lastname'];
  149. $username = $teacher['username'];
  150. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id,true));
  151. if ($i%2 == 0) $class_tr = 'row_odd';
  152. else $class_tr = 'row_even';
  153. $teachers_table .= '<tr class="'.$class_tr.'">
  154. <td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>
  155. <td align="right">'.$time_on_platform.'</td>
  156. </tr>';
  157. $i++;
  158. }
  159. $teachers_table .= '</table>';
  160. } else {
  161. $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
  162. }
  163. $content .= $teachers_table;
  164. if (count($teachers) > 0) {
  165. $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/teachers.php">'.get_lang('SeeMore').'</a></div>';
  166. }
  167. $content .= '</div>';
  168. return $content;
  169. }
  170. /**
  171. * Get number of teachers
  172. * @return int
  173. */
  174. function get_number_of_teachers() {
  175. return count($this->teachers);
  176. }
  177. }
  178. ?>