improve pdf report BT#911

skala
Carlos Vargas 15 years ago
parent 1c5740d6e0
commit 2d9b4ae905
  1. 14
      main/gradebook/gradebook_view_result.php
  2. 13
      main/gradebook/lib/fe/exportgradebook.php
  3. 11
      main/gradebook/lib/results_data_generator.class.php

@ -197,7 +197,9 @@ if ($export_result_form->validate()) {
$datagen = new ResultsDataGenerator ($eval[0],$allresults); $datagen = new ResultsDataGenerator ($eval[0],$allresults);
// set headers pdf // set headers pdf
$h1 = array(get_lang('Teacher'),$_user['firstName'].' '.$_user['lastName']); !empty($_user['official_code'])? $officialcode=$_user['official_code'].' - ':'';
$h1 = array(get_lang('Teacher'),$officialcode.$_user['firstName'].', '.$_user['lastName']);
$h2 = array(get_lang('Score'),$eval[0]->get_max()); $h2 = array(get_lang('Score'),$eval[0]->get_max());
$h3 = array(get_lang('Course'),$_course['name']); $h3 = array(get_lang('Course'),$_course['name']);
$h4 = array(get_lang('Weight'),$eval[0]->get_weight()); $h4 = array(get_lang('Weight'),$eval[0]->get_weight());
@ -233,14 +235,15 @@ if ($export_result_form->validate()) {
array(get_lang('Code'),15), array(get_lang('Code'),15),
array($head_ape_name, 50), array($head_ape_name, 50),
array(get_lang('Score'),15), array(get_lang('Score'),15),
array(get_lang('Letters'),15),
array($head_display_score,15) array($head_display_score,15)
); );
// get data table // get data table
if (api_sort_by_first_name()) { if (api_sort_by_first_name()) {
$data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_FIRSTNAME, 0, null, true); $data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_FIRSTNAME, 0, null, true, true);
} else { } else {
$data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_LASTNAME,0,null,true); $data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_LASTNAME,0,null, true, true);
} }
$data_table = array(); $data_table = array();
@ -249,11 +252,12 @@ if ($export_result_form->validate()) {
$user_info = api_get_user_info($data['id']); $user_info = api_get_user_info($data['id']);
$result[] = $user_info['username']; $result[] = $user_info['username'];
if (!api_is_western_name_order()) { if (!api_is_western_name_order()) {
$result[] = $user_info['firstname'].' '.$user_info['lastname']; $result[] = $user_info['firstname'].', '.$user_info['lastname'];
} else { } else {
$result[] = $user_info['lastname'].' '.$user_info['firstname']; $result[] = $user_info['lastname'].', '.$user_info['firstname'];
} }
$result[] = $data['score']; $result[] = $data['score'];
$result[] = api_strtoupper(get_lang('Literal'.$data['scoreletter']));
if ($scoredisplay->is_custom()) { if ($scoredisplay->is_custom()) {
$result[] = $data['display']; $result[] = $data['display'];
} }

@ -92,14 +92,14 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
require_once api_get_path(LIBRARY_PATH).'mpdf/mpdf.php'; require_once api_get_path(LIBRARY_PATH).'mpdf/mpdf.php';
$mpdf = new mPDF('UTF-8', 'A4', '', '', 18, 15, 70, 35, 16, 13, 'P'); $mpdf = new mPDF('UTF-8', 'A4', '', '', 18, 15, 65, 35, 5, 13, 'P');
$mpdf->useOnlyCoreFonts = true; $mpdf->useOnlyCoreFonts = true;
$mpdf->mirrorMargins = 0; // Use different Odd/Even headers and footers and mirror margins $mpdf->mirrorMargins = 0; // Use different Odd/Even headers and footers and mirror margins
if (is_array($headers_pdf)) { if (is_array($headers_pdf)) {
// preparing headers pdf // preparing headers pdf
$header = '<table width="100%" cellspacing="2" cellpadding="10" border="0" class="strong"> $header = '<table width="100%" cellspacing="1" cellpadding="5" border="0" class="strong">
<tr><td width="100%" style="text-align: left;" class="title" colspan="4"><h3>'.api_get_setting('Institution').'</h3></td></tr> <tr><td width="100%" style="text-align: left;" class="title" colspan="4"><img src="'.api_get_path(WEB_CSS_PATH).'chamilo_red/images/header-logo.png"></td></tr>
<tr><td width="100%" style="text-align: center;" class="title" colspan="4"><h1>'.$title_pdf.'</h1></td></tr> <tr><td width="100%" style="text-align: center;" class="title" colspan="4"><h1>'.$title_pdf.'</h1></td></tr>
<tr><td><strong>'.$headers_pdf[0][0].'</strong> </td><td> <strong>'.$headers_pdf[0][1].'</strong></td> <tr><td><strong>'.$headers_pdf[0][0].'</strong> </td><td> <strong>'.$headers_pdf[0][1].'</strong></td>
<td><strong>'.$headers_pdf[1][0].'</strong> </td><td> <strong>'.$headers_pdf[1][1].'</strong></td> <td><strong>'.$headers_pdf[1][0].'</strong> </td><td> <strong>'.$headers_pdf[1][1].'</strong></td>
@ -124,6 +124,8 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
} }
$footer .= '</table>'; $footer .= '</table>';
$footer .= '<div align="right" style="font-weight: bold;">{PAGENO}</div>';
// preparing content pdf // preparing content pdf
$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css'; $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
if (file_exists($css_file)) { if (file_exists($css_file)) {
@ -158,9 +160,10 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
foreach ($data_table as $data) { foreach ($data_table as $data) {
$content_table .= '<tr>'; $content_table .= '<tr>';
$content_table .= '<td>'.($item<10?'0'.$item:$item).'</td>'; $content_table .= '<td>'.($item<10?'0'.$item:$item).'</td>';
foreach ($data as $content) { foreach ($data as $key => $content) {
if (!empty($content)) { if (!empty($content)) {
$content_table .= '<td style="padding:4px" >'.$content.'</td>'; $key == 1 ? $align='align="left"':$align='align="center"';
$content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>';
} }
} }
$content_table .= '</tr>'; $content_table .= '</tr>';

@ -53,7 +53,7 @@ class ResultsDataGenerator
* 4 ['score'] : student's score * 4 ['score'] : student's score
* 5 ['display'] : custom score display (only if custom scoring enabled) * 5 ['display'] : custom score display (only if custom scoring enabled)
*/ */
public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) { public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false, $pdf=false) {
// do some checks on count, redefine if invalid value // do some checks on count, redefine if invalid value
if (!isset($count)) { if (!isset($count)) {
@ -69,11 +69,20 @@ class ResultsDataGenerator
$user = array(); $user = array();
$info = get_user_info_from_id($result->get_user_id()); $info = get_user_info_from_id($result->get_user_id());
$user['id'] = $result->get_user_id(); $user['id'] = $result->get_user_id();
if ($pdf == true){
$user['username'] = $info['username']; $user['username'] = $info['username'];
}
$user['result_id'] = $result->get_id(); $user['result_id'] = $result->get_id();
$user['lastname'] = $info['lastname']; $user['lastname'] = $info['lastname'];
$user['firstname'] = $info['firstname']; $user['firstname'] = $info['firstname'];
if ($pdf == true){
$user['score'] = $result->get_score();
} else {
$user['score'] = $this->get_score_display($result->get_score(),true, $ignore_score_color); $user['score'] = $this->get_score_display($result->get_score(),true, $ignore_score_color);
}
if ($pdf == true){
$user['scoreletter'] = $result->get_score();
}
if ($scoredisplay->is_custom()) if ($scoredisplay->is_custom())
$user['display'] = $this->get_score_display($result->get_score(),false, $ignore_score_color);; $user['display'] = $this->get_score_display($result->get_score(),false, $ignore_score_color);;
$table[] = $user; $table[] = $user;

Loading…
Cancel
Save