Adding more fixes to the PDF export see BT#4080

skala
Julio Montoya 14 years ago
parent b98d6482f2
commit a9a93ac9da
  1. 3
      main/gradebook/gradebook_flatview.php
  2. 57
      main/gradebook/lib/flatview_data_generator.class.php
  3. 80
      main/gradebook/lib/gradebook_functions.inc.php
  4. 8
      main/lang/spanish/gradebook.inc.php
  5. 1
      main/lang/spanish/trad4all.inc.php

@ -127,6 +127,7 @@ if (isset($_GET['exportpdf'])) {
$params['join_firstname_lastname'] = true; $params['join_firstname_lastname'] = true;
$params['show_usercode'] = true; $params['show_usercode'] = true;
$params['export_pdf'] = true; $params['export_pdf'] = true;
$params['only_total_category'] = false;
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'));
@ -134,7 +135,7 @@ if (isset($_GET['exportpdf'])) {
} }
if (isset ($_GET['print'])) { if (isset ($_GET['print'])) {
$printable_data = get_printable_data ($cat[0], $users, $alleval, $alllinks); $printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks);
echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name()); echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name());
exit; exit;
} }

@ -12,7 +12,6 @@
*/ */
class FlatViewDataGenerator class FlatViewDataGenerator
{ {
// Sorting types constants // Sorting types constants
const FVDG_SORT_LASTNAME = 1; const FVDG_SORT_LASTNAME = 1;
const FVDG_SORT_FIRSTNAME = 2; const FVDG_SORT_FIRSTNAME = 2;
@ -66,9 +65,14 @@ class FlatViewDataGenerator
} else { } else {
$headers[] = get_lang('LastnameAndFirstname'); $headers[] = get_lang('LastnameAndFirstname');
} }
} else {
if (api_is_western_name_order()) {
$headers[] = get_lang('FirstName');
$headers[] = get_lang('LastName');
} else { } else {
$headers[] = get_lang('LastName'); $headers[] = get_lang('LastName');
$headers[] = get_lang('FirstName'); $headers[] = get_lang('FirstName');
}
} }
if (!isset($items_count)) { if (!isset($items_count)) {
$items_count = count($this->evals_links) - $items_start; $items_count = count($this->evals_links) - $items_start;
@ -110,7 +114,11 @@ class FlatViewDataGenerator
foreach ($allcat as $sub_cat) { foreach ($allcat as $sub_cat) {
$sub_cat_weight = 100*$sub_cat->get_weight()/$main_weight; $sub_cat_weight = 100*$sub_cat->get_weight()/$main_weight;
$headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).' '.$sub_cat_weight.' % '; $add_weight = " $sub_cat_weight %";
if (isset($this->params['export_pdf']) && $this->params['export_pdf']) {
$add_weight = null;
}
$headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).$add_weight;
} }
} else { } else {
if (!isset($this->params['only_total_category'])) { if (!isset($this->params['only_total_category'])) {
@ -122,7 +130,7 @@ class FlatViewDataGenerator
} }
} }
} }
$headers[] = get_lang('GradebookQualificationTotal').' 100%'; $headers[] = api_strtoupper(get_lang('GradebookQualificationTotal'));
return $headers; return $headers;
} }
@ -178,12 +186,14 @@ class FlatViewDataGenerator
if ($items_count < 0) { if ($items_count < 0) {
$items_count = 0; $items_count = 0;
} }
// copy users to a new array that we will sort // copy users to a new array that we will sort
// TODO - needed ? // TODO - needed ?
$usertable = array (); $usertable = array ();
foreach ($this->users as $user) { foreach ($this->users as $user) {
$usertable[] = $user; $usertable[] = $user;
} }
// sort users array // sort users array
if ($users_sorting & self :: FVDG_SORT_LASTNAME) { if ($users_sorting & self :: FVDG_SORT_LASTNAME) {
usort($usertable, array ('FlatViewDataGenerator','sort_by_last_name')); usort($usertable, array ('FlatViewDataGenerator','sort_by_last_name'));
@ -265,12 +275,22 @@ class FlatViewDataGenerator
} }
} else { } else {
if ($export_to_pdf) { if ($export_to_pdf) {
$row['lastname'] = $user[2]; //last name if (api_is_western_name_order()) {
$row['firstname'] = $user[3]; //first name $row['firstname'] = $user[3];
$row['lastname'] = $user[2];
} else {
$row['lastname'] = $user[2];
$row['firstname'] = $user[3];
}
} else {
if (api_is_western_name_order()) {
$row[] = $user[3]; //first name
$row[] = $user[2]; //last 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;
@ -304,21 +324,13 @@ class FlatViewDataGenerator
//$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']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) {
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) {
@ -347,34 +359,22 @@ class FlatViewDataGenerator
$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']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) {
if (!$show_all) { if (!$show_all) {
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['score'] = ''; $row[] = '';
} }
} else {
if ($export_to_pdf) {
$row['score'] = $temp_score.' ';
} else { } 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;
} }
$item_total = $main_weight; $item_total = $main_weight;
@ -397,6 +397,7 @@ class FlatViewDataGenerator
} }
} }
unset($score); unset($score);
//var_dump($row);exit;
$data[] = $row; $data[] = $row;
} }
return $data; return $data;

