block_student.class.php 9.6 KB

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