block_student.class.php 9.6 KB

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