WooCommerce Code Reference

DataStore extends DataStore
in package
implements DataStoreInterface

API\Reports\Products\Stats\DataStore.

Interfaces, Classes and Traits

DataStoreInterface
WooCommerce Reports data store interface.

Table of Contents

$cache_group  : string
Cache group for the reports.
$cache_key  : string
Cache identifier.
$cache_timeout  : int
Time out for the cache.
$column_types  : array<string|int, mixed>
Mapping columns to data type to return correct response types.
$context  : string
Data store context used to pass to filters.
$date_column_name  : string
Date field name.
$debug_cache  : bool
Include debugging information in the returned data when true.
$debug_cache_data  : array<string|int, mixed>
Debugging information to include in the returned data.
$extended_attributes  : array<string|int, mixed>
Extended product attributes to include in the data.
$force_cache_refresh  : bool
Refresh the cache for the current query when true.
$interval_query  : SqlQuery
Intervals query object.
$report_columns  : array<string|int, mixed>
SQL columns to select in the db query.
$subquery  : SqlQuery
Subquery object for query nesting.
$table_name  : string
Table used as a data store for this report.
$total_query  : SqlQuery
Totals query object.
$limit_parameters  : array<string|int, mixed>
Query limit parameters.
$order  : string
Order property, used in the cmp function.
$order_by  : string
Order by property, used in the cmp function.
$sql_clauses  : array<string|int, mixed>
List of SQL clauses.
$sql_filters  : array<string|int, mixed>
SQL clause merge filters.
__construct()  : mixed
Constructor.
add_debug_cache_to_envelope()  : array<string|int, mixed>
Add cache debugging information to an enveloped API response.
add_sql_clause()  : mixed
Add a SQL clause to be included when get_data is called.
clear_all_clauses()  : mixed
Reinitialize the clause array.
get_data()  : stdClass|WP_Error
Returns the report data based on parameters supplied by the user.
get_db_table_name()  : mixed
Get table name from database class.
get_query_statement()  : string
Get the full SQL statement.
init()  : mixed
Set up all the hooks for maintaining and populating table data.
sync_on_order_delete()  : mixed
Clean products data when an order is deleted.
sync_order_products()  : int|bool
Create or update an entry in the wc_admin_order_product_lookup table for an order.
add_from_sql_params()  : mixed
Fills FROM clause of SQL request based on user supplied parameters.
add_intervals_sql_params()  : mixed
Fills FROM and WHERE clauses of SQL request for 'Intervals' section of data response based on user supplied parameters.
add_order_by_clause()  : string
Add order by SQL clause if included in query.
add_order_by_sql_params()  : mixed
Fills ORDER BY clause of SQL request based on user supplied parameters.
add_order_status_clause()  : mixed
Add order status SQL clauses if included in query.
add_orderby_order_clause()  : mixed
Add order by order SQL clause.
add_sql_query_params()  : mixed
Updates the database query with parameters used for Products report: categories and order status.
add_time_period_sql_params()  : mixed
Fills WHERE clause of SQL request with date-related constraints.
assign_report_columns()  : mixed
Assign report columns once full table name has been assigned.
cast_numbers()  : array<string|int, mixed>|WP_Error
Casts strings returned from the database to appropriate data types for output.
clear_sql_clause()  : mixed
Clear SQL clauses by type.
create_interval_subtotals()  : mixed
Change structure of intervals to form a correct response.
expected_intervals_on_page()  : float|int
Returns expected number of items on the page in case of date ordering.
fill_in_missing_intervals()  : stdClass
Fills in interval gaps from DB with 0-filled objects.
format_join_selections()  : string
Returns a comma separated list of the field names prepared to be used for a selection after a join with `default_results`.
get_attribute_subqueries()  : array<string|int, mixed>
Returns product attribute subquery elements used in JOIN and WHERE clauses, based on query arguments from the user.
get_cache_key()  : string
Returns string to be used as cache key for the data.
get_cached_data()  : mixed
Wrapper around Cache::get().
get_customer_subquery()  : string
Returns customer subquery to be used in WHERE SQL query, based on query arguments from the user.
get_excluded_coupons()  : string
Returns comma separated ids of excluded coupons, based on query arguments from the user.
get_excluded_orders()  : string
Returns comma separated ids of excluded orders, based on query arguments from the user.
get_excluded_products()  : string
Returns comma separated ids of excluded products, based on query arguments from the user.
get_excluded_products_array()  : array<string|int, mixed>
Returns an array of ids of disallowed products, based on query arguments from the user.
get_excluded_report_order_statuses()  : array<string|int, mixed>
Get the excluded order statuses used when calculating reports.
get_excluded_users()  : string
Returns comma separated ids of excluded users, based on query arguments from the user.
get_excluded_variations()  : string
Returns comma separated ids of excluded variations, based on query arguments from the user.
get_fields()  : array<string|int, mixed>
Returns a comma separated list of the fields in the `query_args`, if there aren't, returns `report_columns` keys.
get_filtered_ids()  : string
Returns filtered comma separated ids, based on query arguments from the user.
get_ids_table()  : array<string|int, mixed>
Generates a virtual table given a list of IDs.
get_included_categories()  : string
Returns comma separated ids of included categories, based on query arguments from the user.
get_included_coupons()  : string
Returns comma separated ids of included coupons, based on query arguments from the user.
get_included_orders()  : string
Returns comma separated ids of included orders, based on query arguments from the user.
get_included_products()  : string
Returns comma separated ids of allowed products, based on query arguments from the user.
get_included_products_array()  : array<string|int, mixed>
Returns an array of ids of allowed products, based on query arguments from the user.
get_included_users()  : string
Returns comma separated ids of included users, based on query arguments from the user.
get_included_variations()  : string
Returns comma separated ids of allowed variations, based on query arguments from the user.
get_limit_params()  : array<string|int, mixed>
Fills LIMIT parameters of SQL request based on user supplied parameters.
get_limit_sql_params()  : array<string|int, mixed>
Fills LIMIT clause of SQL request based on user supplied parameters.
get_match_operator()  : string
Returns logic operator for WHERE subclause based on 'match' query argument.
get_object_where_filter()  : string
Get WHERE filter by object ids subquery.
get_products_by_cat_ids()  : array<string|int, mixed>|stdClass
Returns an array of products belonging to given categories.
get_refund_subquery()  : array<string|int, mixed>
Get join and where clauses for refunds based on user supplied parameters.
get_sql_clause()  : string
Get SQL clause by type.
get_status_subquery()  : string
Returns order status subquery to be used in WHERE SQL query, based on query arguments from the user.
include_extended_info()  : mixed
Enriches the product data with attributes specified by the extended_attributes.
initialize_queries()  : mixed
Initialize query objects.
intervals_missing()  : bool
Returns true if there are any intervals that need to be filled in the response.
normalize_order_by()  : string
Normalizes order_by clause to match to SQL query.
normalize_order_status()  : string
Maps order status provided by the user to the one used in the database.
normalize_timezones()  : mixed
Converts input datetime parameters to local timezone. If there are no inputs from the user in query_args, uses default from $defaults.
remove_extra_records()  : mixed
Removes extra records from intervals so that only requested number of records get returned.
selected_columns()  : string
Returns a list of columns selected by the query_args formatted as a comma separated string.
set_cached_data()  : bool
Wrapper around Cache::set().
set_db_table_name()  : mixed
Set table name from database class.
should_use_cache()  : bool
Whether or not the report should use the caching layer.
sort_array()  : mixed
Sorts array of arrays based on subarray key $sort_by.
sort_intervals()  : mixed
Sorts intervals according to user's request.
str_replace_clause()  : mixed
Replace strings within SQL clauses by type.
update_interval_boundary_dates()  : mixed
Updates start and end dates for intervals so that they represent intervals' borders, not times when data in db were recorded.
update_intervals_sql_params()  : mixed
Updates the LIMIT query part for Intervals query of the report.
update_sql_query_params()  : mixed
Updates the database query with parameters used for Products Stats report: categories and order status.
interval_cmp()  : string
Compares two report data objects by pre-defined object property and ASC/DESC ordering.

