From 1279ac3a7f71788bbbf093d92d15d037a7fe6f6f Mon Sep 17 00:00:00 2001 From: Carlos Proensa Date: Mon, 21 Dec 2015 21:00:56 +0100 Subject: [PATCH] Implement columns in csv and excel export In CSV and Excel export, there were columns that are not implemented, and were silently removed from user column selection: bugnotes_count, attachment_count With this commit they are now implemented Fixes #0019284 --- core/csv_api.php | 32 ++++++++++++++++++++++++++++++++ core/excel_api.php | 41 ++++++++++++++++++++++++++++++++--------- core/helper_api.php | 6 ------ 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/core/csv_api.php b/core/csv_api.php index 2b871b01fe..d2b6cae43a 100644 --- a/core/csv_api.php +++ b/core/csv_api.php @@ -480,3 +480,35 @@ function csv_format_due_date( BugData $p_bug ) { function csv_format_sponsorship_total( BugData $p_bug ) { return csv_escape_string( $p_bug->sponsorship_total ); } + +/** + * return the attachment count for an issue + * @param BugData $p_bug A BugData object. + * @return string + * @access public + */ +function csv_format_attachment_count( BugData $p_bug ) { + # Check for attachments + $t_attachment_count = 0; + if( file_can_view_bug_attachments( $p_bug->id, null ) ) { + $t_attachment_count = file_bug_attachment_count( $p_bug->id ); + } + return csv_escape_string( $t_attachment_count ); +} + +/** + * return the bug note count for an issue + * @param BugData $p_bug A BugData object. + * @return string + * @access public + */ +function csv_format_bugnotes_count( BugData $p_bug ) { + # grab the bugnote count + $t_bugnote_stats = bug_get_bugnote_stats( $p_bug->id ); + if( $t_bugnote_stats ) { + $t_bugnote_count = $t_bugnote_stats['count']; + } else { + $t_bugnote_count = 0; + } + return csv_escape_string( $t_bugnote_count ); +} diff --git a/core/excel_api.php b/core/excel_api.php index 421a10e6d6..108f131041 100644 --- a/core/excel_api.php +++ b/core/excel_api.php @@ -251,15 +251,6 @@ function excel_format_reporter_id( BugData $p_bug ) { return excel_prepare_string( user_get_name( $p_bug->reporter_id ) ); } -/** - * Gets the formatted number of bug notes. - * @param BugData $p_bug A bug object. - * @return string The number of bug notes. - */ -function excel_format_bugnotes_count( BugData $p_bug ) { - return excel_prepare_number( $p_bug->bugnotes_count ); -} - /** * Gets the formatted handler id. * @param BugData $p_bug A bug object. @@ -576,6 +567,38 @@ function excel_format_sponsorship_total( BugData $p_bug ) { return excel_prepare_string( $p_bug->sponsorship_total ); } +/** + * Gets the attachment count for an issue + * @param BugData $p_bug A bug object. + * @return string + * @access public + */ +function excel_format_attachment_count( BugData $p_bug ) { + # Check for attachments + $t_attachment_count = 0; + if( file_can_view_bug_attachments( $p_bug->id, null ) ) { + $t_attachment_count = file_bug_attachment_count( $p_bug->id ); + } + return excel_prepare_number( $t_attachment_count ); +} + +/** + * Gets the bug note count for an issue + * @param BugData $p_bug A bug object. + * @return string + * @access public + */ +function excel_format_bugnotes_count( BugData $p_bug ) { + # grab the bugnote count + $t_bugnote_stats = bug_get_bugnote_stats( $p_bug->id ); + if( null !== $t_bugnote_stats ) { + $t_bugnote_count = $t_bugnote_stats['count']; + } else { + $t_bugnote_count = 0; + } + return excel_prepare_number( $t_bugnote_count ); +} + /** * The ExcelStyle class is able to render style information * diff --git a/core/helper_api.php b/core/helper_api.php index 48b69a7c29..2f8bb297b5 100644 --- a/core/helper_api.php +++ b/core/helper_api.php @@ -506,15 +506,9 @@ function helper_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAG if( $p_columns_target == COLUMNS_TARGET_CSV_PAGE || $p_columns_target == COLUMNS_TARGET_EXCEL_PAGE ) { $t_keys_to_remove[] = 'selection'; $t_keys_to_remove[] = 'edit'; - $t_keys_to_remove[] = 'bugnotes_count'; - $t_keys_to_remove[] = 'attachment_count'; $t_keys_to_remove[] = 'overdue'; } - if( $p_columns_target == COLUMNS_TARGET_CSV_PAGE || $p_columns_target == COLUMNS_TARGET_EXCEL_PAGE ) { - $t_keys_to_remove[] = 'attachment_count'; - } - $t_current_project_id = helper_get_current_project(); if( $t_current_project_id != ALL_PROJECTS && !access_has_project_level( config_get( 'view_handler_threshold' ), $t_current_project_id ) ) {