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