Properties

$column_types

Mapping columns to data type to return correct response types.

protected array<string|int, mixed> $column_types = array('date_start' => 'strval', 'date_end' => 'strval', 'product_id' => 'intval', 'items_sold' => 'intval', 'net_revenue' => 'floatval', 'orders_count' => 'intval', 'products_count' => 'intval', 'variations_count' => 'intval')

$debug_cache_data

Debugging information to include in the returned data.

protected array<string|int, mixed> $debug_cache_data = array()

$extended_attributes

Extended product attributes to include in the data.

protected array<string|int, mixed> $extended_attributes = array('name', 'price', 'image', 'permalink', 'stock_status', 'stock_quantity', 'manage_stock', 'low_stock_amount', 'category_ids', 'variations', 'sku')

$sql_clauses

List of SQL clauses.

private array<string|int, mixed> $sql_clauses = array('select' => array(), 'from' => array(), 'left_join' => array(), 'join' => array(), 'right_join' => array(), 'where' => array(), 'where_time' => array(), 'group_by' => array(), 'having' => array(), 'limit' => array(), 'order_by' => array(), 'union' => array())

$sql_filters

SQL clause merge filters.

private array<string|int, mixed> $sql_filters = array('where' => array('where', 'where_time'), 'join' => array('right_join', 'join', 'left_join'))

