Gradebook: Fixing printing to PDF bug

skala
Julio Montoya 14 years ago
parent 1d8a981ec2
commit 36417db478
  1. 46
      main/gradebook/lib/user_data_generator.class.php
  2. 16
      main/gradebook/user_stats.php

@ -25,7 +25,6 @@ class UserDataGenerator
const UDG_SORT_ASC = 128;
const UDG_SORT_DESC = 256;
private $items;
private $userid;
@ -34,7 +33,6 @@ class UserDataGenerator
private $scorecache;
private $avgcache;
function UserDataGenerator($userid, $evals = array(), $links = array()) {
$this->userid = $userid;
$evals_filtered = array();
@ -59,15 +57,12 @@ class UserDataGenerator
}
$this->items = array_merge ($evals_filtered, $links);
$this->coursecodecache = array();
$this->categorycache = array();
$this->scorecache = null;
$this->avgcache = null;
}
/**
* Get total number of items (rows)
*/
@ -75,8 +70,6 @@ class UserDataGenerator
return count($this->items);
}
/**
* Get actual array data
* @return array 2-dimensional array - each array contains the elements:
@ -109,9 +102,8 @@ class UserDataGenerator
usort($allitems, array('UserDataGenerator', 'sort_by_category'));
} elseif ($sorting & self :: UDG_SORT_AVERAGE) {
// if user sorts on average scores, first calculate them and cache them
foreach ($allitems as $item) {
$this->avgcache[$item->get_item_type() . $item->get_id()]
= $item->calc_score();
foreach ($allitems as $item) {
$this->avgcache[$item->get_item_type() . $item->get_id()]= $item->calc_score();
}
usort($allitems, array('UserDataGenerator', 'sort_by_average'));
} elseif ($sorting & self :: UDG_SORT_SCORE) {
@ -159,13 +151,11 @@ class UserDataGenerator
$row[] = $this->build_mask_column ($item, $ignore_score_color);
$data[] = $row;
}
return $data;
}
// Sort functions
// Make sure to only use functions as defined in the GradebookItem interface !
// Sort functions
// Make sure to only use functions as defined in the GradebookItem interface !
function sort_by_type($item1, $item2) {
if ($item1->get_item_type() == $item2->get_item_type()) {
@ -233,20 +223,23 @@ class UserDataGenerator
private function build_category_name ($item) {
$cat = $this->get_category_cached($item->get_category_id());
return $this->get_category_name_to_display($cat);
}
private function build_average_column ($item, $ignore_score_color) {
if (isset($this->avgcache)) {
$avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()];
$avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()];
} else {
$avgscore = $item->calc_score();
}
$scoredisplay = ScoreDisplay :: instance();
$displaytype = SCORE_AVERAGE;
if ($ignore_score_color)
/*if ($ignore_score_color)
$displaytype |= SCORE_IGNORE_SPLIT;
*/
return $scoredisplay->display_score($avgscore, $displaytype);
}
@ -297,17 +290,14 @@ class UserDataGenerator
}
private function get_category_name_to_display ($cat) {
if (isset($cat)){
if ($cat->get_parent_id() == '0' || $cat->get_parent_id() == null){
return '';
} else {
return $cat->get_name();
}
} else {
return '';
}
if (isset($cat)) {
if ($cat->get_parent_id() == '0' || $cat->get_parent_id() == null){
return '';
} else {
return $cat->get_name();
}
} else {
return '';
}
}
}

@ -43,15 +43,12 @@ if ($_GET['selectcat'] != null) {
}
$user_table= new UserTable($my_user_id, $allevals, $alllinks, $addparams);
if (isset ($_GET['exportpdf'])) {
$datagen = new UserDataGenerator($my_user_id, $allevals,$alllinks);
$data_array = $datagen->get_data(UserDataGenerator :: UDG_SORT_NAME, 0, null, true);
if (isset ($_GET['exportpdf'])) {
$datagen = new UserDataGenerator($my_user_id, $allevals, $alllinks);
$data_array = $datagen->get_data(UserDataGenerator :: UDG_SORT_NAME, 0, null, true);
$newarray = array ();
$displayscore = Scoredisplay :: instance();
$newitem = array ();
foreach ($data_array as $data) {
$displayscore = Scoredisplay :: instance();
foreach ($data_array as $data) {
$newarray[] = array_slice($data, 1);
}
$userinfo = get_user_info_from_id($my_user_id);
@ -94,8 +91,8 @@ $actions = '<div class="actions">';
if (isset ($_GET['selectcat'])) {
$interbreadcrumb[]= array ('url' => 'gradebook_flatview.php?selectcat=' . Security::remove_XSS($_GET['selectcat']), 'name' => get_lang('FlatView'));
$actions.= '<a href=gradebook_flatview.php?selectcat=' .Security::remove_XSS($_GET['selectcat']) . '>' . Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('FlatView'),'',ICON_SIZE_MEDIUM).'</a>';
}
if (isset ($_GET['selecteval'])) {
$interbreadcrumb[]= array (
'url' => 'gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']),
@ -104,6 +101,7 @@ if (isset ($_GET['selecteval'])) {
$actions.= '<a href=gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '>
'.Display::return_icon('back.png', get_lang('BackToEvaluation'),'',ICON_SIZE_MEDIUM).'</a>';
}
$actions.= '<a href="' . api_get_self() . '?exportpdf=&userid='.Security::remove_XSS($_GET['userid']).'&selectcat=' . $category[0]->get_id() . '" target="_blank">
' . Display::return_icon('pdf.png', get_lang('ExportPDF'),'',ICON_SIZE_MEDIUM).'</a>';

Loading…
Cancel
Save