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.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Admin / API / Reports / Controller.php
woocommerce / src / Admin / API / Reports Last commit date
Categories 4 weeks ago Coupons 4 weeks ago Customers 2 months ago Downloads 1 year ago Export 3 years ago Import 3 years ago Orders 4 weeks ago PerformanceIndicators 9 months ago Products 4 weeks ago Revenue 3 months ago Stock 4 months ago Taxes 4 weeks ago Variations 4 weeks ago Cache.php 4 years ago Controller.php 11 months ago DataStore.php 4 weeks ago DataStoreInterface.php 4 years ago ExportableInterface.php 4 years ago ExportableTraits.php 4 years ago FilteredGetDataTrait.php 1 year ago GenericController.php 1 year ago GenericQuery.php 1 year ago GenericStatsController.php 1 year ago OrderAwareControllerTrait.php 1 year ago ParameterException.php 4 years ago Query.php 1 year ago Segmenter.php 1 year ago SqlQuery.php 3 years ago StatsDataStoreTrait.php 1 year ago TimeInterval.php 2 years ago
Controller.php
236 lines
1 <?php
2 /**
3 * REST API Reports controller extended to handle requests to the reports endpoint.
4 */
5
6 namespace Automattic\WooCommerce\Admin\API\Reports;
7
8 defined( 'ABSPATH' ) || exit;
9
10 use Automattic\WooCommerce\Admin\API\Reports\GenericController;
11 use Automattic\WooCommerce\Admin\API\Reports\OrderAwareControllerTrait;
12
13 /**
14 * Reports controller class.
15 *
16 * Controller that handles the endpoint that returns all available analytics endpoints.
17 *
18 * @internal
19 * @extends GenericController
20 */
21 class Controller extends GenericController {
22
23 use OrderAwareControllerTrait;
24
25 /**
26 * Get all reports.
27 *
28 * @param WP_REST_Request $request Request data.
29 * @return array|WP_Error
30 */
31 public function get_items( $request ) {
32 $data = array();
33 $reports = array(
34 array(
35 'slug' => 'performance-indicators',
36 'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ),
37 ),
38 array(
39 'slug' => 'revenue/stats',
40 'description' => __( 'Stats about revenue.', 'woocommerce' ),
41 ),
42 array(
43 'slug' => 'orders/stats',
44 'description' => __( 'Stats about orders.', 'woocommerce' ),
45 ),
46 array(
47 'slug' => 'products',
48 'description' => __( 'Products detailed reports.', 'woocommerce' ),
49 ),
50 array(
51 'slug' => 'products/stats',
52 'description' => __( 'Stats about products.', 'woocommerce' ),
53 ),
54 array(
55 'slug' => 'variations',
56 'description' => __( 'Variations detailed reports.', 'woocommerce' ),
57 ),
58 array(
59 'slug' => 'variations/stats',
60 'description' => __( 'Stats about variations.', 'woocommerce' ),
61 ),
62 array(
63 'slug' => 'categories',
64 'description' => __( 'Product categories detailed reports.', 'woocommerce' ),
65 ),
66 array(
67 'slug' => 'categories/stats',
68 'description' => __( 'Stats about product categories.', 'woocommerce' ),
69 ),
70 array(
71 'slug' => 'coupons',
72 'description' => __( 'Coupons detailed reports.', 'woocommerce' ),
73 ),
74 array(
75 'slug' => 'coupons/stats',
76 'description' => __( 'Stats about coupons.', 'woocommerce' ),
77 ),
78 array(
79 'slug' => 'taxes',
80 'description' => __( 'Taxes detailed reports.', 'woocommerce' ),
81 ),
82 array(
83 'slug' => 'taxes/stats',
84 'description' => __( 'Stats about taxes.', 'woocommerce' ),
85 ),
86 array(
87 'slug' => 'downloads',
88 'description' => __( 'Product downloads detailed reports.', 'woocommerce' ),
89 ),
90 array(
91 'slug' => 'downloads/files',
92 'description' => __( 'Product download files detailed reports.', 'woocommerce' ),
93 ),
94 array(
95 'slug' => 'downloads/stats',
96 'description' => __( 'Stats about product downloads.', 'woocommerce' ),
97 ),
98 array(
99 'slug' => 'customers',
100 'description' => __( 'Customers detailed reports.', 'woocommerce' ),
101 ),
102 array(
103 'slug' => 'customers/stats',
104 'description' => __( 'Stats about groups of customers.', 'woocommerce' ),
105 ),
106 );
107
108 /**
109 * Filter the list of allowed reports, so that data can be loaded from third party extensions in addition to WooCommerce core.
110 * Array items should be in format of array( 'slug' => 'downloads/stats', 'description' => '',
111 * 'url' => '', and 'path' => '/wc-ext/v1/...'.
112 *
113 * @param array $endpoints The list of allowed reports..
114 */
115 $reports = apply_filters( 'woocommerce_admin_reports', $reports );
116
117 foreach ( $reports as $report ) {
118 // Silently skip non-compliant reports. Like the ones for WC_Admin_Reports::get_reports().
119 if ( empty( $report['slug'] ) ) {
120 continue;
121 }
122
123 if ( empty( $report['path'] ) ) {
124 $report['path'] = '/' . $this->namespace . '/reports/' . $report['slug'];
125 }
126
127 // Allows a different admin page to be loaded here,
128 // or allows an empty url if no report exists for a set of performance indicators.
129 if ( ! isset( $report['url'] ) ) {
130 if ( '/stats' === substr( $report['slug'], -6 ) ) {
131 $url_slug = substr( $report['slug'], 0, -6 );
132 } else {
133 $url_slug = $report['slug'];
134 }
135
136 $report['url'] = '/analytics/' . $url_slug;
137 }
138
139 $item = $this->prepare_item_for_response( (object) $report, $request );
140 $data[] = $this->prepare_response_for_collection( $item );
141 }
142
143 return rest_ensure_response( $data );
144 }
145
146 /**
147 * Prepare a report object for serialization.
148 *
149 * @param stdClass $report Report data.
150 * @param WP_REST_Request $request Request object.
151 * @return WP_REST_Response
152 */
153 public function prepare_item_for_response( $report, $request ) {
154 $data = array(
155 'slug' => $report->slug,
156 'description' => $report->description,
157 'path' => $report->path,
158 );
159
160 // Wrap the data in a response object.
161 $response = parent::prepare_item_for_response( $data, $request );
162 $response->add_links(
163 array(
164 'self' => array(
165 'href' => rest_url( $report->path ),
166 ),
167 'report' => array(
168 'href' => $report->url,
169 ),
170 'collection' => array(
171 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
172 ),
173 )
174 );
175
176 /**
177 * Filter a report returned from the API.
178 *
179 * Allows modification of the report data right before it is returned.
180 *
181 * @param WP_REST_Response $response The response object.
182 * @param object $report The original report object.
183 * @param WP_REST_Request $request Request used to generate the response.
184 */
185 return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request );
186 }
187
188 /**
189 * Get the Report's schema, conforming to JSON Schema.
190 *
191 * @override WP_REST_Controller::get_item_schema()
192 *
193 * @return array
194 */
195 public function get_item_schema() {
196 $schema = array(
197 '$schema' => 'http://json-schema.org/draft-04/schema#',
198 'title' => 'report',
199 'type' => 'object',
200 'properties' => array(
201 'slug' => array(
202 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
203 'type' => 'string',
204 'context' => array( 'view' ),
205 'readonly' => true,
206 ),
207 'description' => array(
208 'description' => __( 'A human-readable description of the resource.', 'woocommerce' ),
209 'type' => 'string',
210 'context' => array( 'view' ),
211 'readonly' => true,
212 ),
213 'path' => array(
214 'description' => __( 'API path.', 'woocommerce' ),
215 'type' => 'string',
216 'context' => array( 'view' ),
217 'readonly' => true,
218 ),
219 ),
220 );
221
222 return $this->add_additional_fields_schema( $schema );
223 }
224
225 /**
226 * Get the query params for collections.
227 *
228 * @return array
229 */
230 public function get_collection_params() {
231 return array(
232 'context' => $this->get_context_param( array( 'default' => 'view' ) ),
233 );
234 }
235 }
236