WooCommerce Code Reference

ReportCSVExporter extends WC_CSV_Batch_Exporter
in package

ReportCSVExporter Class.

Table of Contents

$column_names  : array<string|int, mixed>
Columns ids and names.
$columns_to_export  : array<string|int, mixed>
List of columns to export, or empty for all.
$controller  : WC_REST_Reports_Controller
REST controller for the report.
$delimiter  : string
The delimiter parameter sets the field delimiter (one character only).
$export_type  : string
Type of export used in filter names.
$exported_row_count  : int
Number exported.
$filename  : string
Filename to export to.
$limit  : int
Batch limit.
$page  : int
Page being exported
$report_args  : array<string|int, mixed>
Parameters for the report query.
$report_type  : string
Type of report being exported.
$row_data  : array<string|int, mixed>
Raw data to export.
$total_rows  : int
Total rows to export.
__construct()  : mixed
Constructor.
escape_data()  : string
Escape a string to be used in a CSV context
export()  : mixed
Do the export.
format_data()  : string
Format and escape data ready for the CSV file.
format_term_ids()  : string
Format term ids to names.
generate_file()  : mixed
Generate the CSV file.
get_column_names()  : array<string|int, mixed>
Return an array of supported column names and ids.
get_columns_to_export()  : array<string|int, mixed>
Return an array of columns to export.
get_default_column_names()  : array<string|int, mixed>
Return default columns.
get_delimiter()  : string
Return the delimiter to use in CSV file
get_file()  : string
Get the file contents.
get_filename()  : string
Generate and return a filename.
get_headers_row_file()  : string
Get the contents of the CSV headers row file. Defaults to the original known headers.
get_limit()  : int
Get batch limit.
get_page()  : int
Get page.
get_percent_complete()  : int
Get total % complete.
get_reports_directory()  : string
Get report uploads directory.
get_total_exported()  : int
Get count of records exported.
get_total_rows()  : int
Get total number of rows in export.
is_column_exporting()  : bool
See if a column is to be exported or not.
maybe_create_directory()  : mixed
Create the directory for reports if it does not yet exist.
prepare_data_to_export()  : mixed
Prepare data for export.
send_content()  : mixed
Set the export content.
send_headers()  : mixed
Set the export headers.
set_column_names()  : mixed
Set column names.
set_columns_to_export()  : mixed
Set columns to export.
set_filename()  : mixed
Set filename to export to.
set_limit()  : mixed
Set batch limit.
set_page()  : mixed
Set page.
set_report_args()  : mixed
Setter for report args.
set_report_type()  : mixed
Setter for report type.
export_column_headers()  : string
Export column headers in CSV format.
export_row()  : mixed
Export rows to an array ready for the CSV.
export_rows()  : string
Export rows in CSV format.
fputcsv()  : mixed
Write to the CSV file.
generate_row_data()  : array<string|int, mixed>
Get the export row for a given report item.
get_csv_data()  : string
Get CSV data for this export.
get_data_to_export()  : array<string|int, mixed>
Get data that will be exported.
get_file_path()  : string
Get file path to export to.
get_headers_row_file_path()  : string
Get CSV headers row file path to export to.
get_raw_row_data()  : array<string|int, mixed>
Generate row data from a raw report item.
get_report_columns()  : array<string|int, mixed>
Get the report columns from the controller.
implode_values()  : string
Implode CSV cell values using commas by default, and wrapping values which contain the separator.
map_report_controller()  : bool|WC_REST_Reports_Controller
Get a REST controller instance for the report type.
write_csv_data()  : mixed
Write data to the file.

Properties

Methods

__construct()

Constructor.

public __construct([string $type = false ][, array<string|int, mixed> $args = array() ]) : mixed
Parameters
$type : string = false

Report type. E.g. 'customers'.

$args : array<string|int, mixed> = array()

Report parameters.

Return values
mixed

escape_data()

Escape a string to be used in a CSV context

public escape_data(string $data) : string

Malicious input can inject formulas into CSV files, opening up the possibility for phishing attacks and disclosure of sensitive information.

Additionally, Excel exposes the ability to launch arbitrary commands through the DDE protocol.

Parameters
$data : string

CSV field to escape.

Tags
see
https://owasp.org/www-community/attacks/CSV_Injection
see
https://hackerone.com/reports/72785
since
3.1.0
Return values
string

format_data()

Format and escape data ready for the CSV file.

