GenericQuery
extends WC_Object_Query
in package
A generic class for a report-specific query to be used in Analytics.
Example usage:
$args = array(
'before' => '2018-07-19 00:00:00',
'after' => '2018-07-05 00:00:00',
'page' => 2,
);
$report = new GenericQuery( $args, 'coupons' );
$mydata = $report->get_data();
It uses the name provided in the class property or in the constructor call to load the report-{name}
data store.
It's used by the {@see GenericController}.
Tags
Table of Contents
- $name : string
- Specific query name.
- $query_vars : array<string|int, mixed>
- Stores query data.
- __construct() : mixed
- Create a new query.
- get() : mixed
- Get the value of a query variable.
- get_data() : mixed
- Get data from `report-{$name}` store, based on the current query vars.
- get_query_vars() : array<string|int, mixed>
- Get the current query vars.
- set() : mixed
- Set a query variable.
- get_default_query_vars() : array<string|int, mixed>
- Valid fields for Products report.
Properties
$name
Specific query name.
protected
string
$name
Will be used to load the report-{name}
data store,
and to call woocommerce_analytics_{snake_case(name)}_*
filters.
$query_vars
Stores query data.
protected
array<string|int, mixed>
$query_vars
= array()
Methods
__construct()
Create a new query.
public
__construct(array<string|int, mixed> $args[, string $name = null ]) : mixed
Parameters
- $args : array<string|int, mixed>
-
Criteria to query on in a format similar to WP_Query.
- $name : string = null
-
Query name.
Tags
Return values
mixed —get()
Get the value of a query variable.
public
get(string $query_var[, mixed $default = '' ]) : mixed
Parameters
- $query_var : string
-
Query variable to get value for.
- $default : mixed = ''
-
Default value if query variable is not set.
Return values
mixed — Query variable value if set, otherwise default.get_data()
Get data from `report-{$name}` store, based on the current query vars.
public
get_data() : mixed
Filters query vars through woocommerce_analytics_{snake_case(name)}_query_args
filter.
Filters results through woocommerce_analytics_{snake_case(name)}_select_query
filter.
Return values
mixed — filtered results from the data store.get_query_vars()
Get the current query vars.
public
get_query_vars() : array<string|int, mixed>
Return values
array<string|int, mixed> —set()
Set a query variable.
public
set(string $query_var, mixed $value) : mixed
Parameters
- $query_var : string
-
Query variable to set.
- $value : mixed
-
Value to set for query variable.
Return values
mixed —get_default_query_vars()
Valid fields for Products report.
protected
get_default_query_vars() : array<string|int, mixed>