Methods

__construct()

Constructor.

public __construct([string $context = '' ]) : mixed
Parameters
$context : string = ''

Optional context passed to filters. Default empty string.

Return values
mixed

add_debug_cache_to_envelope()

Add cache debugging information to an enveloped API response.

public add_debug_cache_to_envelope(array<string|int, mixed> $envelope, WP_REST_Response $response) : array<string|int, mixed>
Parameters
$envelope : array<string|int, mixed>
$response : WP_REST_Response
Return values
array<string|int, mixed>

add_sql_clause()

Add a SQL clause to be included when get_data is called.

public add_sql_clause(string $type, string $clause) : mixed
Parameters
$type : string

Clause type.

$clause : string

SQL clause.

Return values
mixed

get_data()

Returns the report data based on parameters supplied by the user.

public get_data(array<string|int, mixed> $query_args) : stdClass|WP_Error
Parameters
$query_args : array<string|int, mixed>

Query parameters.

Tags
since
3.5.0
Return values
stdClass|WP_ErrorData.

sync_on_order_delete()

Clean products data when an order is deleted.

public static sync_on_order_delete(int $order_id) : mixed
Parameters
$order_id : int

Order ID.

Return values
mixed

sync_order_products()

Create or update an entry in the wc_admin_order_product_lookup table for an order.

public static sync_order_products(int $order_id) : int|bool
Parameters
$order_id : int

Order ID.

Tags
since
3.5.0
Return values
int|boolReturns -1 if order won't be processed, or a boolean indicating processing success.

add_from_sql_params()

Fills FROM clause of SQL request based on user supplied parameters.

protected add_from_sql_params(array<string|int, mixed> $query_args, string $arg_name, string $id_cell) : mixed
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$arg_name : string

Target of the JOIN sql param.

$id_cell : string

ID cell identifier, like table_name.id_column_name.

Return values
mixed

add_intervals_sql_params()

Fills FROM and WHERE clauses of SQL request for 'Intervals' section of data response based on user supplied parameters.

protected add_intervals_sql_params(array<string|int, mixed> $query_args, string $table_name) : mixed
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$table_name : string

Name of the db table relevant for the date constraint.

Return values
mixed

add_order_by_clause()

Add order by SQL clause if included in query.

protected add_order_by_clause(array<string|int, mixed> $query_args, SqlQuery &$sql_query) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$sql_query : SqlQuery

Query object.

Return values
stringOrder by clause.

add_order_by_sql_params()

Fills ORDER BY clause of SQL request based on user supplied parameters.

protected add_order_by_sql_params(array<string|int, mixed> $query_args) : mixed
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
mixed

add_order_status_clause()

Add order status SQL clauses if included in query.

protected add_order_status_clause(array<string|int, mixed> $query_args, string $table_name, SqlQuery &$sql_query) : mixed
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$table_name : string

Database table name.

$sql_query : SqlQuery

Query object.

Return values
mixed

add_orderby_order_clause()

Add order by order SQL clause.

protected add_orderby_order_clause(array<string|int, mixed> $query_args, SqlQuery &$sql_query) : mixed
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$sql_query : SqlQuery

Query object.

Return values
mixed

add_sql_query_params()

Updates the database query with parameters used for Products report: categories and order status.

protected add_sql_query_params(array<string|int, mixed> $query_args) : mixed
Parameters
$query_args : array<string|int, mixed>

Query arguments supplied by the user.

Return values
mixed

add_time_period_sql_params()

Fills WHERE clause of SQL request with date-related constraints.

protected add_time_period_sql_params(array<string|int, mixed> $query_args, string $table_name) : mixed
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$table_name : string

Name of the db table relevant for the date constraint.

Return values
mixed

cast_numbers()

Casts strings returned from the database to appropriate data types for output.

protected cast_numbers(array<string|int, mixed> $array) : array<string|int, mixed>|WP_Error
Parameters
$array : array<string|int, mixed>

Associative array of values extracted from the database.