public format_data(string $data) : string
Parameters
$data : string

Data to format.

Tags
since
3.1.0
Return values
string

format_term_ids()

Format term ids to names.

public format_term_ids(array<string|int, mixed> $term_ids, string $taxonomy) : string
Parameters
$term_ids : array<string|int, mixed>

Term IDs to format.

$taxonomy : string

Taxonomy name.

Tags
since
3.1.0
Return values
string

get_column_names()

Return an array of supported column names and ids.

public get_column_names() : array<string|int, mixed>
Tags
since
3.1.0
Return values
array<string|int, mixed>

get_columns_to_export()

Return an array of columns to export.

public get_columns_to_export() : array<string|int, mixed>
Tags
since
3.1.0
Return values
array<string|int, mixed>

get_default_column_names()

Return default columns.

public get_default_column_names() : array<string|int, mixed>
Tags
since
3.1.0
Return values
array<string|int, mixed>

get_percent_complete()

Get total % complete.

public get_percent_complete() : int

Forces an int from parent::get_percent_complete(), which can return a float.

Return values
intPercent complete.

get_reports_directory()

Get report uploads directory.

public static get_reports_directory() : string
Return values
string

get_total_rows()

Get total number of rows in export.

public get_total_rows() : int
Return values
intNumber of rows to export.

is_column_exporting()

See if a column is to be exported or not.

public is_column_exporting(string $column_id) : bool
Parameters
$column_id : string

ID of the column being exported.

Tags
since
3.1.0
Return values
bool

maybe_create_directory()

Create the directory for reports if it does not yet exist.

public static maybe_create_directory() : mixed
Return values
mixed

send_content()

Set the export content.

public send_content(string $csv_data) : mixed
Parameters
$csv_data : string

All CSV content.

Tags
since
3.1.0
Return values
mixed

set_column_names()

Set column names.

public set_column_names(array<string|int, mixed> $column_names) : mixed
Parameters
$column_names : array<string|int, mixed>

Column names array.

Tags
since
3.1.0
Return values
mixed

set_columns_to_export()

Set columns to export.

public set_columns_to_export(array<string|int, mixed> $columns) : mixed
Parameters
$columns : array<string|int, mixed>

Columns array.

Tags
since
3.1.0
Return values
mixed

set_report_args()

Setter for report args.

public set_report_args(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

The report args.

Return values
mixed

set_report_type()

Setter for report type.

public set_report_type(string $type) : mixed
Parameters
$type : string

The report type. E.g. customers.

Return values
mixed

export_row()

Export rows to an array ready for the CSV.

protected export_row(array<string|int, mixed> $row_data, string $key, resource $buffer) : mixed
Parameters
$row_data : array<string|int, mixed>

Data to export.

$key : string

Column being exported.

$buffer : resource

Output buffer.

Tags
since
3.1.0
Return values
mixed

fputcsv()

Write to the CSV file.

protected fputcsv(resource $buffer, array<string|int, mixed> $export_row) : mixed
Parameters
$buffer : resource

Resource we are writing to.

$export_row : array<string|int, mixed>

Row to export.

Tags
since
3.4.0
Return values
mixed

generate_row_data()

Get the export row for a given report item.

protected generate_row_data(object $item) : array<string|int, mixed>
Parameters
$item : object

Report item data.

Return values
array<string|int, mixed>CSV row data.

get_data_to_export()

Get data that will be exported.

protected get_data_to_export() : array<string|int, mixed>
Tags
since
3.1.0
Return values
array<string|int, mixed>

get_raw_row_data()

Generate row data from a raw report item.

protected get_raw_row_data(object $item) : array<string|int, mixed>
Parameters
$item : object

Report item data.

Return values
array<string|int, mixed>CSV row data.

get_report_columns()

Get the report columns from the controller.

protected get_report_columns() : array<string|int, mixed>
Return values
array<string|int, mixed>Array of report column names.

implode_values()

Implode CSV cell values using commas by default, and wrapping values which contain the separator.

protected implode_values(array<string|int, mixed> $values) : string
Parameters
$values : array<string|int, mixed>

Values to implode.

Tags
since
3.2.0
Return values
string

map_report_controller()

Get a REST controller instance for the report type.

protected map_report_controller() : bool|WC_REST_Reports_Controller
Return values
bool|WC_REST_Reports_ControllerReport controller instance or boolean false on error.