block_student.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. /**
  3. * This file is part of student block plugin for dashboard,
  4. * it should be required inside dashboard controller for showing it into dashboard interface from plattform.
  5. *
  6. * @package chamilo.dashboard
  7. *
  8. * @author Christian Fasanando
  9. */
  10. /**
  11. * This class is used like controller for student block plugin,
  12. * the class name must be registered inside path.info file
  13. * (e.g: controller = "BlockStudent"), so dashboard controller will be instantiate it.
  14. *
  15. * @package chamilo.dashboard
  16. */
  17. class BlockStudent extends Block
  18. {
  19. private $user_id;
  20. private $students;
  21. private $path;
  22. private $permission = [DRH];
  23. /**
  24. * Constructor.
  25. */
  26. public function __construct($user_id)
  27. {
  28. $this->user_id = $user_id;
  29. $this->path = 'block_student';
  30. if ($this->is_block_visible_for_user($user_id)) {
  31. $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT);
  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
  53. * about students and its position for showing it inside dashboard interface
  54. * it's important to use the name 'get_block' for beeing used from dashboard controller.
  55. *
  56. * @return array column and content html
  57. */
  58. public function get_block()
  59. {
  60. global $charset;
  61. $column = 1;
  62. $data = [];
  63. $student_content_html = $this->get_students_content_html_for_drh();
  64. $html = '<div class="panel panel-default" id="intro">
  65. <div class="panel-heading">
  66. '.get_lang('StudentsInformationsList').'
  67. <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.'">
  68. <em class="fa fa-times"></em>
  69. </a>
  70. </div>
  71. </div>
  72. <div class="panel-body">
  73. '.$student_content_html.'
  74. </div>
  75. </div>';
  76. $data['column'] = $column;
  77. $data['content_html'] = $html;
  78. return $data;
  79. }
  80. /**
  81. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface.
  82. *
  83. * @return string content html
  84. */
  85. public function get_students_content_html_for_platform_admin()
  86. {
  87. $students = $this->students;
  88. $content = '<h4>'.get_lang('YourStudents').'</h4>';
  89. $students_table = null;
  90. if (count($students) > 0) {
  91. $students_table .= '<table class="data_table">';
  92. $students_table .= '<tr>
  93. <th width="10%" rowspan="2">'.get_lang('FirstName').'</th>
  94. <th width="10%" rowspan="2">'.get_lang('LastName').'</th>
  95. <th width="30%" colspan="2">'.get_lang('CourseInformation').'</th>
  96. </tr>
  97. <tr>
  98. <th width="10%">'.get_lang('Courses').'</th>
  99. <th width="10%">'.get_lang('Time').'</th>
  100. </tr>';
  101. $i = 1;
  102. foreach ($students as $student) {
  103. $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true);
  104. $count_courses = count($courses_by_user);
  105. $rowspan = $count_courses ? $count_courses + 1 : 2;
  106. if ($i % 2 == 0) {
  107. $style = ' style="background-color:#F2F2F2" ';
  108. } else {
  109. $style = ' style="background-color:#FFF" ';
  110. }
  111. $students_table .= '<tr '.$style.'>
  112. <td rowspan="'.$rowspan.'">'.$student['firstname'].'</td>
  113. <td rowspan="'.$rowspan.'">'.$student['lastname'].'</td>
  114. </tr>';
  115. // courses information about the student
  116. if (!empty($courses_by_user)) {
  117. foreach ($courses_by_user as $course) {
  118. $course_code = $course['code'];
  119. $courseInfo = api_get_course_info($course_code);
  120. $courseId = $courseInfo['real_id'];
  121. $course_title = $course['title'];
  122. $time = api_time_to_hms(Tracking::get_time_spent_on_the_course($student['user_id'], $courseId));
  123. $students_table .= '<tr '.$style.'>
  124. <td align="right">'.$course_title.'</td>
  125. <td align="right">'.$time.'</td>
  126. </tr>';
  127. }
  128. } else {
  129. $students_table .= '<tr '.$style.'>
  130. <td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td>
  131. </tr>';
  132. }
  133. $i++;
  134. }
  135. $students_table .= '</table>';
  136. } else {
  137. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  138. }
  139. $content .= $students_table;
  140. if (count($students) > 0) {
  141. $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=useroverview">'.get_lang('SeeMore').'</a></div>';
  142. }
  143. //$content .= '</div>';
  144. return $content;
  145. }
  146. /**
  147. * @return string
  148. */
  149. public function get_students_content_html_for_drh()
  150. {
  151. $attendance = new Attendance();
  152. $students = $this->students;
  153. $content = '<h4>'.get_lang('YourStudents').'</h4>';
  154. $students_table = null;
  155. if (count($students) > 0) {
  156. $students_table .= '<table class="data_table">';
  157. $students_table .= '<tr>
  158. <th>'.get_lang('User').'</th>
  159. <th>'.get_lang('AttendancesFaults').'</th>
  160. <th>'.get_lang('Evaluations').'</th>
  161. </tr>';
  162. $i = 1;
  163. foreach ($students as $student) {
  164. $student_id = $student['user_id'];
  165. $firstname = $student['firstname'];
  166. $lastname = $student['lastname'];
  167. $username = $student['username'];
  168. // get average of faults in attendances by student
  169. $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
  170. if (!empty($results_faults_avg)) {
  171. $attendances_faults_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>';
  172. } else {
  173. $attendances_faults_avg = '0%';
  174. }
  175. $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
  176. $evaluations_avg = 0;
  177. $score = $weight = 0;
  178. foreach ($courses_by_user as $course) {
  179. $course_code = $course['code'];
  180. $cats = Category::load(
  181. null,
  182. null,
  183. $course_code,
  184. null,
  185. null,
  186. null,
  187. false
  188. );
  189. $scoretotal = [];
  190. if (isset($cats) && isset($cats[0])) {
  191. $scoretotal = $cats[0]->calc_score($student_id, null, $course_code);
  192. }
  193. if (!empty($scoretotal)) {
  194. $score += $scoretotal[0];
  195. $weight += $scoretotal[1];
  196. }
  197. }
  198. if (!empty($weight)) {
  199. $evaluations_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.round($score, 2).'/'.round($weight, 2).'('.round(($score / $weight) * 100, 2).' %)</a>';
  200. }
  201. if ($i % 2 == 0) {
  202. $class_tr = 'row_odd';
  203. } else {
  204. $class_tr = 'row_even';
  205. }
  206. $students_table .= '<tr class="'.$class_tr.'">
  207. <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
  208. <td>'.$attendances_faults_avg.'</td>
  209. <td>'.$evaluations_avg.'</td>
  210. </tr>';
  211. $i++;
  212. }
  213. $students_table .= '</table>';
  214. } else {
  215. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  216. }
  217. $content .= $students_table;
  218. if (count($students) > 0) {
  219. $content .= '<div style="text-align:right;margin-top:10px;">
  220. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a>
  221. </div>';
  222. }
  223. //$content .= '</div>';
  224. return $content;
  225. }
  226. /**
  227. * Get number of students.
  228. *
  229. * @return int
  230. */
  231. public function get_number_of_students()
  232. {
  233. return count($this->students);
  234. }
  235. }