Return values
array<string|int, mixed>|WP_Error

clear_sql_clause()

Clear SQL clauses by type.

protected clear_sql_clause(string|array<string|int, mixed> $types) : mixed
Parameters
$types : string|array<string|int, mixed>

Clause type.

Return values
mixed

create_interval_subtotals()

Change structure of intervals to form a correct response.

protected create_interval_subtotals(array<string|int, mixed> &$intervals) : mixed

Also converts local datetimes to GMT and adds them to the intervals.

Parameters
$intervals : array<string|int, mixed>

Time interval, e.g. day, week, month.

Return values
mixed

expected_intervals_on_page()

Returns expected number of items on the page in case of date ordering.

protected expected_intervals_on_page(int $expected_interval_count, int $items_per_page, int $page_no) : float|int
Parameters
$expected_interval_count : int

Expected number of intervals in total.

$items_per_page : int

Number of items per page.

$page_no : int

Page number.

Return values
float|int

fill_in_missing_intervals()

Fills in interval gaps from DB with 0-filled objects.

protected fill_in_missing_intervals(array<string|int, mixed> $db_intervals, DateTime $start_datetime, DateTime $end_datetime, string $time_interval, stdClass &$data) : stdClass
Parameters
$db_intervals : array<string|int, mixed>

Array of all intervals present in the db.

$start_datetime : DateTime

Start date.

$end_datetime : DateTime

End date.

$time_interval : string

Time interval, e.g. day, week, month.

$data : stdClass

Data with SQL extracted intervals.

Return values
stdClass

format_join_selections()

Returns a comma separated list of the field names prepared to be used for a selection after a join with `default_results`.

protected format_join_selections(array<string|int, mixed> $fields, array<string|int, mixed> $default_results_fields[, array<string|int, mixed> $outer_selections = array() ]) : string
Parameters
$fields : array<string|int, mixed>

Array of fields name.

$default_results_fields : array<string|int, mixed>

Fields to load from default_results table.

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

Array of fields that are not selected in the inner query.

Return values
string

get_attribute_subqueries()

Returns product attribute subquery elements used in JOIN and WHERE clauses, based on query arguments from the user.

protected get_attribute_subqueries(array<string|int, mixed> $query_args) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
array<string|int, mixed>

get_cache_key()

Returns string to be used as cache key for the data.

protected get_cache_key(array<string|int, mixed> $params) : string
Parameters
$params : array<string|int, mixed>

Query parameters.

Return values
string

get_cached_data()

Wrapper around Cache::get().

protected get_cached_data(string $cache_key) : mixed
Parameters
$cache_key : string

Cache key.

Return values
mixed

get_customer_subquery()

Returns customer subquery to be used in WHERE SQL query, based on query arguments from the user.