@ -30,16 +30,6 @@ require_once api_get_path(LIBRARY_PATH).'grade_model.lib.php';
* @return boolean True on success, false on failure * @return boolean True on success, false on failure
*/ */
function add_resource_to_course_gradebook($category_id, $course_code, $resource_type, $resource_id, $resource_name='', $weight=0, $max=0, $resource_description='', $visible=0, $session_id = 0) { function add_resource_to_course_gradebook($category_id, $course_code, $resource_type, $resource_id, $resource_name='', $weight=0, $max=0, $resource_description='', $visible=0, $session_id = 0) {
/* See defines in lib/be/linkfactory.class.php
define('LINK_EXERCISE',1);
define('LINK_DROPBOX',2);
define('LINK_STUDENTPUBLICATION',3);
define('LINK_LEARNPATH',4);
define('LINK_FORUM_THREAD',5),
define('LINK_WORK',6);
*/
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be.inc.php';
$link = LinkFactory :: create($resource_type); $link = LinkFactory :: create($resource_type);
$link->set_user_id(api_get_user_id()); $link->set_user_id(api_get_user_id());
$link->set_course_code($course_code); $link->set_course_code($course_code);
@ -72,17 +62,11 @@ function add_resource_to_course_gradebook($category_id, $course_code, $resource_
} }
function block_students() { function block_students() {
//if (!api_is_allowed_to_create_course()) {
if (!api_is_allowed_to_edit()) { if (!api_is_allowed_to_edit()) {
api_not_allowed(); api_not_allowed();
} }
} }
/**
* Returns the info header for the user result page
* @param $userid
*/
/** /**
* Returns the course name from a given code * Returns the course name from a given code
* @param string $code * @param string $code
@ -95,6 +79,7 @@ function get_course_name_from_code($code) {
return $col['title']; return $col['title'];
} }
} }
/** /**
* Builds an img tag for a gradebook item * Builds an img tag for a gradebook item
* @param string $type value returned by a gradebookitem's get_icon_name() * @param string $type value returned by a gradebookitem's get_icon_name()
@ -157,7 +142,6 @@ function get_icon_file_name ($type) {
return api_get_path(WEB_IMG_PATH).$icon; return api_get_path(WEB_IMG_PATH).$icon;
} }
/** /**
* Builds the course or platform admin icons to edit a category * Builds the course or platform admin icons to edit a category
* @param object $cat category object * @param object $cat category object
@ -211,11 +195,6 @@ function build_edit_icons_cat($cat, $selectcat) {
} else { } else {
//$modify_icons .= '&nbsp;<img src="../img/deplacer_fichier_na.gif" border="0" title="' . get_lang('Move') . '" alt="" />'; //$modify_icons .= '&nbsp;<img src="../img/deplacer_fichier_na.gif" border="0" title="' . get_lang('Move') . '" alt="" />';
} }
if (empty($grade_model_id) || $grade_model_id == -1) {
/*$modify_icons .= ' <a href="gradebook_edit_all.php?id_session='.api_get_session_id().'&amp;cidReq='.$cat->get_course_code().'&selectcat=' . $cat->get_id() . '"> '.
Display::return_icon('percentage.png', get_lang('EditAllWeights'),'',ICON_SIZE_SMALL).' </a>'; */
}
if ($cat->is_locked() && !api_is_platform_admin()) { if ($cat->is_locked() && !api_is_platform_admin()) {
$modify_icons .= Display::return_icon('delete_na.png', get_lang('DeleteAll'),'',ICON_SIZE_SMALL); $modify_icons .= Display::return_icon('delete_na.png', get_lang('DeleteAll'),'',ICON_SIZE_SMALL);
} else { } else {
@ -372,7 +351,6 @@ function get_resource_from_course_gradebook($link_id) {
*/ */
function remove_resource_from_course_gradebook($link_id) { function remove_resource_from_course_gradebook($link_id) {
if ( empty($link_id) ) { return false; } if ( empty($link_id) ) { return false; }
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be.inc.php';
// TODO find the corresponding category (the first one for this course, ordered by ID) // TODO find the corresponding category (the first one for this course, ordered by ID)
$l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = "DELETE FROM $l WHERE id = ".(int)$link_id; $sql = "DELETE FROM $l WHERE id = ".(int)$link_id;
@ -410,7 +388,6 @@ function get_course_id_by_link_id($id_link) {
} }
function get_table_type_course($type) { function get_table_type_course($type) {
global $_configuration;
global $table_evaluated; global $table_evaluated;
return Database::get_course_table($table_evaluated[$type][0]); return Database::get_course_table($table_evaluated[$type][0]);
} }
@ -699,9 +676,11 @@ function load_gradebook_select_in_tool($form) {
} }
} }
/**
* PDF report creation
*/
function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array()) { function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array()) {
// Beginning of PDF report creation //Getting data
$printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks, $params); $printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks, $params);
// Reading report's CSS // Reading report's CSS
@ -709,7 +688,6 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$css = file_exists($css_file) ? @file_get_contents($css_file) : ''; $css = file_exists($css_file) ? @file_get_contents($css_file) : '';
// HTML report creation first // HTML report creation first
$time = time();
$course_code = trim($cat[0]->get_course_code()); $course_code = trim($cat[0]->get_course_code());
$organization = api_get_setting('Institution'); $organization = api_get_setting('Institution');
@ -758,16 +736,19 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
if ($use_grade_model) { if ($use_grade_model) {
if ($parent_id == 0) { if ($parent_id == 0) {
$title = '<h2 align="center">'.get_lang('FlatView').'</h2>'; $title = '<h2 align="center">'.api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed').'</h2>';
} else { } else {
$title = '<h2 align="center">'.$cat[0]->get_description().' - ('.$cat[0]->get_name().') </h2>'; $title = '<h2 align="center"> '.api_strtoupper(get_lang('Average')).'<br />'.$cat[0]->get_description().' - ('.$cat[0]->get_name().')</h2>';
} }
} else { } else {
$title = '<h2 align="center">'.get_lang('FlatView').'</h2>'; if ($parent_id == 0) {
$title = '<h2 align="center">'.api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed').'</h2>';
} else {
$title = '<h2 align="center">'.api_strtoupper(get_lang('Average')).'</h2>';
}
} }
Display::$global_template->assign('pdf_title', $title); Display::$global_template->assign('pdf_title', $title);
//Showing only the current teacher/admin instead the all teacherlist name see BT#4080 //Showing only the current teacher/admin instead the all teacherlist name see BT#4080
//$teacher_list = CourseManager::get_teacher_list_from_course_code_to_string($course_code); //$teacher_list = CourseManager::get_teacher_list_from_course_code_to_string($course_code);
$user_info = api_get_user_info(); $user_info = api_get_user_info();
@ -784,45 +765,41 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$columns = count($printable_data[0]); $columns = count($printable_data[0]);
$has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0; $has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0;
if (api_is_western_name_order()) {
// Choosing the right person name order according to the current language.
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 ($has_data) {
foreach ($printable_data[1] as &$printable_data_row) {
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, get_lang('NumberAbbreviation'));$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) {
$printable_data_cell = strip_tags($printable_data_cell);
$table->setHeaderContents($row, $column, $printable_data_cell); $table->setHeaderContents($row, $column, $printable_data_cell);
$column++; $column++;
} }
$row++; $row++;
if ($has_data) { if ($has_data) {
$counter = 1; $counter = 1;
//var_dump($printable_data);exit;
foreach ($printable_data[1] as &$printable_data_row) { foreach ($printable_data[1] as &$printable_data_row) {
$column = 0; $column = 0;
$table->setCellContents($row, $column, $counter); $table->setCellContents($row, $column, $counter);
$table->updateCellAttributes($row, $column, 'align="center"'); $table->updateCellAttributes($row, $column, 'align="center"');
$column++; $counter++; $column++;
$counter++;
foreach ($printable_data_row as $key => &$printable_data_cell) { foreach ($printable_data_row as $key => &$printable_data_cell) {
$attributes = array(); $attributes = array();
$attributes['align'] = 'center'; $attributes['align'] = 'center';
if (in_array($key, array('name'))) { $attributes['style'] = null;
if ($key === 'name') {
$attributes['align'] = 'left'; $attributes['align'] = 'left';
} }
if (in_array($key, array('total'))) { if ($key === 'total') {
$attributes['style'] = 'font-weight:bold'; $attributes['style'] = 'font-weight:bold';
} }
//var_dump($key, $printable_data_cell, $attributes);
$table->setCellContents($row, $column, $printable_data_cell); $table->setCellContents($row, $column, $printable_data_cell);
$table->updateCellAttributes($row, $column, $attributes); $table->updateCellAttributes($row, $column, $attributes);
$column++; $column++;
@ -830,13 +807,13 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true); $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++; $row++;
} }
//exit;
} else { } else {
$column = 0; $column = 0;
$table->setCellContents($row, $column, get_lang('NoResults')); $table->setCellContents($row, $column, get_lang('NoResults'));
$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);
@ -854,11 +831,12 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$pdf = new PDF($page_format, $params['orientation']); $pdf = new PDF($page_format, $params['orientation']);
// Sending the created PDF report to the client // Sending the created PDF report to the client
$file_name = date('YmdHi_', $time); $file_name = null;
if (!empty($course_code)) { if (!empty($course_code)) {
$file_name .= $course_code.'_'; $file_name .= $course_code;
} }
$file_name .= get_lang('FlatView').'.pdf'; $file_name = api_get_utc_datetime();
$file_name = get_lang('FlatView').'_'.$file_name.'.pdf';
$pdf->content_to_pdf($html, $css, $file_name, api_get_course_id()); $pdf->content_to_pdf($html, $css, $file_name, api_get_course_id());
exit; exit;
} }

