Adding style changes in the PDF export see BT#4080

skala
Julio Montoya 14 years ago
parent 4f72175aee
commit 3f1dfef29f
  1. 2
      main/gradebook/gradebook_flatview.php
  2. 70
      main/gradebook/lib/flatview_data_generator.class.php
  3. 28
      main/gradebook/lib/gradebook_functions.inc.php

@ -105,6 +105,7 @@ if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
$params['only_total_category'] = true; $params['only_total_category'] = true;
$params['join_firstname_lastname'] = true; $params['join_firstname_lastname'] = true;
$params['show_official_code'] = true; $params['show_official_code'] = true;
$params['export_pdf'] = true;
if ($cat[0]->is_locked() == true || api_is_platform_admin()) { if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
Display :: set_header(null, false, false); Display :: set_header(null, false, false);
@ -125,6 +126,7 @@ if (isset($_GET['exportpdf'])) {
Display :: set_header(null, false, false); Display :: set_header(null, false, false);
$params['join_firstname_lastname'] = true; $params['join_firstname_lastname'] = true;
$params['show_usercode'] = true; $params['show_usercode'] = true;
$params['export_pdf'] = true;
export_pdf_flatview($cat, $users, $alleval, $alllinks, $params); export_pdf_flatview($cat, $users, $alleval, $alllinks, $params);
} else { } else {
Display :: display_header(get_lang('ExportPDF')); Display :: display_header(get_lang('ExportPDF'));

@ -60,9 +60,12 @@ class FlatViewDataGenerator
if (isset($this->params['show_official_code']) && $this->params['show_official_code']) { if (isset($this->params['show_official_code']) && $this->params['show_official_code']) {
$headers[] = get_lang('OfficialCode'); $headers[] = get_lang('OfficialCode');
} }
if (isset($this->params['join_firstname_lastname']) && $this->params['join_firstname_lastname']) { if (isset($this->params['join_firstname_lastname']) && $this->params['join_firstname_lastname']) {
$headers[] = get_lang('Name'); if (api_is_western_name_order()) {
$headers[] = get_lang('FirstnameAndLastname');
} else {
$headers[] = get_lang('LastnameAndFirstname');
}
} else { } else {
$headers[] = get_lang('LastName'); $headers[] = get_lang('LastName');
$headers[] = get_lang('FirstName'); $headers[] = get_lang('FirstName');
@ -233,18 +236,41 @@ class FlatViewDataGenerator
$use_grade_model = false; $use_grade_model = false;
} }
$export_to_pdf = false;
if (isset($this->params['export_pdf']) && $this->params['export_pdf']) {
$export_to_pdf = true;
}
foreach ($selected_users as $user) { foreach ($selected_users as $user) {
$row = array(); $row = array();
if ($export_to_pdf) {
$row['user_id'] = $user_id = $user[0]; //user id
} else {
$row[] = $user_id = $user[0]; //user id $row[] = $user_id = $user[0]; //user id
}
if (isset($this->params['show_official_code']) && $this->params['show_official_code']) { if (isset($this->params['show_official_code']) && $this->params['show_official_code']) {
if ($export_to_pdf) {
$row['official_code'] = $user[4]; //official code
} else {
$row[] = $user[4]; //official code $row[] = $user[4]; //official code
} }
}
if (isset($this->params['join_firstname_lastname']) && $this->params['join_firstname_lastname']) { if (isset($this->params['join_firstname_lastname']) && $this->params['join_firstname_lastname']) {
if ($export_to_pdf) {
$row['name'] = api_get_person_name($user[3], $user[2]); //last name
} else {
$row[] = api_get_person_name($user[3], $user[2]); //last name $row[] = api_get_person_name($user[3], $user[2]); //last name
}
} else {
if ($export_to_pdf) {
$row['lastname'] = $user[2]; //last name
$row['firstname'] = $user[3]; //first name
} else { } else {
$row[] = $user[2]; //last name $row[] = $user[2]; //last name
$row[] = $user[3]; //first name $row[] = $user[3]; //first name
}
} }
$item_value = 0; $item_value = 0;
@ -280,11 +306,19 @@ class FlatViewDataGenerator
if (!isset($this->params['only_total_category'])) { if (!isset($this->params['only_total_category'])) {
if (!$show_all) { if (!$show_all) {
if ($export_to_pdf) {
$row['score'] = $temp_score.' ';
} else {
$row[] = $temp_score.' '; $row[] = $temp_score.' ';
}
} else {
if ($export_to_pdf) {
$row['score'] = $temp_score;
} else { } else {
$row[] = $temp_score; $row[] = $temp_score;
} }
} }
}
$item_value_total +=$item_value; $item_value_total +=$item_value;
} }
if ($convert_using_the_global_weight) { if ($convert_using_the_global_weight) {
@ -309,34 +343,36 @@ class FlatViewDataGenerator
$item_value = $item_value*$item->get_weight(); $item_value = $item_value*$item->get_weight();
$item_value = $main_weight*$item_value/$item->get_weight(); $item_value = $main_weight*$item_value/$item->get_weight();
} }
//if ($debug) var_dump($item_value);
$item_total += $item->get_weight(); $item_total += $item->get_weight();
//SCORE_DIV, SCORE_PERCENT, SCORE_DIV_PERCENT, SCORE_AVERAGE
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); $temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
//$temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM); //$temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM);
if (!isset($this->params['only_total_category'])) { if (!isset($this->params['only_total_category'])) {
if (!$show_all) { if (!$show_all) {
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION, if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION,
LINK_LEARNPATH, LINK_FORUM_THREAD, LINK_ATTENDANCE,LINK_SURVEY))) { LINK_LEARNPATH, LINK_FORUM_THREAD, LINK_ATTENDANCE,LINK_SURVEY))) {
if (!empty($score[0])) { if (!empty($score[0])) {
if ($export_to_pdf) {
$row['score'] = $temp_score.' ';
} else {
$row[] = $temp_score.' '; $row[] = $temp_score.' ';
}
} else { } else {
$row[] = ''; $row['score'] = '';
} }
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
} else { } else {
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT); if ($export_to_pdf) {
//$row[] = $score[0]; $row['score'] = $temp_score.' ';
} else {
$row[] = $temp_score.' '; $row[] = $temp_score.' ';
} }
}
} else {
if ($export_to_pdf) {
$row['score'] = $temp_score;
} else { } else {
//$row[] = $scoredisplay->display_score($score, SCORE_DECIMAL);
$row[] = $temp_score; $row[] = $temp_score;
//$row[] = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); }
} }
} }
$item_value_total +=$item_value; $item_value_total +=$item_value;
@ -348,9 +384,17 @@ class FlatViewDataGenerator
$total_score = array($item_value_total, $item_total); $total_score = array($item_value_total, $item_total);
if (!$show_all) { if (!$show_all) {
if ($export_to_pdf) {
$row['total'] = $scoredisplay->display_score($total_score);
} else {
$row[] = $scoredisplay->display_score($total_score); $row[] = $scoredisplay->display_score($total_score);
}
} else {
if ($export_to_pdf) {
$row['total'] = $scoredisplay->display_score($total_score, SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS);
} else { } else {
$row[] = $scoredisplay->display_score($total_score, SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS); $row[] = $scoredisplay->display_score($total_score, SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS);
}
} }
unset($score); unset($score);
$data[] = $row; $data[] = $row;

