Skip to content

Commit 207e42a

Browse files
committed
Adding user image when exporting to PDF see BT#2741
1 parent e14297f commit 207e42a

File tree

4 files changed

+40
-24
lines changed

4 files changed

+40
-24
lines changed

main/css/print.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;}
487487
text-align:left;
488488
padding-left:5px;
489489
} /* header cell in data table in tools */
490+
490491
.data_table {
491492
border-collapse: collapse;
492493
width: 100%;
@@ -518,7 +519,6 @@ padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;}
518519
text-align: left;
519520
}
520521

521-
522522
.data_table_no_border {
523523
border-collapse: collapse;
524524
border-spacing: 0;

main/inc/lib/export.lib.inc.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public static function _export_complex_table_xml_helper ($data, $level = 1) {
169169
return $string;
170170
}
171171

172-
public static function export_table_pdf($data, $file_name = 'export', $header, $description, $params = array()) {
172+
public static function export_table_pdf($data, $file_name = 'export', $header = null, $description = null, $params = array(), $header_attributes = array()) {
173173
$headers = $data[0];
174174
unset($data[0]);
175175
$html = '';
@@ -185,6 +185,8 @@ public static function export_table_pdf($data, $file_name = 'export', $header, $
185185
$column = 0;
186186
foreach ($headers as $header) {
187187
$table->setHeaderContents($row, $column, $header);
188+
$attributes = $header_attributes[$column];
189+
$table->updateCellAttributes($row, $column, $attributes);
188190
$column++;
189191
}
190192
$row++;
@@ -193,23 +195,22 @@ public static function export_table_pdf($data, $file_name = 'export', $header, $
193195
$column = 0;
194196
foreach ($printable_data_row as &$printable_data_cell) {
195197
$table->setCellContents($row, $column, $printable_data_cell);
196-
//$table->updateCellAttributes($row, $column);
198+
//$table->updateCellAttributes($row, $column, $atributes);
197199
$column++;
198200
}
199201
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
200202
$row++;
201203
}
202204

203205
$html .= $table->toHtml();
204-
$html = api_utf8_encode($html);
205-
206+
$html = api_utf8_encode($html);
207+
206208
$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).'/print.css';
207-
$css = file_exists($css_file) ? @file_get_contents($css_file) : '';
209+
$css = file_exists($css_file) ? @file_get_contents($css_file) : '';
208210

209211
$pdf = new PDF('A4', 'P', $params);
210212
$pdf->set_custom_header($headers_in_pdf);
211213
$pdf->content_to_pdf($html, $css, $file_name, api_get_course_id());
212214
exit;
213215
}
214-
215216
}

main/inc/lib/main_api.lib.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,24 +1031,28 @@ function _api_format_user($user, $add_password = false) {
10311031

10321032
//Getting user avatar
10331033

1034-
$picture_filename = trim($user['picture_uri']);
1034+
$picture_filename = trim($user['picture_uri']);
10351035
$avatar = api_get_path(WEB_CODE_PATH).'img/unknown.jpg';
10361036
$avatar_small = api_get_path(WEB_CODE_PATH).'img/unknown_22.jpg';
1037+
$avatar_sys_path = api_get_path(SYS_CODE_PATH).'img/unknown.jpg';
10371038
$dir = 'upload/users/'.$user_id.'/';
10381039

1039-
if (!empty($picture_filename) && api_is_anonymous() ) {
1040+
//if (!empty($picture_filename) && api_is_anonymous() ) { //Why you have to be anonymous?
1041+
if (!empty($picture_filename)) {
10401042
if (api_get_setting('split_users_upload_directory') === 'true') {
10411043
$dir = 'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/';
10421044
}
10431045
}
1044-
10451046
$image_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename;
1047+
10461048
if (file_exists($image_sys_path) && !is_dir($image_sys_path)) {
10471049
$avatar = api_get_path(WEB_CODE_PATH).$dir.$picture_filename;
10481050
$avatar_small = api_get_path(WEB_CODE_PATH).$dir.'small_'.$picture_filename;
1051+
$avatar_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename;
10491052
}
10501053

10511054
$result['avatar'] = $avatar;
1055+
$result['avatar_sys_path'] = $avatar_sys_path;
10521056
$result['avatar_small'] = $avatar_small;
10531057

10541058
if (isset($user['user_is_online'])) {
@@ -1058,7 +1062,6 @@ function _api_format_user($user, $add_password = false) {
10581062
$result['user_is_online_in_chat'] = intval($user['user_is_online_in_chat']);
10591063
}
10601064

1061-
10621065
if ($add_password) {
10631066
$result['password'] = $user['password'];
10641067
}

main/user/user.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Code
2424
*/
2525
// name of the language file that needs to be included
26-
$language_file = array('registration', 'admin', 'userInfo');
26+
$language_file = array('registration', 'admin', 'userInfo', 'registration');
2727
$use_anonymous = true;
2828
require_once '../inc/global.inc.php';
2929
$current_course_tool = TOOL_USER;
@@ -77,6 +77,8 @@
7777
}
7878
}
7979

80+
$user_image_pdf_size = 80;
81+
8082
if (api_is_allowed_to_edit(null, true)) {
8183
if (isset($_GET['action'])) {
8284
switch ($_GET['action']) {
@@ -120,9 +122,9 @@
120122

121123
if ($_GET['type'] == 'pdf') {
122124
if ($is_western_name_order) {
123-
$a_users[0] = array('#', get_lang('OfficialCode'), get_lang('FirstName').', '.get_lang('LastName'));
125+
$a_users[0] = array('#', get_lang('UserPicture'), get_lang('OfficialCode'), get_lang('FirstName').', '.get_lang('LastName'));
124126
} else {
125-
$a_users[0] = array('#', get_lang('OfficialCode'), get_lang('LastName').', '.get_lang('FirstName'));
127+
$a_users[0] = array('#', get_lang('UserPicture'), get_lang('OfficialCode'), get_lang('LastName').', '.get_lang('FirstName'));
126128
}
127129
}
128130

@@ -168,20 +170,21 @@
168170
}
169171
$data[] = $user;
170172
if ($_GET['type'] == 'pdf') {
173+
$user_info = api_get_user_info($user['user_id']);
174+
$user_image = Display::img($user_info['avatar'], null, array('width' => $user_image_pdf_size.'px'));
171175
if ($is_western_name_order) {
172-
$user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
176+
$user_pdf = array($counter, $user_image, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
173177
} else {
174-
$user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
178+
$user_pdf = array($counter, $user_image, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
175179
}
176180
$a_users[] = $user_pdf;
177181
} else {
178182
$a_users[] = $user;
179183
}
180184
$counter++;
181185
}
182-
}
183-
184-
186+
}
187+
185188
if ($session_id == 0) {
186189

187190
// users directly subscribed to the course
@@ -220,11 +223,14 @@
220223
}
221224
}
222225
if ($_GET['type'] == 'pdf') {
226+
$user_info = api_get_user_info($user['user_id']);
227+
$user_image = Display::img($user_info['avatar'], null, array('width' => $user_image_pdf_size.'px'));
228+
223229
if ($is_western_name_order) {
224-
$user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
230+
$user_pdf = array($counter, $user_image, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
225231
} else {
226-
$user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
227-
}
232+
$user_pdf = array($counter, $user_image, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
233+
}
228234
$a_users[] = $user_pdf;
229235
} else {
230236
$a_users[] = $user;
@@ -268,7 +274,7 @@
268274
if (!empty($session_id)) {
269275
//If I'm a coach
270276
$coaches = CourseManager::get_coach_list_from_course_code($course_info['code'], $session_id);
271-
277+
272278
if (isset($coaches) && isset($coaches[$user_id])) {
273279
$user_info = api_get_user_info($user_id);
274280
$description .= '<tr><td>'.get_lang('Coach').': </td><td class="highlight">'.$user_info['complete_name'].'</td>';
@@ -284,7 +290,13 @@
284290
$description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
285291
$description .= '</table>';
286292
$params = array();
287-
Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params);
293+
$header_attributes = array(
294+
array('style' => 'width:10px'),
295+
array('style' => 'width:30px'),
296+
array('style' => 'width:50px'),
297+
array('style' => 'width:500px'),
298+
);
299+
Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params, $header_attributes);
288300
exit;
289301
}
290302
}

0 commit comments

Comments
 (0)