block_teacher.class.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 $path;
  23. private $permission = [DRH];
  24. /**
  25. * Controller.
  26. */
  27. public function __construct($user_id)
  28. {
  29. $this->user_id = $user_id;
  30. $this->path = 'block_teacher';
  31. if ($this->is_block_visible_for_user($user_id)) {
  32. $this->teachers = UserManager::get_users_followed_by_drh($user_id, COURSEMANAGER);
  33. }
  34. }
  35. /**
  36. * This method check if a user is allowed to see the block inside dashboard interface.
  37. *
  38. * @param int User id
  39. *
  40. * @return bool Is block visible for user
  41. */
  42. public function is_block_visible_for_user($user_id)
  43. {
  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
  54. * teachers and its position for showing it inside dashboard interface
  55. * it's important to use the name 'get_block' for beeing used from
  56. * dashboard controller.
  57. *
  58. * @return array column and content html
  59. */
  60. public function get_block()
  61. {
  62. global $charset;
  63. $column = 1;
  64. $data = [];
  65. $teacher_content_html = $this->get_teachers_content_html_for_drh();
  66. $html = '
  67. <div class="panel panel-default" id="intro">
  68. <div class="panel-heading">
  69. '.get_lang('TeachersInformationsList').'
  70. <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
  71. <em class="fa fa-times"></em>
  72. </a></div>
  73. </div>
  74. <div class="panel-body">
  75. '.$teacher_content_html.'
  76. </div>
  77. </div>
  78. ';
  79. $data['column'] = $column;
  80. $data['content_html'] = $html;
  81. return $data;
  82. }
  83. /**
  84. * This method return a content html, it's used inside get_block method
  85. * for showing it inside dashboard interface.
  86. *
  87. * @return string content html
  88. */
  89. public function get_teachers_content_html_for_platform_admin()
  90. {
  91. $teachers = $this->teachers;
  92. $content = '<h4>'.get_lang('YourTeachers').'</h4>';
  93. $teachers_table = null;
  94. if (count($teachers) > 0) {
  95. $teachers_table .= '<table class="data_table" width:"95%">';
  96. $teachers_table .= '
  97. <tr>
  98. <th>'.get_lang('User').'</th>
  99. <th>'.get_lang('TimeSpentOnThePlatform').'</th>
  100. <th>'.get_lang('LastConnexion').'</th>
  101. </tr>
  102. ';
  103. $i = 1;
  104. foreach ($teachers as $teacher) {
  105. $teacher_id = $teacher['user_id'];
  106. $firstname = $teacher['firstname'];
  107. $lastname = $teacher['lastname'];
  108. $username = $teacher['username'];
  109. $time_on_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($teacher_id));
  110. $last_connection = Tracking::get_last_connection_date($teacher_id);
  111. if ($i % 2 == 0) {
  112. $class_tr = 'row_odd';
  113. } else {
  114. $class_tr = 'row_even';
  115. }
  116. $teachers_table .= '
  117. <tr class="'.$class_tr.'">
  118. <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
  119. <td align="right">'.$time_on_platform.'</td>
  120. <td align="right">'.$last_connection.'</td>
  121. </tr>
  122. ';
  123. $i++;
  124. }
  125. $teachers_table .= '</table>';
  126. } else {
  127. $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
  128. }
  129. $content .= $teachers_table;
  130. if (count($teachers) > 0) {
  131. $content .= '<div style="text-align:right;margin-top:10px;">
  132. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin">'.get_lang('SeeMore').'</a></div>';
  133. }
  134. return $content;
  135. }
  136. public function get_teachers_content_html_for_drh()
  137. {
  138. $teachers = $this->teachers;
  139. $content = '<h4>'.get_lang('YourTeachers').'</h4>';
  140. $teachers_table = null;
  141. if (count($teachers) > 0) {
  142. $a_last_week = get_last_week();
  143. $last_week = date('Y-m-d', $a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
  144. $teachers_table .= '<table class="data_table" width:"95%">';
  145. $teachers_table .= '
  146. <tr>
  147. <th>'.get_lang('User').'</th>
  148. <th>'.get_lang('TimeSpentLastWeek').'<br />'.$last_week.'</th>
  149. </tr>
  150. ';
  151. $i = 1;
  152. foreach ($teachers as $teacher) {
  153. $teacher_id = $teacher['user_id'];
  154. $firstname = $teacher['firstname'];
  155. $lastname = $teacher['lastname'];
  156. $username = $teacher['username'];
  157. $time_on_platform = api_time_to_hms(
  158. Tracking::get_time_spent_on_the_platform($teacher_id, true)
  159. );
  160. if ($i % 2 == 0) {
  161. $class_tr = 'row_odd';
  162. } else {
  163. $class_tr = 'row_even';
  164. }
  165. $teachers_table .= '<tr class="'.$class_tr.'">
  166. <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
  167. <td align="right">'.$time_on_platform.'</td>
  168. </tr>';
  169. $i++;
  170. }
  171. $teachers_table .= '</table>';
  172. } else {
  173. $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
  174. }
  175. $content .= $teachers_table;
  176. if (count($teachers) > 0) {
  177. $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>';
  178. }
  179. return $content;
  180. }
  181. /**
  182. * Get number of teachers.
  183. *
  184. * @return int
  185. */
  186. public function get_number_of_teachers()
  187. {
  188. return count($this->teachers);
  189. }
  190. }