block_student.class.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. * required files for getting data
  10. */
  11. require_once api_get_path(LIBRARY_PATH).'attendance.lib.php';
  12. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
  13. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
  14. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/result.class.php';
  15. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/linkfactory.class.php';
  16. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/category.class.php';
  17. /**
  18. * This class is used like controller for student block plugin,
  19. * the class name must be registered inside path.info file (e.g: controller = "BlockStudent"), so dashboard controller will be instantiate it
  20. * @package chamilo.dashboard
  21. */
  22. class BlockStudent extends Block
  23. {
  24. private $user_id;
  25. private $students;
  26. private $path;
  27. private $permission = array(DRH);
  28. /**
  29. * Constructor
  30. */
  31. public function __construct ($user_id)
  32. {
  33. $this->user_id = $user_id;
  34. $this->path = 'block_student';
  35. if ($this->is_block_visible_for_user($user_id)) {
  36. $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT);
  37. }
  38. }
  39. /**
  40. * This method check if a user is allowed to see the block inside dashboard interface
  41. * @param int User id
  42. * @return bool Is block visible for user
  43. */
  44. public function is_block_visible_for_user($user_id)
  45. {
  46. $user_info = api_get_user_info($user_id);
  47. $user_status = $user_info['status'];
  48. $is_block_visible_for_user = false;
  49. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  50. $is_block_visible_for_user = true;
  51. }
  52. return $is_block_visible_for_user;
  53. }
  54. /**
  55. * This method return content html containing information about students and its position for showing it inside dashboard interface
  56. * it's important to use the name 'get_block' for beeing used from dashboard controller
  57. * @return array column and content html
  58. */
  59. public function get_block()
  60. {
  61. global $charset;
  62. $column = 1;
  63. $data = array();
  64. $student_content_html = $this->get_students_content_html_for_drh();
  65. $html = '<li class="widget color-blue" id="intro">
  66. <div class="widget-head">
  67. <h3>'.get_lang('StudentsInformationsList').'</h3>
  68. <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.'">'.
  69. Display::return_icon('close.gif',get_lang('Close')).'</a>
  70. </div>
  71. </div>
  72. <div class="widget-content">
  73. '.$student_content_html.'
  74. </div>
  75. </li>';
  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. * @return string content html
  83. */
  84. public function get_students_content_html_for_platform_admin()
  85. {
  86. $students = $this->students;
  87. $content = '<div style="margin:10px;">';
  88. $content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>';
  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. $course_title = $course['title'];
  120. $time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($student['user_id'], $course_code));
  121. $students_table .= '<tr '.$style.'>
  122. <td align="right">'.$course_title.'</td>
  123. <td align="right">'.$time.'</td>
  124. </tr>';
  125. }
  126. } else {
  127. $students_table .= '<tr '.$style.'>
  128. <td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td>
  129. </tr>';
  130. }
  131. $i++;
  132. }
  133. $students_table .= '</table>';
  134. } else {
  135. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  136. }
  137. $content .= $students_table;
  138. if (count($students) > 0) {
  139. $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>';
  140. }
  141. $content .= '</div>';
  142. return $content;
  143. }
  144. public function get_students_content_html_for_drh() {
  145. $attendance = new Attendance();
  146. $students = $this->students;
  147. $content = '<div style="margin:5px;">';
  148. $content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>';
  149. $students_table = null;
  150. if (count($students) > 0) {
  151. $students_table .= '<table class="data_table">';
  152. $students_table .= '<tr>
  153. <th>'.get_lang('User').'</th>
  154. <th>'.get_lang('AttendancesFaults').'</th>
  155. <th>'.get_lang('Evaluations').'</th>
  156. </tr>';
  157. $i = 1;
  158. foreach ($students as $student) {
  159. $student_id = $student['user_id'];
  160. $firstname = $student['firstname'];
  161. $lastname = $student['lastname'];
  162. $username = $student['username'];
  163. // get average of faults in attendances by student
  164. $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
  165. if (!empty($results_faults_avg)) {
  166. $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>';
  167. } else {
  168. $attendances_faults_avg = '0%';
  169. }
  170. $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
  171. $evaluations_avg = 0;
  172. $score = $weight = 0;
  173. foreach ($courses_by_user as $course) {
  174. $course_code = $course['code'];
  175. $cats = Category::load(null, null, $course_code, null, null, null, false);
  176. $scoretotal = array();
  177. if (isset($cats) && isset($cats[0])) {
  178. $scoretotal= $cats[0]->calc_score($student_id, $course_code);
  179. }
  180. if (!empty($scoretotal)) {
  181. $score += $scoretotal[0];
  182. $weight += $scoretotal[1];
  183. }
  184. }
  185. if (!empty($weight)) {
  186. $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>';
  187. }
  188. if ($i%2 == 0) {
  189. $class_tr = 'row_odd';
  190. } else {
  191. $class_tr = 'row_even';
  192. }
  193. $students_table .= '<tr class="'.$class_tr.'">
  194. <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
  195. <td>'.$attendances_faults_avg.'</td>
  196. <td>'.$evaluations_avg.'</td>
  197. </tr>';
  198. $i++;
  199. }
  200. $students_table .= '</table>';
  201. } else {
  202. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  203. }
  204. $content .= $students_table;
  205. if (count($students) > 0) {
  206. $content .= '<div style="text-align:right;margin-top:10px;">
  207. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a>
  208. </div>';
  209. }
  210. $content .= '</div>';
  211. return $content;
  212. }
  213. /**
  214. * Get number of students
  215. * @return int
  216. */
  217. function get_number_of_students()
  218. {
  219. return count($this->students);
  220. }
  221. }