From f02417114ffa5aac48d35d0c3ac82bc8636e7646 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 30 May 2019 14:48:30 +0100 Subject: [PATCH] Reports --- src/RestApi/Version4/Controllers/Reports.php | 18 -- ...tegories-controller.php => Categories.php} | 6 +- ...s-stats-controller.php => CouponStats.php} | 13 +- ...rts-coupons-controller.php => Coupons.php} | 13 +- ...stats-controller.php => CustomerStats.php} | 13 +- ...customers-controller.php => Customers.php} | 13 +- ...stats-controller.php => DownloadStats.php} | 13 +- ...downloads-controller.php => Downloads.php} | 13 +- ...ports-import-controller.php => Import.php} | 13 +- ...rs-stats-controller.php => OrderStats.php} | 13 +- ...ports-orders-controller.php => Orders.php} | 13 +- ...ntroller.php => PerformanceIndicators.php} | 13 +- ...-stats-controller.php => ProductStats.php} | 13 +- ...s-products-controller.php => Products.php} | 13 +- ...-stats-controller.php => RevenueStats.php} | 13 +- ...reports-stock-controller.php => Stock.php} | 13 +- ...ck-stats-controller.php => StockStats.php} | 13 +- ...axes-stats-controller.php => TaxStats.php} | 13 +- ...reports-taxes-controller.php => Taxes.php} | 13 +- ...riations-controller.php => Variations.php} | 13 +- ...class-wc-admin-rest-reports-controller.php | 303 ------------------ ...est-reports-downloads-files-controller.php | 33 -- src/RestApi/Version4/changelog.md | 20 +- 23 files changed, 148 insertions(+), 466 deletions(-) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-categories-controller.php => Categories.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-coupons-stats-controller.php => CouponStats.php} (97%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-coupons-controller.php => Coupons.php} (97%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-customers-stats-controller.php => CustomerStats.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-customers-controller.php => Customers.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-downloads-stats-controller.php => DownloadStats.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-downloads-controller.php => Downloads.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-import-controller.php => Import.php} (97%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-orders-stats-controller.php => OrderStats.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-orders-controller.php => Orders.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-performance-indicators-controller.php => PerformanceIndicators.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-products-stats-controller.php => ProductStats.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-products-controller.php => Products.php} (97%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-revenue-stats-controller.php => RevenueStats.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-stock-controller.php => Stock.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-stock-stats-controller.php => StockStats.php} (93%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-taxes-stats-controller.php => TaxStats.php} (98%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-taxes-controller.php => Taxes.php} (97%) rename src/RestApi/Version4/Controllers/Reports/{class-wc-admin-rest-reports-variations-controller.php => Variations.php} (97%) delete mode 100644 src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-controller.php delete mode 100644 src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-files-controller.php diff --git a/src/RestApi/Version4/Controllers/Reports.php b/src/RestApi/Version4/Controllers/Reports.php index 76113202b5d..72a8dc96631 100644 --- a/src/RestApi/Version4/Controllers/Reports.php +++ b/src/RestApi/Version4/Controllers/Reports.php @@ -123,10 +123,6 @@ class Reports extends WC_REST_Controller { 'slug' => 'downloads', 'description' => __( 'Product downloads detailed reports.', 'woocommerce' ), ), - array( - 'slug' => 'downloads/files', - 'description' => __( 'Product download files detailed reports.', 'woocommerce' ), - ), array( 'slug' => 'downloads/stats', 'description' => __( 'Stats about product downloads.', 'woocommerce' ), @@ -301,18 +297,4 @@ class Reports extends WC_REST_Controller { return $order_statuses; } - - /** - * Check whether a given request has permission to read reports. - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|boolean - */ - public function get_items_permissions_check( $request ) { - if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); - } - - return true; - } } diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-categories-controller.php b/src/RestApi/Version4/Controllers/Reports/Categories.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-categories-controller.php rename to src/RestApi/Version4/Controllers/Reports/Categories.php index 2a1fff9fd04..d5cde576636 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-categories-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Categories.php @@ -11,12 +11,12 @@ namespace WooCommerce\RestApi\Version4\Controllers\Reports; defined( 'ABSPATH' ) || exit; -use \WC_Admin_REST_Reports_Controller; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; /** - * REST API Category Reports class. + * REST API Categories Reports class. */ -class Categories extends WC_Admin_REST_Reports_Controller { +class Categories extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-coupons-stats-controller.php b/src/RestApi/Version4/Controllers/Reports/CouponStats.php similarity index 97% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-coupons-stats-controller.php rename to src/RestApi/Version4/Controllers/Reports/CouponStats.php index a416a57dc3f..fe655e18af9 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-coupons-stats-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/CouponStats.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/coupons/stats endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports coupons stats controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API CouponStats Reports class. */ -class WC_Admin_REST_Reports_Coupons_Stats_Controller extends WC_REST_Reports_Controller { +class CouponStats extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-coupons-controller.php b/src/RestApi/Version4/Controllers/Reports/Coupons.php similarity index 97% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-coupons-controller.php rename to src/RestApi/Version4/Controllers/Reports/Coupons.php index f2146a7bfe3..3821e17bd07 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-coupons-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Coupons.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/coupons endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports coupons controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API Coupons Reports class. */ -class WC_Admin_REST_Reports_Coupons_Controller extends WC_REST_Reports_Controller { +class Coupons extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-customers-stats-controller.php b/src/RestApi/Version4/Controllers/Reports/CustomerStats.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-customers-stats-controller.php rename to src/RestApi/Version4/Controllers/Reports/CustomerStats.php index 5b076fa929b..e604aeacb97 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-customers-stats-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/CustomerStats.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/customers/stats endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports customers stats controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API CustomerStats Reports class. */ -class WC_Admin_REST_Reports_Customers_Stats_Controller extends WC_REST_Reports_Controller { +class CustomerStats extends Reports { /** * Endpoint namespace. * diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-customers-controller.php b/src/RestApi/Version4/Controllers/Reports/Customers.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-customers-controller.php rename to src/RestApi/Version4/Controllers/Reports/Customers.php index 02b974cc922..da23ebb5d15 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-customers-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Customers.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/customers endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports customers controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API Customers Reports class. */ -class WC_Admin_REST_Reports_Customers_Controller extends WC_REST_Reports_Controller { +class Customers extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-stats-controller.php b/src/RestApi/Version4/Controllers/Reports/DownloadStats.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-stats-controller.php rename to src/RestApi/Version4/Controllers/Reports/DownloadStats.php index 4a0234449af..08da58d69ab 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-stats-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/DownloadStats.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/downloads/stats endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports downloads stats controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API DownloadStats Reports class. */ -class WC_Admin_REST_Reports_Downloads_Stats_Controller extends WC_REST_Reports_Controller { +class DownloadStats extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-controller.php b/src/RestApi/Version4/Controllers/Reports/Downloads.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-controller.php rename to src/RestApi/Version4/Controllers/Reports/Downloads.php index 9ce998461af..256117c37ca 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Downloads.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/downloads endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports downloads controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API Downloads Reports class. */ -class WC_Admin_REST_Reports_Downloads_Controller extends WC_Admin_REST_Reports_Controller { +class Downloads extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-import-controller.php b/src/RestApi/Version4/Controllers/Reports/Import.php similarity index 97% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-import-controller.php rename to src/RestApi/Version4/Controllers/Reports/Import.php index b0f16d997b4..26db4b41ce3 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-import-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Import.php @@ -4,18 +4,19 @@ * * Handles requests to /reports/import * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * Reports Imports controller. - * - * @package WooCommerce Admin/API - * @extends WC_REST_Data_Controller + * REST API Import Reports class. */ -class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Controller { +class Import extends Reports { /** * Endpoint namespace. * diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-orders-stats-controller.php b/src/RestApi/Version4/Controllers/Reports/OrderStats.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-orders-stats-controller.php rename to src/RestApi/Version4/Controllers/Reports/OrderStats.php index 33a2fc4aa87..4f60962102a 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-orders-stats-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/OrderStats.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/orders/stats endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports orders stats controller class. - * - * @package WooCommerce/API - * @extends WC_Admin_REST_Reports_Controller + * REST API OrderStats Reports class. */ -class WC_Admin_REST_Reports_Orders_Stats_Controller extends WC_Admin_REST_Reports_Controller { +class OrderStats extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-orders-controller.php b/src/RestApi/Version4/Controllers/Reports/Orders.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-orders-controller.php rename to src/RestApi/Version4/Controllers/Reports/Orders.php index 20535bd3632..2d7a8ec9f07 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-orders-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Orders.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/orders endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports orders controller class. - * - * @package WooCommerce/API - * @extends WC_Admin_REST_Reports_Controller + * REST API Orders Reports class. */ -class WC_Admin_REST_Reports_Orders_Controller extends WC_Admin_REST_Reports_Controller { +class Orders extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-performance-indicators-controller.php b/src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-performance-indicators-controller.php rename to src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php index 84ad882da6a..ebc0bf052ac 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-performance-indicators-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/PerformanceIndicators.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/store-performance endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports Performance indicators controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API PerformanceIndicators class. */ -class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Reports_Controller { +class PerformanceIndicators extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-products-stats-controller.php b/src/RestApi/Version4/Controllers/Reports/ProductStats.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-products-stats-controller.php rename to src/RestApi/Version4/Controllers/Reports/ProductStats.php index 3cfeb1c6f3c..acb4b42d6cc 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-products-stats-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/ProductStats.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/products/stats endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports products stats controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API ProductStats Reports class. */ -class WC_Admin_REST_Reports_Products_Stats_Controller extends WC_REST_Reports_Controller { +class ProductStats extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-products-controller.php b/src/RestApi/Version4/Controllers/Reports/Products.php similarity index 97% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-products-controller.php rename to src/RestApi/Version4/Controllers/Reports/Products.php index ef64c8aae10..214506b6bd8 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-products-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Products.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/products endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports products controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API Products Reports class. */ -class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controller { +class Products extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-revenue-stats-controller.php b/src/RestApi/Version4/Controllers/Reports/RevenueStats.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-revenue-stats-controller.php rename to src/RestApi/Version4/Controllers/Reports/RevenueStats.php index 33c78e1e35e..5533a211a6b 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-revenue-stats-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/RevenueStats.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/revenue/stats endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports revenue stats controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API RevenueStats Reports class. */ -class WC_Admin_REST_Reports_Revenue_Stats_Controller extends WC_REST_Reports_Controller { +class RevenueStats extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-stock-controller.php b/src/RestApi/Version4/Controllers/Reports/Stock.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-stock-controller.php rename to src/RestApi/Version4/Controllers/Reports/Stock.php index 7a4c4535f8c..9ff7535bf53 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-stock-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Stock.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/stock endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports stock controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API Stock Reports class. */ -class WC_Admin_REST_Reports_Stock_Controller extends WC_REST_Reports_Controller { +class Stock extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-stock-stats-controller.php b/src/RestApi/Version4/Controllers/Reports/StockStats.php similarity index 93% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-stock-stats-controller.php rename to src/RestApi/Version4/Controllers/Reports/StockStats.php index 6d3b091da56..101f90369f1 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-stock-stats-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/StockStats.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/stock/stats endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports stock stats controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API StockStats Reports class. */ -class WC_Admin_REST_Reports_Stock_Stats_Controller extends WC_REST_Reports_Controller { +class StockStats extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-taxes-stats-controller.php b/src/RestApi/Version4/Controllers/Reports/TaxStats.php similarity index 98% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-taxes-stats-controller.php rename to src/RestApi/Version4/Controllers/Reports/TaxStats.php index 35d7baf8e7e..ae81a1c2626 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-taxes-stats-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/TaxStats.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/taxes/stats endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports taxes stats controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API TaxesStats Reports class. */ -class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Controller { +class TaxStats extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-taxes-controller.php b/src/RestApi/Version4/Controllers/Reports/Taxes.php similarity index 97% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-taxes-controller.php rename to src/RestApi/Version4/Controllers/Reports/Taxes.php index b4f1ca1f968..2a68ba10266 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-taxes-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Taxes.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/taxes endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports taxes controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API Taxes Reports class. */ -class WC_Admin_REST_Reports_Taxes_Controller extends WC_REST_Reports_Controller { +class Taxes extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-variations-controller.php b/src/RestApi/Version4/Controllers/Reports/Variations.php similarity index 97% rename from src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-variations-controller.php rename to src/RestApi/Version4/Controllers/Reports/Variations.php index ed2ebb8818d..f2fed45f205 100644 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-variations-controller.php +++ b/src/RestApi/Version4/Controllers/Reports/Variations.php @@ -4,18 +4,19 @@ * * Handles requests to the /reports/products endpoint. * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Reports; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports; + /** - * REST API Reports products controller class. - * - * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * REST API Variations Reports class. */ -class WC_Admin_REST_Reports_Variations_Controller extends WC_REST_Reports_Controller { +class Variations extends Reports { /** * Endpoint namespace. diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-controller.php b/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-controller.php deleted file mode 100644 index 5cae9909de9..00000000000 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-controller.php +++ /dev/null @@ -1,303 +0,0 @@ -namespace, - '/' . $this->rest_base, - array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) - ); - } - - /** - * Check whether a given request has permission to read reports. - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|boolean - */ - public function get_items_permissions_check( $request ) { - if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); - } - - return true; - } - - - /** - * Get all reports. - * - * @param WP_REST_Request $request Request data. - * @return array|WP_Error - */ - public function get_items( $request ) { - $data = array(); - $reports = array( - array( - 'slug' => 'performance-indicators', - 'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ), - ), - array( - 'slug' => 'revenue/stats', - 'description' => __( 'Stats about revenue.', 'woocommerce' ), - ), - array( - 'slug' => 'orders/stats', - 'description' => __( 'Stats about orders.', 'woocommerce' ), - ), - array( - 'slug' => 'products', - 'description' => __( 'Products detailed reports.', 'woocommerce' ), - ), - array( - 'slug' => 'products/stats', - 'description' => __( 'Stats about products.', 'woocommerce' ), - ), - array( - 'slug' => 'categories', - 'description' => __( 'Product categories detailed reports.', 'woocommerce' ), - ), - array( - 'slug' => 'categories/stats', - 'description' => __( 'Stats about product categories.', 'woocommerce' ), - ), - array( - 'slug' => 'coupons', - 'description' => __( 'Coupons detailed reports.', 'woocommerce' ), - ), - array( - 'slug' => 'coupons/stats', - 'description' => __( 'Stats about coupons.', 'woocommerce' ), - ), - array( - 'slug' => 'taxes', - 'description' => __( 'Taxes detailed reports.', 'woocommerce' ), - ), - array( - 'slug' => 'taxes/stats', - 'description' => __( 'Stats about taxes.', 'woocommerce' ), - ), - array( - 'slug' => 'downloads', - 'description' => __( 'Product downloads detailed reports.', 'woocommerce' ), - ), - array( - 'slug' => 'downloads/files', - 'description' => __( 'Product download files detailed reports.', 'woocommerce' ), - ), - array( - 'slug' => 'downloads/stats', - 'description' => __( 'Stats about product downloads.', 'woocommerce' ), - ), - array( - 'slug' => 'customers', - 'description' => __( 'Customers detailed reports.', 'woocommerce' ), - ), - ); - - /** - * Filter the list of allowed reports, so that data can be loaded from third party extensions in addition to WooCommerce core. - * Array items should be in format of array( 'slug' => 'downloads/stats', 'description' => '', - * 'url' => '', and 'path' => '/wc-ext/v1/...'. - * - * @param array $endpoints The list of allowed reports.. - */ - $reports = apply_filters( 'woocommerce_admin_reports', $reports ); - - foreach ( $reports as $report ) { - if ( empty( $report['slug'] ) ) { - continue; - } - - if ( empty( $report['path'] ) ) { - $report['path'] = '/' . $this->namespace . '/reports/' . $report['slug']; - } - - // Allows a different admin page to be loaded here, - // or allows an empty url if no report exists for a set of performance indicators. - if ( ! isset( $report['url'] ) ) { - if ( '/stats' === substr( $report['slug'], -6 ) ) { - $url_slug = substr( $report['slug'], 0, -6 ); - } else { - $url_slug = $report['slug']; - } - - $report['url'] = '/analytics/' . $url_slug; - } - - $item = $this->prepare_item_for_response( (object) $report, $request ); - $data[] = $this->prepare_response_for_collection( $item ); - } - - return rest_ensure_response( $data ); - } - - /** - * Get the order number for an order. If no filter is present for `woocommerce_order_number`, we can just return the ID. - * Returns the parent order number if the order is actually a refund. - * - * @param int $order_id Order ID. - * @return string - */ - public function get_order_number( $order_id ) { - $order = wc_get_order( $order_id ); - - if ( 'shop_order_refund' === $order->get_type() ) { - $order = wc_get_order( $order->get_parent_id() ); - } - - if ( ! has_filter( 'woocommerce_order_number' ) ) { - return $order->get_id(); - } - - return $order->get_order_number(); - } - - /** - * Prepare a report object for serialization. - * - * @param stdClass $report Report data. - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response - */ - public function prepare_item_for_response( $report, $request ) { - $data = array( - 'slug' => $report->slug, - 'description' => $report->description, - 'path' => $report->path, - ); - - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); - - // Wrap the data in a response object. - $response = rest_ensure_response( $data ); - $response->add_links( - array( - 'self' => array( - 'href' => rest_url( $report->path ), - ), - 'report' => array( - 'href' => $report->url, - ), - 'collection' => array( - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), - ), - ) - ); - - /** - * Filter a report returned from the API. - * - * Allows modification of the report data right before it is returned. - * - * @param WP_REST_Response $response The response object. - * @param object $report The original report object. - * @param WP_REST_Request $request Request used to generate the response. - */ - return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request ); - } - - /** - * Get the Report's schema, conforming to JSON Schema. - * - * @return array - */ - public function get_item_schema() { - $schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'report', - 'type' => 'object', - 'properties' => array( - 'slug' => array( - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), - 'type' => 'string', - 'context' => array( 'view' ), - 'readonly' => true, - ), - 'description' => array( - 'description' => __( 'A human-readable description of the resource.', 'woocommerce' ), - 'type' => 'string', - 'context' => array( 'view' ), - 'readonly' => true, - ), - 'path' => array( - 'description' => __( 'API path.', 'woocommerce' ), - 'type' => 'string', - 'context' => array( 'view' ), - 'readonly' => true, - ), - ), - ); - - return $this->add_additional_fields_schema( $schema ); - } - - /** - * Get the query params for collections. - * - * @return array - */ - public function get_collection_params() { - return array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ); - } - - /** - * Get order statuses without prefixes. - * - * @return array - */ - public function get_order_statuses() { - $order_statuses = array(); - - foreach ( array_keys( wc_get_order_statuses() ) as $status ) { - $order_statuses[] = str_replace( 'wc-', '', $status ); - } - - return $order_statuses; - } -} diff --git a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-files-controller.php b/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-files-controller.php deleted file mode 100644 index d0f54fbdc66..00000000000 --- a/src/RestApi/Version4/Controllers/Reports/class-wc-admin-rest-reports-downloads-files-controller.php +++ /dev/null @@ -1,33 +0,0 @@ -