block_student.class.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. * @package chamilo.dashboard
  6. * @author Christian Fasanando
  7. */
  8. /**
  9. * This class is used like controller for student block plugin,
  10. * the class name must be registered inside path.info file (e.g: controller = "BlockStudent"), so dashboard controller will be instantiate it
  11. * @package chamilo.dashboard
  12. */
  13. class BlockStudent extends Block
  14. {
  15. private $user_id;
  16. private $students;
  17. private $path;
  18. private $permission = array(DRH);
  19. /**
  20. * Constructor
  21. */
  22. public function __construct ($user_id)
  23. {
  24. $this->user_id = $user_id;
  25. $this->path = 'block_student';
  26. if ($this->is_block_visible_for_user($user_id)) {
  27. $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT);
  28. }
  29. }
  30. /**
  31. * This method check if a user is allowed to see the block inside dashboard interface
  32. * @param int User id
  33. * @return bool Is block visible for user
  34. */
  35. public function is_block_visible_for_user($user_id)
  36. {
  37. $user_info = api_get_user_info($user_id);
  38. $user_status = $user_info['status'];
  39. $is_block_visible_for_user = false;
  40. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  41. $is_block_visible_for_user = true;
  42. }
  43. return $is_block_visible_for_user;
  44. }
  45. /**
  46. * This method return content html containing information about students and its position for showing it inside dashboard interface
  47. * it's important to use the name 'get_block' for beeing used from dashboard controller
  48. * @return array column and content html
  49. */
  50. public function get_block()
  51. {
  52. global $charset;
  53. $column = 1;
  54. $data = array();
  55. $student_content_html = $this->get_students_content_html_for_drh();
  56. $html = '<li class="widget color-blue" id="intro">
  57. <div class="widget-head">
  58. <h3>'.get_lang('StudentsInformationsList').'</h3>
  59. <div class="widget-actions"><a onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">'.
  60. Display::return_icon('close.gif',get_lang('Close')).'</a>
  61. </div>
  62. </div>
  63. <div class="widget-content">
  64. '.$student_content_html.'
  65. </div>
  66. </li>';
  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 for showing it inside dashboard interface
  73. * @return string content html
  74. */
  75. public function get_students_content_html_for_platform_admin()
  76. {
  77. $students = $this->students;
  78. $content = '<div style="margin:10px;">';
  79. $content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>';
  80. $students_table = null;
  81. if (count($students) > 0) {
  82. $students_table .= '<table class="data_table">';
  83. $students_table .= '<tr>
  84. <th width="10%" rowspan="2">'.get_lang('FirstName').'</th>
  85. <th width="10%" rowspan="2">'.get_lang('LastName').'</th>
  86. <th width="30%" colspan="2">'.get_lang('CourseInformation').'</th>
  87. </tr>
  88. <tr>
  89. <th width="10%">'.get_lang('Courses').'</th>
  90. <th width="10%">'.get_lang('Time').'</th>
  91. </tr>';
  92. $i = 1;
  93. foreach ($students as $student) {
  94. $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true);
  95. $count_courses = count($courses_by_user);
  96. $rowspan = $count_courses?$count_courses+1:2;
  97. if ($i%2 == 0) {
  98. $style = ' style="background-color:#F2F2F2" ';
  99. } else {
  100. $style = ' style="background-color:#FFF" ';
  101. }
  102. $students_table .= '<tr '.$style.'>
  103. <td rowspan="'.$rowspan.'">'.$student['firstname'].'</td>
  104. <td rowspan="'.$rowspan.'">'.$student['lastname'].'</td>
  105. </tr>';
  106. // courses information about the student
  107. if (!empty($courses_by_user)) {
  108. foreach ($courses_by_user as $course) {
  109. $course_code = $course['code'];
  110. $courseInfo = api_get_course_info($course_code);
  111. $courseId = $courseInfo['real_id'];
  112. $course_title = $course['title'];
  113. $time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($student['user_id'], $courseId));
  114. $students_table .= '<tr '.$style.'>
  115. <td align="right">'.$course_title.'</td>
  116. <td align="right">'.$time.'</td>
  117. </tr>';
  118. }
  119. } else {
  120. $students_table .= '<tr '.$style.'>
  121. <td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td>
  122. </tr>';
  123. }
  124. $i++;
  125. }
  126. $students_table .= '</table>';
  127. } else {
  128. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  129. }
  130. $content .= $students_table;
  131. if (count($students) > 0) {
  132. $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>';
  133. }
  134. $content .= '</div>';
  135. return $content;
  136. }
  137. public function get_students_content_html_for_drh() {
  138. $attendance = new Attendance();
  139. $students = $this->students;
  140. $content = '<div style="margin:5px;">';
  141. $content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>';
  142. $students_table = null;
  143. if (count($students) > 0) {
  144. $students_table .= '<table class="data_table">';
  145. $students_table .= '<tr>
  146. <th>'.get_lang('User').'</th>
  147. <th>'.get_lang('AttendancesFaults').'</th>
  148. <th>'.get_lang('Evaluations').'</th>
  149. </tr>';
  150. $i = 1;
  151. foreach ($students as $student) {
  152. $student_id = $student['user_id'];
  153. $firstname = $student['firstname'];
  154. $lastname = $student['lastname'];
  155. $username = $student['username'];
  156. // get average of faults in attendances by student
  157. $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
  158. if (!empty($results_faults_avg)) {
  159. $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>';
  160. } else {
  161. $attendances_faults_avg = '0%';
  162. }
  163. $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
  164. $evaluations_avg = 0;
  165. $score = $weight = 0;
  166. foreach ($courses_by_user as $course) {
  167. $course_code = $course['code'];
  168. $cats = Category::load(null, null, $course_code, null, null, null, false);
  169. $scoretotal = array();
  170. if (isset($cats) && isset($cats[0])) {
  171. $scoretotal= $cats[0]->calc_score($student_id, null, $course_code);
  172. }
  173. if (!empty($scoretotal)) {
  174. $score += $scoretotal[0];
  175. $weight += $scoretotal[1];
  176. }
  177. }
  178. if (!empty($weight)) {
  179. $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>';
  180. }
  181. if ($i%2 == 0) {
  182. $class_tr = 'row_odd';
  183. } else {
  184. $class_tr = 'row_even';
  185. }
  186. $students_table .= '<tr class="'.$class_tr.'">
  187. <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
  188. <td>'.$attendances_faults_avg.'</td>
  189. <td>'.$evaluations_avg.'</td>
  190. </tr>';
  191. $i++;
  192. }
  193. $students_table .= '</table>';
  194. } else {
  195. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  196. }
  197. $content .= $students_table;
  198. if (count($students) > 0) {
  199. $content .= '<div style="text-align:right;margin-top:10px;">
  200. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a>
  201. </div>';
  202. }
  203. $content .= '</div>';
  204. return $content;
  205. }
  206. /**
  207. * Get number of students
  208. * @return int
  209. */
  210. function get_number_of_students()
  211. {
  212. return count($this->students);
  213. }
  214. }