block_student.class.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 = '<div class="panel panel-default" id="intro">
  57. <div class="panel-heading">
  58. '.get_lang('StudentsInformationsList').'
  59. <div class="pull-right"><a class="btn btn-danger btn-xs" 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. <em class="fa fa-times"></em>
  61. </a>
  62. </div>
  63. </div>
  64. <div class="panel-body">
  65. '.$student_content_html.'
  66. </div>
  67. </div>';
  68. $data['column'] = $column;
  69. $data['content_html'] = $html;
  70. return $data;
  71. }
  72. /**
  73. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  74. * @return string content html
  75. */
  76. public function get_students_content_html_for_platform_admin()
  77. {
  78. $students = $this->students;
  79. //$content = '<div style="margin:10px;">';
  80. $content = '<h4>'.get_lang('YourStudents').'</h4>';
  81. $students_table = null;
  82. if (count($students) > 0) {
  83. $students_table .= '<table class="data_table">';
  84. $students_table .= '<tr>
  85. <th width="10%" rowspan="2">'.get_lang('FirstName').'</th>
  86. <th width="10%" rowspan="2">'.get_lang('LastName').'</th>
  87. <th width="30%" colspan="2">'.get_lang('CourseInformation').'</th>
  88. </tr>
  89. <tr>
  90. <th width="10%">'.get_lang('Courses').'</th>
  91. <th width="10%">'.get_lang('Time').'</th>
  92. </tr>';
  93. $i = 1;
  94. foreach ($students as $student) {
  95. $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true);
  96. $count_courses = count($courses_by_user);
  97. $rowspan = $count_courses?$count_courses+1:2;
  98. if ($i%2 == 0) {
  99. $style = ' style="background-color:#F2F2F2" ';
  100. } else {
  101. $style = ' style="background-color:#FFF" ';
  102. }
  103. $students_table .= '<tr '.$style.'>
  104. <td rowspan="'.$rowspan.'">'.$student['firstname'].'</td>
  105. <td rowspan="'.$rowspan.'">'.$student['lastname'].'</td>
  106. </tr>';
  107. // courses information about the student
  108. if (!empty($courses_by_user)) {
  109. foreach ($courses_by_user as $course) {
  110. $course_code = $course['code'];
  111. $courseInfo = api_get_course_info($course_code);
  112. $courseId = $courseInfo['real_id'];
  113. $course_title = $course['title'];
  114. $time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($student['user_id'], $courseId));
  115. $students_table .= '<tr '.$style.'>
  116. <td align="right">'.$course_title.'</td>
  117. <td align="right">'.$time.'</td>
  118. </tr>';
  119. }
  120. } else {
  121. $students_table .= '<tr '.$style.'>
  122. <td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td>
  123. </tr>';
  124. }
  125. $i++;
  126. }
  127. $students_table .= '</table>';
  128. } else {
  129. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  130. }
  131. $content .= $students_table;
  132. if (count($students) > 0) {
  133. $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>';
  134. }
  135. //$content .= '</div>';
  136. return $content;
  137. }
  138. public function get_students_content_html_for_drh() {
  139. $attendance = new Attendance();
  140. $students = $this->students;
  141. //$content = '<div style="margin:5px;">';
  142. $content = '<h4>'.get_lang('YourStudents').'</h4>';
  143. $students_table = null;
  144. if (count($students) > 0) {
  145. $students_table .= '<table class="data_table">';
  146. $students_table .= '<tr>
  147. <th>'.get_lang('User').'</th>
  148. <th>'.get_lang('AttendancesFaults').'</th>
  149. <th>'.get_lang('Evaluations').'</th>
  150. </tr>';
  151. $i = 1;
  152. foreach ($students as $student) {
  153. $student_id = $student['user_id'];
  154. $firstname = $student['firstname'];
  155. $lastname = $student['lastname'];
  156. $username = $student['username'];
  157. // get average of faults in attendances by student
  158. $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
  159. if (!empty($results_faults_avg)) {
  160. $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>';
  161. } else {
  162. $attendances_faults_avg = '0%';
  163. }
  164. $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
  165. $evaluations_avg = 0;
  166. $score = $weight = 0;
  167. foreach ($courses_by_user as $course) {
  168. $course_code = $course['code'];
  169. $cats = Category::load(null, null, $course_code, null, null, null, false);
  170. $scoretotal = array();
  171. if (isset($cats) && isset($cats[0])) {
  172. $scoretotal= $cats[0]->calc_score($student_id, null, $course_code);
  173. }
  174. if (!empty($scoretotal)) {
  175. $score += $scoretotal[0];
  176. $weight += $scoretotal[1];
  177. }
  178. }
  179. if (!empty($weight)) {
  180. $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>';
  181. }
  182. if ($i%2 == 0) {
  183. $class_tr = 'row_odd';
  184. } else {
  185. $class_tr = 'row_even';
  186. }
  187. $students_table .= '<tr class="'.$class_tr.'">
  188. <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
  189. <td>'.$attendances_faults_avg.'</td>
  190. <td>'.$evaluations_avg.'</td>
  191. </tr>';
  192. $i++;
  193. }
  194. $students_table .= '</table>';
  195. } else {
  196. $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
  197. }
  198. $content .= $students_table;
  199. if (count($students) > 0) {
  200. $content .= '<div style="text-align:right;margin-top:10px;">
  201. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a>
  202. </div>';
  203. }
  204. //$content .= '</div>';
  205. return $content;
  206. }
  207. /**
  208. * Get number of students
  209. * @return int
  210. */
  211. function get_number_of_students()
  212. {
  213. return count($this->students);
  214. }
  215. }