block_teacher.class.php 7.5 KB

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