Adding PDF export (wokrs but not finished yet) see BT#4080

skala
Julio Montoya 13 years ago
parent 241a7d265c
commit 9fdf61cc7b
  1. 11
      main/gradebook/gradebook_flatview.php
  2. 8
      main/gradebook/index.php
  3. 104
      main/gradebook/lib/flatview_data_generator.class.php
  4. 27
      main/gradebook/lib/gradebook_functions.inc.php

@ -99,13 +99,18 @@ $flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $
$parameters=array('selectcat'=>intval($_GET['selectcat']));
$flatviewtable->set_additional_parameters($parameters);
if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
$params = array();
$params['only_total_category'] = true;
export_pdf_flatview($cat, $users, $alleval, $alllinks, $params);
}
if (isset($_GET['exportpdf'])) {
$interbreadcrumb[] = array (
'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
'name' => get_lang('FlatView')
);
$export_pdf_form = new DataForm(DataForm::TYPE_EXPORT_PDF, 'export_pdf_form', null, api_get_self().'?exportpdf=&offset='.intval($_GET['offset']).'&selectcat='.intval($_GET['selectcat']), '_blank', '');
$export_pdf_form = new DataForm(DataForm::TYPE_EXPORT_PDF, 'export_pdf_form', null, api_get_self().'?exportpdf=&offset='.intval($_GET['offset']).'&selectcat='.intval($_GET['selectcat']), '_blank', '');
if ($export_pdf_form->validate()) {
$params = $export_pdf_form->exportValues();
@ -116,7 +121,7 @@ if (isset($_GET['exportpdf'])) {
}
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());
exit;
}

