block_teacher.class.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /**
  12. * This class is used like controller for teacher block plugin,
  13. * the class name must be registered inside path.info file (e.g: controller = "BlockTeacher"), so dashboard controller will be instantiate it
  14. * @package chamilo.dashboard
  15. */
  16. class BlockTeacher extends Block {
  17. private $user_id;
  18. private $teachers;
  19. private $path;
  20. private $permission = array(DRH);
  21. /**
  22. * Controller
  23. */
  24. public function __construct ($user_id) {
  25. $this->user_id = $user_id;
  26. $this->path = 'block_teacher';
  27. if ($this->is_block_visible_for_user($user_id)) {
  28. /*if (api_is_platform_admin()) {
  29. $this->teachers = UserManager::get_user_list(array('status' => COURSEMANAGER));
  30. } else {*/
  31. $this->teachers = UserManager::get_users_followed_by_drh($user_id, COURSEMANAGER);
  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 teachers 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 = 1;
  57. $data = array();
  58. /*if (api_is_platform_admin()) {
  59. $teacher_content_html = $this->get_teachers_content_html_for_platform_admin();
  60. } else if (api_is_drh()) {*/
  61. $teacher_content_html = $this->get_teachers_content_html_for_drh();
  62. //}
  63. $html = '<li class="widget color-blue" id="intro">
  64. <div class="widget-head">
  65. <h3>'.get_lang('TeachersInformationsList').'</h3>
  66. <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>
  67. </div>
  68. <div class="widget-content">
  69. '.$teacher_content_html.'
  70. </div>
  71. </li>';
  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_teachers_content_html_for_platform_admin() {
  81. $content = '<div style="margin:10px;">';
  82. $content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>';
  83. if (count($this->teachers) > 0) {
  84. $teachers_table = '<table class="data_table">';
  85. $teachers_table .= '<tr>
  86. <th>'.get_lang('User').'</th>
  87. <th>'.get_lang('TimeSpentOnThePlatform').'</th>
  88. <th>'.get_lang('LastConnexion').'</th>
  89. </tr>';
  90. $i = 1;
  91. foreach ($this->teachers as $teacher) {
  92. $teacher_id = $teacher['user_id'];
  93. $firstname = $teacher['firstname'];
  94. $lastname = $teacher['lastname'];
  95. $username = $teacher['username'];
  96. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id));
  97. $last_connection = Tracking :: get_last_connection_date($teacher_id);
  98. if ($i%2 == 0) {
  99. $class_tr = 'row_odd';
  100. } else {
  101. $class_tr = 'row_even';
  102. }
  103. $teachers_table .= '<tr class="'.$class_tr.'">
  104. <td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>
  105. <td align="right">'.$time_on_platform.'</td>
  106. <td align="right">'.$last_connection.'</td>
  107. </tr>';
  108. $i++;
  109. }
  110. $teachers_table .= '</table>';
  111. } else {
  112. $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
  113. }
  114. $content .= $teachers_table;
  115. if (count($this->teachers) > 0) {
  116. $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>';
  117. }
  118. $content .= '</div>';
  119. return $content;
  120. }
  121. public function get_teachers_content_html_for_drh() {
  122. $content = '<div style="margin:10px;">';
  123. $content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>';
  124. if (count($this->teachers) > 0) {
  125. $a_last_week = Text::get_last_week();
  126. $last_week = api_convert_and_format_date($a_last_week[0], DATE_FORMAT_SHORT).' '.get_lang('Until').'<br />'.api_convert_and_format_date($a_last_week[6], DATE_FORMAT_SHORT);
  127. $teachers_table = '<table class="data_table">';
  128. $teachers_table .= '<tr>
  129. <th>'.get_lang('User').'</th>
  130. <th>'.get_lang('TimeSpentLastWeek').'<br />'.$last_week.'</th>
  131. </tr>';
  132. $i = 1;
  133. foreach ($this->teachers as $teacher) {
  134. $teacher_id = $teacher['user_id'];
  135. $firstname = $teacher['firstname'];
  136. $lastname = $teacher['lastname'];
  137. $username = $teacher['username'];
  138. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id, 'custom', api_get_utc_datetime($a_last_week[0]), api_get_utc_datetime($a_last_week[6])));
  139. if ($i%2 == 0) {
  140. $class_tr = 'row_odd';
  141. } else {
  142. $class_tr = 'row_even';
  143. }
  144. $teachers_table .= '<tr class="'.$class_tr.'">
  145. <td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>
  146. <td align="right">'.$time_on_platform.'</td>
  147. </tr>';
  148. $i++;
  149. }
  150. $teachers_table .= '</table>';
  151. } else {
  152. $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
  153. }
  154. $content .= $teachers_table;
  155. if (count($this->teachers) > 0) {
  156. $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>';
  157. }
  158. $content .= '</div>';
  159. return $content;
  160. }
  161. /**
  162. * Get number of teachers
  163. * @return int
  164. */
  165. function get_number_of_teachers() {
  166. return count($this->teachers);
  167. }
  168. }