Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 45f4f52

Browse files
vincentselsdregad
authored andcommittedJan 10, 2012
Fix #13715: Export plugin columns to CSV and Excel
Prior to this, trying to include plugin columns in a CSV or Excel export would generate a file containing errors: * CSV: "Fatal error: Call to undefined function csv_format_XXX() in csv_export.php on line 116" * excel: "Fatal error: Call to undefined function excel_format_XXX() in excel_xml_export.php on line 96" where XXX is the column's name. Signed-off-by: Damien Regad <damien.regad@merckgroup.com>
1 parent 224ca74 commit 45f4f52

5 files changed

+42
-3
lines changed
 

‎core/columns_api.php

+9
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ function columns_get_plugin_columns() {
142142
return $s_column_array;
143143
}
144144

145+
/**
146+
* Returns true if the specified $p_column is a plugin column.
147+
* @param string $p_column A column name.
148+
*/
149+
function column_is_plugin_column( $p_column ) {
150+
$t_plugin_columns = columns_get_plugin_columns();
151+
return isset( $t_plugin_columns[ $p_column ] );
152+
}
153+
145154
/**
146155
* Allow plugin columns to pre-cache data for a set of issues
147156
* rather than requiring repeated queries for each issue.

‎core/excel_api.php

+20
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,26 @@ function excel_format_custom_field( $p_issue_id, $p_project_id, $p_custom_field
473473
return excel_prepare_string( '' );
474474
}
475475

476+
/**
477+
* Gets the formatted value for the specified plugin column value.
478+
* @param $p_custom_field The plugin column name.
479+
* @param $p_bug The bug to print the column for (needed for the display function of the plugin column).
480+
* @returns The custom field value.
481+
*/
482+
function excel_format_plugin_column_value( $p_column, $p_bug ) {
483+
$t_plugin_columns = columns_get_plugin_columns();
484+
485+
if ( !isset( $t_plugin_columns[$p_column] ) ) {
486+
return excel_prepare_string( '' );
487+
} else {
488+
$t_column_object = $t_plugin_columns[ $p_column ];
489+
ob_start();
490+
$t_column_object->display( $p_bug, COLUMNS_TARGET_EXCEL_PAGE );
491+
$t_value = ob_get_clean();
492+
return excel_prepare_string( $t_value );
493+
}
494+
}
495+
476496
/**
477497
* Gets the formatted due date.
478498
* @param $p_due_date The due date.

‎csv_export.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
if ( $t_rows === false ) {
4747
print_header_redirect( 'view_all_set.php?type=0' );
4848
}
49+
50+
# pre-cache custom column data
51+
columns_plugin_cache_issue_data( $t_rows );
4952

5053
$t_filename = csv_get_default_filename();
5154

@@ -108,8 +111,7 @@
108111
$t_first_column = false;
109112
}
110113

111-
$t_custom_field = column_get_custom_field_name( $t_column );
112-
if ( $t_custom_field !== null ) {
114+
if ( column_get_custom_field_name( $t_column ) !== null || column_is_plugin_column( $t_column ) ) {
113115
ob_start();
114116
$t_column_value_function = 'print_column_value';
115117
helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );

‎excel_xml_export.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
if ( $result === false ) {
5656
print_header_redirect( 'view_all_set.php?type=0&print=1' );
5757
}
58+
59+
# pre-cache custom column data
60+
columns_plugin_cache_issue_data( $result );
5861

5962
header( 'Content-Type: application/vnd.ms-excel; charset=UTF-8' );
6063
header( 'Pragma: public' );
@@ -91,7 +94,9 @@
9194
$t_custom_field = column_get_custom_field_name( $t_column );
9295
if ( $t_custom_field !== null ) {
9396
echo excel_format_custom_field( $t_row->id, $t_row->project_id, $t_custom_field );
94-
} else {
97+
} else if ( column_is_plugin_column( $t_column ) ) {
98+
echo excel_format_plugin_column_value( $t_column, $t_row );
99+
} else{
95100
$t_function = 'excel_format_' . $t_column;
96101
echo $t_function( $t_row->$t_column );
97102
}

‎print_all_bug_page.php

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080

8181
$result = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count );
8282
$row_count = count( $result );
83+
84+
# pre-cache custom column data
85+
columns_plugin_cache_issue_data( $result );
8386

8487
# for export
8588
$t_show_flag = gpc_get_int( 'show_flag', 0 );

0 commit comments

Comments
 (0)
Please sign in to comment.