block_student.class.php 8.9 KB

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