From 36417db478dcb2dd314b261bef33024f4a6f39ec Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 12 Apr 2012 13:06:15 +0200 Subject: [PATCH] Gradebook: Fixing printing to PDF bug --- .../lib/user_data_generator.class.php | 46 ++++++++----------- main/gradebook/user_stats.php | 16 +++---- 2 files changed, 25 insertions(+), 37 deletions(-) mode change 100755 => 100644 main/gradebook/lib/user_data_generator.class.php diff --git a/main/gradebook/lib/user_data_generator.class.php b/main/gradebook/lib/user_data_generator.class.php old mode 100755 new mode 100644 index 0abb461498..331a971f90 --- a/main/gradebook/lib/user_data_generator.class.php +++ b/main/gradebook/lib/user_data_generator.class.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 ''; + } } } diff --git a/main/gradebook/user_stats.php b/main/gradebook/user_stats.php index 88c15ad2ee..d9ac81f37e 100644 --- a/main/gradebook/user_stats.php +++ b/main/gradebook/user_stats.php @@ -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 = '
'; if (isset ($_GET['selectcat'])) { $interbreadcrumb[]= array ('url' => 'gradebook_flatview.php?selectcat=' . Security::remove_XSS($_GET['selectcat']), 'name' => get_lang('FlatView')); $actions.= '' . Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('FlatView'),'',ICON_SIZE_MEDIUM).''; - } + 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.= ' '.Display::return_icon('back.png', get_lang('BackToEvaluation'),'',ICON_SIZE_MEDIUM).''; } + $actions.= ' ' . Display::return_icon('pdf.png', get_lang('ExportPDF'),'',ICON_SIZE_MEDIUM).'';