Skip to content

Commit e14297f

Browse files
committed
User list to PDF, now it shows the current teacher BT#2741
1 parent 96f3aae commit e14297f

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

main/inc/lib/course.lib.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,17 +1283,14 @@ public static function get_coach_list_from_course_code($course_code, $session_id
12831283
}
12841284

12851285
// We get the session coach.
1286-
$rs = Database::query('SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION).
1287-
' WHERE id="'.$session_id.'"');
1288-
$user_info = array();
1286+
$rs = Database::query('SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' WHERE id="'.$session_id.'"');
12891287
$session_id_coach = Database::result($rs, 0, 'id_coach');
12901288
$user_info = Database::get_user_info_from_id($session_id_coach);
12911289
$user_info['status'] = $user['status'];
12921290
$user_info['role'] = $user['role'];
12931291
$user_info['tutor_id'] = $user['tutor_id'];
12941292
$user_info['email'] = $user['email'];
12951293
$users[$session_id_coach] = $user_info;
1296-
12971294
return $users;
12981295
}
12991296

main/user/user.php

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130

131131
// users subscribed to the course through a session
132132

133-
if (api_get_session_id()) {
133+
if (api_get_session_id()) {
134134
$table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
135135
$sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", $select_email_condition phone, user.official_code, active $legal
136136
FROM $table_session_course_user as session_course_user, $table_users as user ";
@@ -242,27 +242,50 @@
242242
Export::export_table_xls($a_users);
243243
exit;
244244
case 'pdf' :
245-
$header = get_lang('StudentList');
246-
$description = '<table class="data_table_no_border">';
247-
if (api_get_session_id()) {
248-
$description .= '<tr><td>'.get_lang('Session').': </td><td class="highlight">'.api_get_session_name(api_get_session_id()).'</td>';
249-
}
250-
$description .= '<tr><td>'.get_lang('Course').': </td><td class="highlight">'.$course_info['name'].'</td>';
251-
252-
$teachers = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']);
253-
$coaches = CourseManager::get_coach_list_from_course_code_to_string($course_info['code'], $session_id);
245+
$header = get_lang('StudentList');
246+
$description = '<table class="data_table_no_border">';
247+
if (api_get_session_id()) {
248+
$description .= '<tr><td>'.get_lang('Session').': </td><td class="highlight">'.api_get_session_name(api_get_session_id()).'</td>';
249+
}
250+
$description .= '<tr><td>'.get_lang('Course').': </td><td class="highlight">'.$course_info['name'].'</td>';
254251

255-
if (!empty($teachers)) {
256-
$description .= '<tr><td>'.get_lang('Teachers').': </td><td class="highlight">'.$teachers.' </td>';
257-
}
258-
if (!empty($coaches)) {
259-
$description .= '<tr><td>'.get_lang('Coachs').': </td><td class="highlight">'.$coaches.' </td>';
260-
}
261-
$description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
262-
$description .= '</table>';
263-
$params = array();
264-
Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params);
265-
exit;
252+
$teachers = CourseManager::get_teacher_list_from_course_code($course_info['code']);
253+
254+
//If I'm a teacher in this course show just my name
255+
if (isset($teachers[$user_id])) {
256+
if (!empty($teachers)) {
257+
$teacher_info = $teachers[$user_id];
258+
$description .= '<tr><td>'.get_lang('Teacher').': </td><td class="highlight">'.api_get_person_name($teacher_info['firstname'], $teacher_info['lastname']).'</td>';
259+
}
260+
} else {
261+
//If not show all teachers
262+
$teachers = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']);
263+
if (!empty($teachers)) {
264+
$description .= '<tr><td>'.get_lang('Teachers').': </td><td class="highlight">'.$teachers.'</td>';
265+
}
266+
}
267+
268+
if (!empty($session_id)) {
269+
//If I'm a coach
270+
$coaches = CourseManager::get_coach_list_from_course_code($course_info['code'], $session_id);
271+
272+
if (isset($coaches) && isset($coaches[$user_id])) {
273+
$user_info = api_get_user_info($user_id);
274+
$description .= '<tr><td>'.get_lang('Coach').': </td><td class="highlight">'.$user_info['complete_name'].'</td>';
275+
} else {
276+
//If not show everything
277+
$teachers = CourseManager::get_coach_list_from_course_code_to_string($course_info['code'], $session_id);
278+
if (!empty($teachers)) {
279+
$description .= '<tr><td>'.get_lang('Coachs').': </td><td class="highlight">'.$coaches.'</td>';
280+
}
281+
}
282+
}
283+
284+
$description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
285+
$description .= '</table>';
286+
$params = array();
287+
Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params);
288+
exit;
266289
}
267290
}
268291
}

0 commit comments

Comments
 (0)