block_teacher.class.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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
  14. * (e.g: controller = "BlockTeacher"), so dashboard controller will be instantiate it
  15. * @package chamilo.dashboard
  16. */
  17. class BlockTeacher extends Block
  18. {
  19. private $user_id;
  20. private $teachers;
  21. private $path;
  22. private $permission = array(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. * @param int User id
  37. * @return bool Is block visible for user
  38. */
  39. public function is_block_visible_for_user($user_id)
  40. {
  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. {
  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. <i class="fa fa-times"></i>
  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 for showing it inside dashboard interface
  79. * @return string content html
  80. */
  81. public function get_teachers_content_html_for_platform_admin()
  82. {
  83. $teachers = $this->teachers;
  84. //$content = '<div style="margin:10px;">';
  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) $class_tr = 'row_odd';
  105. else $class_tr = 'row_even';
  106. $teachers_table .= '
  107. <tr class="'.$class_tr.'">
  108. <td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>
  109. <td align="right">'.$time_on_platform.'</td>
  110. <td align="right">'.$last_connection.'</td>
  111. </tr>
  112. ';
  113. $i++;
  114. }
  115. $teachers_table .= '</table>';
  116. } else {
  117. $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
  118. }
  119. $content .= $teachers_table;
  120. if (count($teachers) > 0) {
  121. $content .= '<div style="text-align:right;margin-top:10px;">
  122. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin">'.get_lang('SeeMore').'</a></div>';
  123. }
  124. //$content .= '</div>';
  125. return $content;
  126. }
  127. public function get_teachers_content_html_for_drh()
  128. {
  129. $teachers = $this->teachers;
  130. //$content = '<div style="margin:10px;">';
  131. $content = '<h4>'.get_lang('YourTeachers').'</h4>';
  132. $teachers_table = null;
  133. if (count($teachers) > 0) {
  134. $a_last_week = get_last_week();
  135. $last_week = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
  136. $teachers_table .= '<table class="data_table" width:"95%">';
  137. $teachers_table .= '
  138. <tr>
  139. <th>'.get_lang('User').'</th>
  140. <th>'.get_lang('TimeSpentLastWeek').'<br />'.$last_week.'</th>
  141. </tr>
  142. ';
  143. $i = 1;
  144. foreach ($teachers as $teacher) {
  145. $teacher_id = $teacher['user_id'];
  146. $firstname = $teacher['firstname'];
  147. $lastname = $teacher['lastname'];
  148. $username = $teacher['username'];
  149. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id,true));
  150. if ($i%2 == 0) $class_tr = 'row_odd';
  151. else $class_tr = 'row_even';
  152. $teachers_table .= '<tr class="'.$class_tr.'">
  153. <td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>
  154. <td align="right">'.$time_on_platform.'</td>
  155. </tr>';
  156. $i++;
  157. }
  158. $teachers_table .= '</table>';
  159. } else {
  160. $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
  161. }
  162. $content .= $teachers_table;
  163. if (count($teachers) > 0) {
  164. $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>';
  165. }
  166. //$content .= '</div>';
  167. return $content;
  168. }
  169. /**
  170. * Get number of teachers
  171. * @return int
  172. */
  173. function get_number_of_teachers()
  174. {
  175. return count($this->teachers);
  176. }
  177. }