protected get_customer_subquery(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_excluded_coupons()

Returns comma separated ids of excluded coupons, based on query arguments from the user.

protected get_excluded_coupons(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_excluded_orders()

Returns comma separated ids of excluded orders, based on query arguments from the user.

protected get_excluded_orders(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_excluded_products()

Returns comma separated ids of excluded products, based on query arguments from the user.

protected get_excluded_products(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_excluded_products_array()

Returns an array of ids of disallowed products, based on query arguments from the user.

protected get_excluded_products_array(array<string|int, mixed> $query_args) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
array<string|int, mixed>

get_excluded_report_order_statuses()

Get the excluded order statuses used when calculating reports.

protected static get_excluded_report_order_statuses() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_excluded_users()

Returns comma separated ids of excluded users, based on query arguments from the user.

protected get_excluded_users(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_excluded_variations()

Returns comma separated ids of excluded variations, based on query arguments from the user.

protected get_excluded_variations(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_fields()

Returns a comma separated list of the fields in the `query_args`, if there aren't, returns `report_columns` keys.

protected get_fields(array<string|int, mixed> $query_args) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
array<string|int, mixed>

get_filtered_ids()

Returns filtered comma separated ids, based on query arguments from the user.

protected get_filtered_ids(array<string|int, mixed> $query_args, string $field[, string $separator = ',' ]) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$field : string

Query field to filter.

$separator : string = ','

Field separator.

Return values
string

get_ids_table()

Generates a virtual table given a list of IDs.

protected get_ids_table(array<string|int, mixed> $ids, array<string|int, mixed> $id_field[, array<string|int, mixed> $other_values = array() ]) : array<string|int, mixed>
Parameters
$ids : array<string|int, mixed>

Array of IDs.

$id_field : array<string|int, mixed>

Name of the ID field.

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

Other values that must be contained in the virtual table.

Return values
array<string|int, mixed>

get_included_categories()

Returns comma separated ids of included categories, based on query arguments from the user.

protected get_included_categories(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_included_coupons()

Returns comma separated ids of included coupons, based on query arguments from the user.

protected get_included_coupons(array<string|int, mixed> $query_args[, string $field = 'coupon_includes' ]) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$field : string = 'coupon_includes'

Field name in the parameter list.

Return values
string

get_included_orders()

Returns comma separated ids of included orders, based on query arguments from the user.

protected get_included_orders(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_included_products()

Returns comma separated ids of allowed products, based on query arguments from the user.

protected get_included_products(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_included_products_array()

Returns an array of ids of allowed products, based on query arguments from the user.

protected get_included_products_array(array<string|int, mixed> $query_args) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
array<string|int, mixed>

get_included_users()

Returns comma separated ids of included users, based on query arguments from the user.

protected get_included_users(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_included_variations()

Returns comma separated ids of allowed variations, based on query arguments from the user.

protected get_included_variations(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_limit_params()

Fills LIMIT parameters of SQL request based on user supplied parameters.

protected get_limit_params([array<string|int, mixed> $query_args = array() ]) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed> = array()

Parameters supplied by the user.

Return values
array<string|int, mixed>

get_limit_sql_params()

Fills LIMIT clause of SQL request based on user supplied parameters.

protected get_limit_sql_params(array<string|int, mixed> $query_args) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
array<string|int, mixed>

get_match_operator()

Returns logic operator for WHERE subclause based on 'match' query argument.

protected get_match_operator(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
string

get_object_where_filter()

Get WHERE filter by object ids subquery.

protected get_object_where_filter(string $select_table, string $select_field, string $filter_table, string $filter_field, string $compare, string $id_list) : string
Parameters
$select_table : string

Select table name.

$select_field : string

Select table object ID field name.

$filter_table : string

Lookup table name.

$filter_field : string

Lookup table object ID field name.

$compare : string

Comparison string (IN|NOT IN).

$id_list : string

Comma separated ID list.

Return values
string

get_products_by_cat_ids()

Returns an array of products belonging to given categories.

protected get_products_by_cat_ids(array<string|int, mixed> $categories) : array<string|int, mixed>|stdClass
Parameters
$categories : array<string|int, mixed>

List of categories IDs.

Return values
array<string|int, mixed>|stdClass

get_refund_subquery()

Get join and where clauses for refunds based on user supplied parameters.

protected get_refund_subquery(array<string|int, mixed> $query_args) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

Return values
array<string|int, mixed>

get_sql_clause()

Get SQL clause by type.

protected get_sql_clause(string $type[, string $handling = 'unfiltered' ]) : string
Parameters
$type : string

Clause type.

$handling : string = 'unfiltered'

Whether to filter the return value (filtered|unfiltered). Default unfiltered.

Return values
stringSQL clause.

get_status_subquery()

Returns order status subquery to be used in WHERE SQL query, based on query arguments from the user.

protected get_status_subquery(array<string|int, mixed> $query_args[, string $operator = 'AND' ]) : string
Parameters
$query_args : array<string|int, mixed>

Parameters supplied by the user.

$operator : string = 'AND'

AND or OR, based on match query argument.

Return values
string

include_extended_info()

Enriches the product data with attributes specified by the extended_attributes.

protected include_extended_info(array<string|int, mixed> &$products_data, array<string|int, mixed> $query_args) : mixed
Parameters
$products_data : array<string|int, mixed>

Product data.

$query_args : array<string|int, mixed>

Query parameters.

Return values
mixed

intervals_missing()

Returns true if there are any intervals that need to be filled in the response.

protected intervals_missing(int $expected_interval_count, int $db_records, int $items_per_page, int $page_no, string $order, string $order_by, int $intervals_count) : bool
Parameters
$expected_interval_count : int

Expected number of intervals in total.

$db_records : int

Total number of records for given period in the database.

$items_per_page : int

Number of items per page.

$page_no : int

Page number.

$order : string

asc or desc.

$order_by : string

Column by which the result will be sorted.

$intervals_count : int

Number of records for given (possibly shortened) time interval.

Return values
bool

normalize_order_by()

Normalizes order_by clause to match to SQL query.

protected normalize_order_by(string $order_by) : string
Parameters
$order_by : string

Order by option requeste by user.

Return values
string

normalize_order_status()

Maps order status provided by the user to the one used in the database.

protected static normalize_order_status(string $status) : string
Parameters
$status : string

Order status.

Return values
string

normalize_timezones()

Converts input datetime parameters to local timezone. If there are no inputs from the user in query_args, uses default from $defaults.

protected normalize_timezones(array<string|int, mixed> &$query_args, array<string|int, mixed> $defaults) : mixed
Parameters
$query_args : array<string|int, mixed>

Array of query arguments.

$defaults : array<string|int, mixed>

Array of default values.

Return values
mixed

remove_extra_records()

Removes extra records from intervals so that only requested number of records get returned.

protected remove_extra_records(stdClass &$data, int $page_no, int $items_per_page, int $db_interval_count, int $expected_interval_count, string $order_by, string $order) : mixed
Parameters
$data : stdClass

Data from whose intervals the records get removed.

$page_no : int

Offset requested by the user.

$items_per_page : int

Number of records requested by the user.

$db_interval_count : int

Database interval count.

$expected_interval_count : int

Expected interval count on the output.

$order_by : string

Order by field.

$order : string

ASC or DESC.

Return values
mixed

selected_columns()

Returns a list of columns selected by the query_args formatted as a comma separated string.

protected selected_columns(array<string|int, mixed> $query_args) : string
Parameters
$query_args : array<string|int, mixed>

User-supplied options.

Return values
string

set_cached_data()

Wrapper around Cache::set().

protected set_cached_data(string $cache_key, mixed $value) : bool
Parameters
$cache_key : string

Cache key.

$value : mixed

New value.

Return values
bool

should_use_cache()

Whether or not the report should use the caching layer.

protected should_use_cache() : bool

Provides an opportunity for plugins to prevent reports from using cache.

Return values
boolWhether or not to utilize caching.

sort_array()

Sorts array of arrays based on subarray key $sort_by.

protected sort_array(array<string|int, mixed> &$arr, string $sort_by, string $direction) : mixed
Parameters
$arr : array<string|int, mixed>

Array to sort.

$sort_by : string

Ordering property.

$direction : string

DESC/ASC.

Return values
mixed

sort_intervals()

Sorts intervals according to user's request.

protected sort_intervals(stdClass &$data, string $sort_by, string $direction) : mixed

They are pre-sorted in SQL, but after adding gaps, they need to be sorted including the added ones.

Parameters
$data : stdClass

Data object, must contain an array under $data->intervals.

$sort_by : string

Ordering property.

$direction : string

DESC/ASC.

Return values
mixed

str_replace_clause()

Replace strings within SQL clauses by type.

protected str_replace_clause(string $type, string $search, string $replace) : mixed
Parameters
$type : string

Clause type.

$search : string

String to search for.

$replace : string

Replacement string.

Return values
mixed

update_interval_boundary_dates()

Updates start and end dates for intervals so that they represent intervals' borders, not times when data in db were recorded.

protected update_interval_boundary_dates(DateTime $start_datetime, DateTime $end_datetime, string $time_interval, array<string|int, mixed> &$intervals) : mixed

E.g. if there are db records for only Tuesday and Thursday this week, the actual week interval is [Mon, Sun], not [Tue, Thu].

Parameters
$start_datetime : DateTime

Start date.

$end_datetime : DateTime

End date.

$time_interval : string

Time interval, e.g. day, week, month.

$intervals : array<string|int, mixed>

Array of intervals extracted from SQL db.

Return values
mixed

update_intervals_sql_params()

Updates the LIMIT query part for Intervals query of the report.

protected update_intervals_sql_params(array<string|int, mixed> &$query_args, int $db_interval_count, int $expected_interval_count, string $table_name) : mixed

If there are less records in the database than time intervals, then we need to remap offset in SQL query to fetch correct records.

Parameters
$query_args : array<string|int, mixed>

Query arguments.

$db_interval_count : int

Database interval count.

$expected_interval_count : int

Expected interval count on the output.

$table_name : string

Name of the db table relevant for the date constraint.

Return values
mixed

update_sql_query_params()

Updates the database query with parameters used for Products Stats report: categories and order status.

protected update_sql_query_params(array<string|int, mixed> $query_args) : mixed
Parameters
$query_args : array<string|int, mixed>

Query arguments supplied by the user.

Return values
mixed

interval_cmp()

Compares two report data objects by pre-defined object property and ASC/DESC ordering.

private interval_cmp(stdClass $a, stdClass $b) : string
Parameters
$a : stdClass

Object a.

$b : stdClass

Object b.

Return values
string