@ -57,6 +57,14 @@ function lock_confirmation() {
}
}
function unlock_confirmation() {
if (confirm("' . get_lang('ConfirmToUnlockElement') . '?")) {
return true;
} else {
return false;
}
}
$(document).ready(function() {

@ -23,18 +23,18 @@ class FlatViewDataGenerator
private $evals;
private $links;
private $evals_links;
public $params;
public $category = array();
/**
* Constructor
*/
public function FlatViewDataGenerator ($users= array (), $evals= array (), $links= array ()) {
public function FlatViewDataGenerator ($users = array(), $evals = array(), $links = array(), $params = array()) {
$this->users = (isset($users) ? $users : array());
$this->evals = (isset($evals) ? $evals : array());
$this->links = (isset($links) ? $links : array());
$this->evals_links = array_merge($this->evals, $this->links);
$this->params = $params;
}
/**
@ -89,17 +89,16 @@ class FlatViewDataGenerator
foreach ($allcat as $sub_cat) {
$headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).' '.$sub_cat->get_weight().' % ';
}
} else {
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$item = $this->evals_links[$count + $items_start];
} else {
if (!isset($this->params['only_total_category'])) {
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$item = $this->evals_links[$count + $items_start];
//$headers[] = $item->get_name().' <br /> '.get_lang('Max').' '.$this->get_max_result_by_link($count + $items_start).' ';
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
//$headers[] = $item->get_name().' <br /> '.get_lang('Max').' '.$this->get_max_result_by_link($count + $items_start).' ';
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$weight = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight() *100, 2);
$headers[] = $item->get_name().' '.$weight.' % ';
if ($show_detail) {
//$headers[] = $item->get_name().' ('.get_lang('Detail').')';
$weight = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight() *100, 2);
$headers[] = $item->get_name().' '.$weight.' % ';
}
}
}
@ -107,17 +106,11 @@ class FlatViewDataGenerator
return $headers;
}
function get_max_result_by_link($id) {
$usertable = array();
$items_count = count ($this->evals) + count ($this->links);
$item_value = 0;
$item_total = 0;
function get_max_result_by_link($id) {
$max = 0;
foreach ($this->users as $user) {
$item = $this->evals_links [$id];
$score = $item->calc_score($user[0]);
$divide=( ($score[1])==0 ) ? 1 : $score[1];
//$item_value = round($score[0]/$divide*$item->get_weight(),2);
if ($score[0] > $max) {
$max = $score[0];
}
@ -160,7 +153,7 @@ class FlatViewDataGenerator
}
if ($users_count < 0) {
$users_count = 0;
}
}
if (!isset($items_count)) {
$items_count = count ($this->evals) + count ($this->links) - $items_start;
}
@ -186,8 +179,8 @@ class FlatViewDataGenerator
// select the requested users
$selected_users = array_slice($usertable, $users_start, $users_count);
// generate actual data array
$scoredisplay = ScoreDisplay :: instance();
$data = array ();
@ -222,7 +215,7 @@ class FlatViewDataGenerator
if (empty($grade_model_id) || $grade_model_id == -1) {
$use_grade_model = false;
}
foreach ($selected_users as $user) {
$row = array ();
$row[] = $user_id = $user[0]; //user id
@ -258,12 +251,13 @@ class FlatViewDataGenerator
}
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
if (!$show_all) {
$row[] = $temp_score.' ';
} else {
$row[] = $temp_score;
}
if (!isset($this->params['only_total_category'])) {
if (!$show_all) {
$row[] = $temp_score.' ';
} else {
$row[] = $temp_score;
}
}
$item_value_total +=$item_value;
}
if ($convert_using_the_global_weight) {
@ -271,13 +265,10 @@ class FlatViewDataGenerator
}
} else {
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$item = $this->evals_links[$count + $items_start];
$item = $this->evals_links[$count + $items_start];
$score = $item->calc_score($user_id);
$debug = false;
if ($user_id == 11) {
$debug = true;
}
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
//sub cat weight
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
@ -287,10 +278,7 @@ class FlatViewDataGenerator
if ($this->category->get_parent_id() == 0 ) {
$item_value = $item_value;
$item_value =round($score[0]/$divide*$item->get_weight(),2);
} else {
// if ($debug) var_dump($item_value);
//$percentage = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(), 2);
//if ($debug) var_dump($item->get_weight().' '.$item_value .' -'.$sub_cat_percentage);
} else {
$item_value = $item_value*$item->get_weight();
$item_value = $main_weight*$item_value/$item->get_weight();
}
@ -299,28 +287,28 @@ class FlatViewDataGenerator
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
//if ($debug) var_dump($temp_score);
if (!$show_all) {
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION,
LINK_LEARNPATH, LINK_FORUM_THREAD, LINK_ATTENDANCE,LINK_SURVEY))) {
if (!empty($score[0])) {
$row[] = $temp_score.' ';
if (!isset($this->params['only_total_category'])) {
if (!$show_all) {
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION,
LINK_LEARNPATH, LINK_FORUM_THREAD, LINK_ATTENDANCE,LINK_SURVEY))) {
if (!empty($score[0])) {
$row[] = $temp_score.' ';
} else {
$row[] = '';
}
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
} else {
$row[] = '';
}
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
//$row[] = $score[0];
$row[] = $temp_score.' ';
}
} else {
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
//$row[] = $score[0];
$row[] = $temp_score.' ';
}
} else {
//$row[] = $scoredisplay->display_score($score, SCORE_DECIMAL);
$row[] = $temp_score;
//$row[] = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
}
//$row[] = $scoredisplay->display_score($score, SCORE_DECIMAL);
$row[] = $temp_score;
//$row[] = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
}
}
$item_value_total +=$item_value;
}
$item_total = $main_weight;

@ -179,7 +179,7 @@ function build_edit_icons_cat($cat, $selectcat) {
if (api_get_setting('gradebook_locking_enabled') == 'true') {
if ($cat->is_locked()) {
if (api_is_platform_admin()) {
$modify_icons .= '&nbsp;<a onclick="javascrip:lock_confirmation()" href="' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=unlock">'.Display::return_icon('unlock.png', get_lang('Unlock'),'',ICON_SIZE_SMALL).'</a>';
$modify_icons .= '&nbsp;<a onclick="javascrip:unlock_confirmation()" href="' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=unlock">'.Display::return_icon('unlock.png', get_lang('Unlock'),'',ICON_SIZE_SMALL).'</a>';
} else {
$modify_icons .= '&nbsp;<a href="#">'.Display::return_icon('unlock_na.png', get_lang('GradebookLockedAlert'),'',ICON_SIZE_SMALL).'</a>';
}
@ -189,7 +189,7 @@ function build_edit_icons_cat($cat, $selectcat) {
}
//PDF
$modify_icons .= '&nbsp;<a href="gradebook_flat_view.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_SMALL).'</a>';
$modify_icons .= '&nbsp;<a href="gradebook_flatview.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_SMALL).'</a>';
if (empty($grade_model_id) || $grade_model_id == -1) {
if ($cat->is_locked() && !api_is_platform_admin()) {
@ -416,8 +416,9 @@ function get_table_type_course($type) {
return Database::get_course_table($table_evaluated[$type][0]);
}
function get_printable_data($cat, $users, $alleval, $alllinks) {
$datagen = new FlatViewDataGenerator ($users, $alleval, $alllinks);
function get_printable_data($cat, $users, $alleval, $alllinks, $params) {
$datagen = new FlatViewDataGenerator ($users, $alleval, $alllinks, $params);
$offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
$offset = intval($offset);
@ -426,7 +427,7 @@ function get_printable_data($cat, $users, $alleval, $alllinks) {
$count = (($offset + 10) > $datagen->get_total_items_count()) ? ($datagen->get_total_items_count() - $offset) : LIMIT;
$header_names = $datagen->get_header_names($offset, $count, true);
$data_array = $datagen->get_data(FlatViewDataGenerator :: FVDG_SORT_LASTNAME, 0, null, $offset, $count, true,true);
$data_array = $datagen->get_data(FlatViewDataGenerator :: FVDG_SORT_LASTNAME, 0, null, $offset, $count, true, true);
$newarray = array();
foreach ($data_array as $data) {
@ -693,7 +694,7 @@ function load_gradebook_select_in_tool($form) {
function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array()) {
// Beginning of PDF report creation
$printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks);
$printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks, $params);
// Reading report's CSS
$css_file = api_get_path(SYS_CODE_PATH).'gradebook/print.css';
@ -731,7 +732,19 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
}
}
$html .= '<h2 align="center">'.get_lang('FlatView').'</h2>';
$grade_model_id = $cat[0]->get_grade_model_id();
$use_grade_model = true;
if (empty($grade_model_id) || $grade_model_id == -1) {
$use_grade_model = false;
}
//var_dump($use_grade_model);exit;
if ($use_grade_model) {
$html .= '<h2 align="center">'.get_lang('FlatView').'</h2>';
} else {
$html .= '<h2 align="center">'.get_lang('FlatView').'</h2>';
}
$html .= '<table align="center" width="100%"><tr><td valign="top">';
$html .= '<table align="left" width="33%">';

Loading…
Cancel
Save