Query.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class for parameter-based Customers Report Stats querying |
| 4 | * |
| 5 | * Example usage: |
| 6 | * $args = array( |
| 7 | * 'registered_before' => '2018-07-19 00:00:00', |
| 8 | * 'registered_after' => '2018-07-05 00:00:00', |
| 9 | * 'page' => 2, |
| 10 | * 'avg_order_value_min' => 100, |
| 11 | * 'country' => 'GB', |
| 12 | * ); |
| 13 | * $report = new \Automattic\WooCommerce\Admin\API\Reports\Customers\Stats\Query( $args ); |
| 14 | * $mydata = $report->get_data(); |
| 15 | */ |
| 16 | |
| 17 | namespace Automattic\WooCommerce\Admin\API\Reports\Customers\Stats; |
| 18 | |
| 19 | defined( 'ABSPATH' ) || exit; |
| 20 | |
| 21 | use Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; |
| 22 | |
| 23 | /** |
| 24 | * API\Reports\Customers\Stats\Query |
| 25 | * |
| 26 | * @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use `Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or use `DataStore` directly. |
| 27 | */ |
| 28 | class Query extends ReportsQuery { |
| 29 | |
| 30 | /** |
| 31 | * Valid fields for Customers report. |
| 32 | * |
| 33 | * @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use `Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or use `DataStore` directly. |
| 34 | * |
| 35 | * @return array |
| 36 | */ |
| 37 | protected function get_default_query_vars() { |
| 38 | wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' ); |
| 39 | |
| 40 | return array( |
| 41 | 'per_page' => get_option( 'posts_per_page' ), // not sure if this should be the default. |
| 42 | 'page' => 1, |
| 43 | 'order' => 'DESC', |
| 44 | 'orderby' => 'date_registered', |
| 45 | 'fields' => '*', // @todo Needed? |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Get product data based on the current query vars. |
| 51 | * |
| 52 | * @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use `Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or use `DataStore` directly. |
| 53 | * |
| 54 | * @return array |
| 55 | */ |
| 56 | public function get_data() { |
| 57 | wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'x.x.x', '`Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' ); |
| 58 | |
| 59 | $args = apply_filters( 'woocommerce_analytics_customers_stats_query_args', $this->get_query_vars() ); |
| 60 | |
| 61 | $data_store = \WC_Data_Store::load( 'report-customers-stats' ); |
| 62 | $results = $data_store->get_data( $args ); |
| 63 | return apply_filters( 'woocommerce_analytics_customers_stats_select_query', $results, $args ); |
| 64 | } |
| 65 | } |
| 66 |