123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- class BlockStudent extends Block
- {
- private $user_id;
- private $students;
- private $permission = [DRH];
-
- public function __construct($user_id)
- {
- $this->user_id = $user_id;
- $this->path = 'block_student';
- if ($this->is_block_visible_for_user($user_id)) {
- $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT);
- }
- }
-
- public function is_block_visible_for_user($user_id)
- {
- $user_info = api_get_user_info($user_id);
- $user_status = $user_info['status'];
- $is_block_visible_for_user = false;
- if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
- $is_block_visible_for_user = true;
- }
- return $is_block_visible_for_user;
- }
-
- public function get_block()
- {
- $column = 1;
- $data = [];
- $html = $this->getBlockCard(
- get_lang('Your learners'),
- $this->getContent()
- );
- $data['column'] = $column;
- $data['content_html'] = $html;
- return $data;
- }
-
- public function getContent()
- {
- $students = $this->students;
- $students_table = null;
- if (count($students) > 0) {
- $students_table .= '<table class="data_table">';
- $students_table .= '<tr>
- <th width="10%" rowspan="2">'.get_lang('First name').'</th>
- <th width="10%" rowspan="2">'.get_lang('Last name').'</th>
- <th width="30%" colspan="2">'.get_lang('Course Information').'</th>
- </tr>
- <tr>
- <th width="10%">'.get_lang('Courses').'</th>
- <th width="10%">'.get_lang('Time').'</th>
- </tr>';
- $i = 1;
- foreach ($students as $student) {
- $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true);
- $count_courses = count($courses_by_user);
- $rowspan = $count_courses ? $count_courses + 1 : 2;
- if ($i % 2 == 0) {
- $style = ' style="background-color:#F2F2F2" ';
- } else {
- $style = ' style="background-color:#FFF" ';
- }
- $students_table .= '<tr '.$style.'>
- <td rowspan="'.$rowspan.'">'.$student['firstname'].'</td>
- <td rowspan="'.$rowspan.'">'.$student['lastname'].'</td>
- </tr>';
-
- if (!empty($courses_by_user)) {
- foreach ($courses_by_user as $course) {
- $course_code = $course['code'];
- $courseInfo = api_get_course_info($course_code);
- $courseId = $courseInfo['real_id'];
- $course_title = $course['title'];
- $time = api_time_to_hms(Tracking::get_time_spent_on_the_course($student['user_id'], $courseId));
- $students_table .= '<tr '.$style.'>
- <td align="right">'.$course_title.'</td>
- <td align="right">'.$time.'</td>
- </tr>';
- }
- } else {
- $students_table .= '<tr '.$style.'>
- <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>
- </tr>';
- }
- $i++;
- }
- $students_table .= '</table>';
- } else {
- $students_table .= get_lang('ThereIsNoInformationAboutYour learners');
- }
- $content = $students_table;
- if (count($students) > 0) {
- $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>';
- }
- return $content;
- }
-
- public function get_students_content_html_for_drh()
- {
- $attendance = new Attendance();
- $students = $this->students;
- $content = '<h4>'.get_lang('Your learners').'</h4>';
- $students_table = null;
- if (count($students) > 0) {
- $students_table .= '<table class="data_table">';
- $students_table .= '<tr>
- <th>'.get_lang('User').'</th>
- <th>'.get_lang('Not attended').'</th>
- <th>'.get_lang('Evaluations').'</th>
- </tr>';
- $i = 1;
- foreach ($students as $student) {
- $student_id = $student['user_id'];
- $firstname = $student['firstname'];
- $lastname = $student['lastname'];
- $username = $student['username'];
-
- $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
- if (!empty($results_faults_avg)) {
- $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>';
- } else {
- $attendances_faults_avg = '0%';
- }
- $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
- $evaluations_avg = 0;
- $score = $weight = 0;
- foreach ($courses_by_user as $course) {
- $course_code = $course['code'];
- $cats = Category::load(
- null,
- null,
- $course_code,
- null,
- null,
- null,
- false
- );
- $scoretotal = [];
- if (isset($cats) && isset($cats[0])) {
- $scoretotal = $cats[0]->calc_score($student_id, null, $course_code);
- }
- if (!empty($scoretotal)) {
- $score += $scoretotal[0];
- $weight += $scoretotal[1];
- }
- }
- if (!empty($weight)) {
- $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>';
- }
- if ($i % 2 == 0) {
- $class_tr = 'row_odd';
- } else {
- $class_tr = 'row_even';
- }
- $students_table .= '<tr class="'.$class_tr.'">
- <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
- <td>'.$attendances_faults_avg.'</td>
- <td>'.$evaluations_avg.'</td>
- </tr>';
- $i++;
- }
- $students_table .= '</table>';
- } else {
- $students_table .= get_lang('ThereIsNoInformationAboutYour learners');
- }
- $content .= $students_table;
- if (count($students) > 0) {
- $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('See more').'</a>
- </div>';
- }
-
- return $content;
- }
-
- public function get_number_of_students()
- {
- return count($this->students);
- }
- }
|