Skip to content

Commit a5708e0

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 b6c7456 commit a5708e0

5 files changed

+41
-2
lines changed
 

‎core/columns_api.php

+9
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ function columns_get_plugin_columns() {
190190
return $s_column_array;
191191
}
192192

193+
/**
194+
* Returns true if the specified $p_column is a plugin column.
195+
* @param string $p_column A column name.
196+
*/
197+
function column_is_plugin_column( $p_column ) {
198+
$t_plugin_columns = columns_get_plugin_columns();
199+
return isset( $t_plugin_columns[ $p_column ] );
200+
}
201+
193202
/**
194203
* Allow plugin columns to pre-cache data for a set of issues
195204
* rather than requiring repeated queries for each issue.

‎core/excel_api.php

+20
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,26 @@ function excel_format_custom_field( $p_issue_id, $p_project_id, $p_custom_field
498498
return excel_prepare_string( '' );
499499
}
500500

501+
/**
502+
* Gets the formatted value for the specified plugin column value.
503+
* @param $p_custom_field The plugin column name.
504+
* @param $p_bug The bug to print the column for (needed for the display function of the plugin column).
505+
* @returns The custom field value.
506+
*/
507+
function excel_format_plugin_column_value( $p_column, $p_bug ) {
508+
$t_plugin_columns = columns_get_plugin_columns();
509+
510+
if ( !isset( $t_plugin_columns[$p_column] ) ) {
511+
return excel_prepare_string( '' );
512+
} else {
513+
$t_column_object = $t_plugin_columns[ $p_column ];
514+
ob_start();
515+
$t_column_object->display( $p_bug, COLUMNS_TARGET_EXCEL_PAGE );
516+
$t_value = ob_get_clean();
517+
return excel_prepare_string( $t_value );
518+
}
519+
}
520+
501521
/**
502522
* Gets the formatted due date.
503523
* @param $p_due_date The due date.

‎csv_export.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
print_header_redirect( 'view_all_set.php?type=0' );
6363
}
6464

65+
# pre-cache custom column data
66+
columns_plugin_cache_issue_data( $t_rows );
67+
6568
$t_filename = csv_get_default_filename();
6669

6770
# Send headers to browser to activate mime loading
@@ -123,8 +126,7 @@
123126
$t_first_column = false;
124127
}
125128

126-
$t_custom_field = column_get_custom_field_name( $t_column );
127-
if ( $t_custom_field !== null ) {
129+
if ( column_get_custom_field_name( $t_column ) !== null || column_is_plugin_column( $t_column ) ) {
128130
ob_start();
129131
$t_column_value_function = 'print_column_value';
130132
helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );

‎excel_xml_export.php

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
print_header_redirect( 'view_all_set.php?type=0&print=1' );
7777
}
7878

79+
# pre-cache custom column data
80+
columns_plugin_cache_issue_data( $result );
81+
7982
header( 'Content-Type: application/vnd.ms-excel; charset=UTF-8' );
8083
header( 'Pragma: public' );
8184
header( 'Content-Disposition: attachment; filename="' . urlencode( file_clean_name( $t_export_title ) ) . '.xml"' ) ;
@@ -111,6 +114,8 @@
111114
$t_custom_field = column_get_custom_field_name( $t_column );
112115
if ( $t_custom_field !== null ) {
113116
echo excel_format_custom_field( $t_row->id, $t_row->project_id, $t_custom_field );
117+
} else if ( column_is_plugin_column( $t_column ) ) {
118+
echo excel_format_plugin_column_value( $t_column, $t_row );
114119
} else {
115120
$t_function = 'excel_format_' . $t_column;
116121
echo $t_function( $t_row->$t_column );

‎print_all_bug_page.php

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
$result = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count );
103103
$row_count = count( $result );
104104

105+
# pre-cache custom column data
106+
columns_plugin_cache_issue_data( $result );
107+
105108
# for export
106109
$t_show_flag = gpc_get_int( 'show_flag', 0 );
107110

0 commit comments

Comments
 (0)
Please sign in to comment.