block_student.class.php 9.3 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(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. private $user_id;
  24. private $students;
  25. private $path;
  26. private $permission = array(DRH);
  27. /**
  28. * Constructor
  29. */
  30. public function __construct ($user_id) {
  31. $this->user_id = $user_id;
  32. $this->path = 'block_student';
  33. if ($this->is_block_visible_for_user($user_id)) {
  34. /*if (api_is_platform_admin()) {
  35. $this->students = UserManager::get_user_list(array('status' => STUDENT));
  36. } else {*/
  37. $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT);
  38. //}
  39. }
  40. }
  41. /**
  42. * This method check if a user is allowed to see the block inside dashboard interface
  43. * @param int User id
  44. * @return bool Is block visible for user
  45. */
  46. public function is_block_visible_for_user($user_id) {
  47. $user_info = api_get_user_info($user_id);
  48. $user_status = $user_info['status'];
  49. $is_block_visible_for_user = false;
  50. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  51. $is_block_visible_for_user = true;
  52. }
  53. return $is_block_visible_for_user;
  54. }
  55. /**
  56. * This method return content html containing information about students and its position for showing it inside dashboard interface
  57. * it's important to use the name 'get_block' for beeing used from dashboard controller
  58. * @return array column and content html
  59. */
  60. public function get_block() {
  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. $students = $this->students;
  86. $content = '<div style="margin:10px;">';
  87. $content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>';
  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_code));
  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. $attendance = new Attendance();
  144. $students = $this->students;
  145. $content = '<div style="margin:5px;">';
  146. $content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>';
  147. if (count($students) > 0) {
  148. $students_table = '<table class="data_table">';
  149. $students_table .= '<tr>
  150. <th>'.get_lang('User').'</th>
  151. <th>'.get_lang('AttendancesFaults').'</th>
  152. <th>'.get_lang('Evaluations').'</th>
  153. </tr>';
  154. $i = 1;
  155. foreach ($students as $student) {
  156. $student_id = $student['user_id'];
  157. $firstname = $student['firstname'];
  158. $lastname = $student['lastname'];
  159. $username = $student['username'];
  160. // get average of faults in attendances by student
  161. $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
  162. if (!empty($results_faults_avg)) {
  163. $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>';
  164. } else {
  165. $attendances_faults_avg = '0%';
  166. }
  167. $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
  168. $evaluations_avg = 0;
  169. $score = $weight = 0;
  170. foreach ($courses_by_user as $course) {
  171. $course_code = $course['code'];
  172. $cats = Category::load(null, null, $course_code, null, null, null, false);
  173. $scoretotal = array();
  174. if (isset($cats) && isset($cats[0])) {
  175. $scoretotal= $cats[0]->calc_score($student_id, $course_code);
  176. }
  177. if (!empty($scoretotal)) {
  178. $score += $scoretotal[0];
  179. $weight += $scoretotal[1];
  180. }
  181. }
  182. if (!empty($weight)) {
  183. $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>';
  184. }
  185. if ($i%2 == 0) {
  186. $class_tr = 'row_odd';
  187. } else {
  188. $class_tr = 'row_even';
  189. }
  190. $students_table .= '<tr class="'.$class_tr.'">
  191. <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
  192. <td>'.$attendances_faults_avg.'</td>
  193. <td>'.$evaluations_avg.'</td>
  194. </tr>';
  195. $i++;
  196. }
  197. $students_table .= '</table>';
  198. } else {
  199. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  200. }
  201. $content .= $students_table;
  202. if (count($students) > 0) {
  203. $content .= '<div style="text-align:right;margin-top:10px;">
  204. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a>
  205. </div>';
  206. }
  207. $content .= '</div>';
  208. return $content;
  209. }
  210. /**
  211. * Get number of students
  212. * @return int
  213. */
  214. function get_number_of_students() {
  215. return count($this->students);
  216. }
  217. }