@ -786,30 +786,21 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
// Choosing the right person name order according to the current language. // Choosing the right person name order according to the current language.
$firstname_position = 0;
$lastname_position = 1;
if (!isset($params['join_firstname_lastname'])) { if (!isset($params['join_firstname_lastname'])) {
//list($printable_data[0][$firstname_position], $printable_data[0][$lastname_position]) = array($printable_data[0][$lastname_position], $printable_data[0][$firstname_position]);
if (isset($params['show_usercode']) && $params['show_usercode'] ) {
$firstname_position ++;
$lastname_position ++;
}
list($printable_data[0][$firstname_position], $printable_data[0][$lastname_position]) = array($printable_data[0][$lastname_position], $printable_data[0][$firstname_position]);
if ($has_data) { if ($has_data) {
foreach ($printable_data[1] as &$printable_data_row) { foreach ($printable_data[1] as &$printable_data_row) {
list($printable_data_row[$firstname_position], $printable_data_row[$lastname_position]) = array($printable_data_row[$lastname_position], $printable_data_row[$firstname_position]); list($printable_data_row['firstname'], $printable_data_row['lastname']) = array($printable_data_row['lastname'], $printable_data_row['firstname']);
} }
} }
} }
} }
$table = new HTML_Table(array('class' => 'data_table')); $table = new HTML_Table(array('class' => 'data_table'));
$row = 0; $row = 0;
$column = 0; $column = 0;
$table->setHeaderContents($row, $column, '#');$column++; $table->setHeaderContents($row, $column, get_lang('NumberAbbreviation'));$column++;
foreach ($printable_data[0] as $printable_data_cell) { foreach ($printable_data[0] as $printable_data_cell) {
$table->setHeaderContents($row, $column, $printable_data_cell); $table->setHeaderContents($row, $column, $printable_data_cell);
$column++; $column++;
@ -823,9 +814,17 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$table->updateCellAttributes($row, $column, 'align="center"'); $table->updateCellAttributes($row, $column, 'align="center"');
$column++; $counter++; $column++; $counter++;
foreach ($printable_data_row as &$printable_data_cell) { foreach ($printable_data_row as $key => &$printable_data_cell) {
$attributes = array();
$attributes['align'] = 'center';
if (in_array($key, array('name'))) {
$attributes['align'] = 'left';
}
if (in_array($key, array('total'))) {
$attributes['style'] = 'font-weight:bold';
}
$table->setCellContents($row, $column, $printable_data_cell); $table->setCellContents($row, $column, $printable_data_cell);
$table->updateCellAttributes($row, $column, 'align="center"'); $table->updateCellAttributes($row, $column, $attributes);
$column++; $column++;
} }
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true); $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
@ -837,6 +836,7 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"'); $table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"');
} }
Display::$global_template->assign('pdf_table', $table->toHtml()); Display::$global_template->assign('pdf_table', $table->toHtml());
unset($printable_data); unset($printable_data);

Loading…
Cancel
Save