@ -80,7 +80,7 @@ $LinkDeleted = "El componente de evaluación ha sido eliminado";
$EditEvaluation = "Modificar componente de evaluación"; $EditEvaluation = "Modificar componente de evaluación";
$DeleteResult = "Eliminar resultados"; $DeleteResult = "Eliminar resultados";
$Display = "Nivel"; $Display = "Nivel";
$Average = "Media"; $Average = "Promedio";
$ViewStatistics = "Ver estadísticas"; $ViewStatistics = "Ver estadísticas";
$ResultAdded = "Resultado añadido"; $ResultAdded = "Resultado añadido";
$EvaluationStatistics = "Estadísticas de evaluación"; $EvaluationStatistics = "Estadísticas de evaluación";
@ -103,9 +103,9 @@ $OverMax = "El valor que ha intentado guardar es superior al límite máximo est
$MoreInfo = "Más información"; $MoreInfo = "Más información";
$ResultsPerUser = "Resultados por usuario"; $ResultsPerUser = "Resultados por usuario";
$TotalUser = "Total por usuario"; $TotalUser = "Total por usuario";
$AverageTotal = "Media total"; $AverageTotal = "Promedio total";
$Evaluation = "Componente de evaluación"; $Evaluation = "Componente de evaluación";
$EvaluationAverage = "Media de la evaluación"; $EvaluationAverage = "Promedio de la evaluación";
$EditCategory = "Editar sus propiedades"; $EditCategory = "Editar sus propiedades";
$EditAllWeights = "Editar ponderaciones"; $EditAllWeights = "Editar ponderaciones";
$GradebookQualificationTotal = "Total"; $GradebookQualificationTotal = "Total";
@ -133,7 +133,7 @@ $NoResultsAvailable = "No hay resultados disponibles";
$CannotChangeTheMaxNote = "No se puede cambiar la nota máxima"; $CannotChangeTheMaxNote = "No se puede cambiar la nota máxima";
$GradebookWeightUpdated = "Peso(s) modificado(s) correctamente"; $GradebookWeightUpdated = "Peso(s) modificado(s) correctamente";
$ChooseItem = "Seleccione un item"; $ChooseItem = "Seleccione un item";
$AverageResultsVsResource = "Media de resultados por componente de evaluación"; $AverageResultsVsResource = "Promedio de resultados por componente de evaluación";
$ToViewGraphScoreRuleMustBeEnabled = "Para ver el gráfico las reglas de puntuación deben haberse definido"; $ToViewGraphScoreRuleMustBeEnabled = "Para ver el gráfico las reglas de puntuación deben haberse definido";
$GradebookPreviousWeight = "Ponderación previa"; $GradebookPreviousWeight = "Ponderación previa";
$AddAssessment = "Crear"; $AddAssessment = "Crear";

@ -1232,4 +1232,5 @@ $CourseList = "Lista de cursos";
$NumberAbbreviation = "N°"; $NumberAbbreviation = "N°";
$FirstnameAndLastname = "Nombres y Apellidos"; $FirstnameAndLastname = "Nombres y Apellidos";
$LastnameAndFirstname = "Apellidos y Nombres"; $LastnameAndFirstname = "Apellidos y Nombres";
$Detailed = "Detallado";
?> ?>
Loading…
Cancel
Save