block_teacher.class.php 6.8 KB

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