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rc.2 3.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 / Downloads / Stats / Controller.php
woocommerce / src / Admin / API / Reports / Downloads / Stats Last commit date
Controller.php 1 year ago DataStore.php 1 year ago Query.php 1 year ago
Controller.php
291 lines
1 <?php
2 /**
3 * REST API Reports downloads stats controller
4 *
5 * Handles requests to the /reports/downloads/stats endpoint.
6 */
7
8 namespace Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use Automattic\WooCommerce\Admin\API\Reports\GenericQuery;
13 use Automattic\WooCommerce\Admin\API\Reports\GenericStatsController;
14 use WP_REST_Request;
15 use WP_REST_Response;
16
17 /**
18 * REST API Reports downloads stats controller class.
19 *
20 * @internal
21 * @extends GenericStatsController
22 */
23 class Controller extends GenericStatsController {
24
25 /**
26 * Route base.
27 *
28 * @var string
29 */
30 protected $rest_base = 'reports/downloads/stats';
31
32 /**
33 * Maps query arguments from the REST request.
34 *
35 * @param array $request Request array.
36 * @return array
37 */
38 protected function prepare_reports_query( $request ) {
39 $args = array();
40 $args['before'] = $request['before'];
41 $args['after'] = $request['after'];
42 $args['interval'] = $request['interval'];
43 $args['page'] = $request['page'];
44 $args['per_page'] = $request['per_page'];
45 $args['orderby'] = $request['orderby'];
46 $args['order'] = $request['order'];
47 $args['match'] = $request['match'];
48 $args['product_includes'] = (array) $request['product_includes'];
49 $args['product_excludes'] = (array) $request['product_excludes'];
50 $args['customer_includes'] = (array) $request['customer_includes'];
51 $args['customer_excludes'] = (array) $request['customer_excludes'];
52 $args['order_includes'] = (array) $request['order_includes'];
53 $args['order_excludes'] = (array) $request['order_excludes'];
54 $args['ip_address_includes'] = (array) $request['ip_address_includes'];
55 $args['ip_address_excludes'] = (array) $request['ip_address_excludes'];
56 $args['fields'] = $request['fields'];
57 $args['force_cache_refresh'] = $request['force_cache_refresh'];
58
59 return $args;
60 }
61
62 /**
63 * Get data from `'downloads-stats'` GenericQuery.
64 *
65 * @override GenericController::get_datastore_data()
66 *
67 * @param array $query_args Query arguments.
68 * @return mixed Results from the data store.
69 */
70 protected function get_datastore_data( $query_args = array() ) {
71 $query = new GenericQuery( $query_args, 'downloads-stats' );
72 return $query->get_data();
73 }
74
75 /**
76 * Prepare a report data item for serialization.
77 *
78 * @param array $report Report data item as returned from Data Store.
79 * @param WP_REST_Request $request Request object.
80 * @return WP_REST_Response
81 */
82 public function prepare_item_for_response( $report, $request ) {
83 $response = parent::prepare_item_for_response( $report, $request );
84
85 /**
86 * Filter a report returned from the API.
87 *
88 * Allows modification of the report data right before it is returned.
89 *
90 * @param WP_REST_Response $response The response object.
91 * @param object $report The original report object.
92 * @param WP_REST_Request $request Request used to generate the response.
93 */
94 return apply_filters( 'woocommerce_rest_prepare_report_downloads_stats', $response, $report, $request );
95 }
96
97 /**
98 * Get the Report's item properties schema.
99 * Will be used by `get_item_schema` as `totals` and `subtotals`.
100 *
101 * @return array
102 */
103 protected function get_item_properties_schema() {
104 return array(
105 'download_count' => array(
106 'title' => __( 'Downloads', 'woocommerce' ),
107 'description' => __( 'Number of downloads.', 'woocommerce' ),
108 'type' => 'number',
109 'context' => array( 'view', 'edit' ),
110 'readonly' => true,
111 'indicator' => true,
112 ),
113 );
114 }
115
116 /**
117 * Get the Report's schema, conforming to JSON Schema.
118 * It does not have the segments as in GenericStatsController.
119 *
120 * @return array
121 */
122 public function get_item_schema() {
123 $totals = $this->get_item_properties_schema();
124
125 $schema = array(
126 '$schema' => 'http://json-schema.org/draft-04/schema#',
127 'title' => 'report_orders_stats',
128 'type' => 'object',
129 'properties' => array(
130 'totals' => array(
131 'description' => __( 'Totals data.', 'woocommerce' ),
132 'type' => 'object',
133 'context' => array( 'view', 'edit' ),
134 'readonly' => true,
135 'properties' => $totals,
136 ),
137 'intervals' => array(
138 'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ),
139 'type' => 'array',
140 'context' => array( 'view', 'edit' ),
141 'readonly' => true,
142 'items' => array(
143 'type' => 'object',
144 'properties' => array(
145 'interval' => array(
146 'description' => __( 'Type of interval.', 'woocommerce' ),
147 'type' => 'string',
148 'context' => array( 'view', 'edit' ),
149 'readonly' => true,
150 'enum' => array( 'day', 'week', 'month', 'year' ),
151 ),
152 'date_start' => array(
153 'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ),
154 'type' => 'date-time',
155 'context' => array( 'view', 'edit' ),
156 'readonly' => true,
157 ),
158 'date_start_gmt' => array(
159 'description' => __( 'The date the report start, as GMT.', 'woocommerce' ),
160 'type' => 'date-time',
161 'context' => array( 'view', 'edit' ),
162 'readonly' => true,
163 ),
164 'date_end' => array(
165 'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ),
166 'type' => 'date-time',
167 'context' => array( 'view', 'edit' ),
168 'readonly' => true,
169 ),
170 'date_end_gmt' => array(
171 'description' => __( 'The date the report end, as GMT.', 'woocommerce' ),
172 'type' => 'date-time',
173 'context' => array( 'view', 'edit' ),
174 'readonly' => true,
175 ),
176 'subtotals' => array(
177 'description' => __( 'Interval subtotals.', 'woocommerce' ),
178 'type' => 'object',
179 'context' => array( 'view', 'edit' ),
180 'readonly' => true,
181 'properties' => $totals,
182 ),
183 ),
184 ),
185 ),
186 ),
187 );
188
189 return $this->add_additional_fields_schema( $schema );
190 }
191
192 /**
193 * Get the query params for collections.
194 *
195 * @return array
196 */
197 public function get_collection_params() {
198 $params = parent::get_collection_params();
199 $params['orderby']['enum'] = $this->apply_custom_orderby_filters(
200 array(
201 'date',
202 'download_count',
203 )
204 );
205 $params['match'] = array(
206 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ),
207 'type' => 'string',
208 'default' => 'all',
209 'enum' => array(
210 'all',
211 'any',
212 ),
213 'validate_callback' => 'rest_validate_request_arg',
214 );
215 $params['product_includes'] = array(
216 'description' => __( 'Limit result set to items that have the specified product(s) assigned.', 'woocommerce' ),
217 'type' => 'array',
218 'items' => array(
219 'type' => 'integer',
220 ),
221 'default' => array(),
222 'sanitize_callback' => 'wp_parse_id_list',
223
224 );
225 $params['product_excludes'] = array(
226 'description' => __( 'Limit result set to items that don\'t have the specified product(s) assigned.', 'woocommerce' ),
227 'type' => 'array',
228 'items' => array(
229 'type' => 'integer',
230 ),
231 'default' => array(),
232 'sanitize_callback' => 'wp_parse_id_list',
233 );
234 $params['order_includes'] = array(
235 'description' => __( 'Limit result set to items that have the specified order ids.', 'woocommerce' ),
236 'type' => 'array',
237 'sanitize_callback' => 'wp_parse_id_list',
238 'validate_callback' => 'rest_validate_request_arg',
239 'items' => array(
240 'type' => 'integer',
241 ),
242 );
243 $params['order_excludes'] = array(
244 'description' => __( 'Limit result set to items that don\'t have the specified order ids.', 'woocommerce' ),
245 'type' => 'array',
246 'sanitize_callback' => 'wp_parse_id_list',
247 'validate_callback' => 'rest_validate_request_arg',
248 'items' => array(
249 'type' => 'integer',
250 ),
251 );
252 $params['customer_includes'] = array(
253 'description' => __( 'Limit response to objects that have the specified customer ids.', 'woocommerce' ),
254 'type' => 'array',
255 'sanitize_callback' => 'wp_parse_id_list',
256 'validate_callback' => 'rest_validate_request_arg',
257 'items' => array(
258 'type' => 'integer',
259 ),
260 );
261 $params['customer_excludes'] = array(
262 'description' => __( 'Limit response to objects that don\'t have the specified customer ids.', 'woocommerce' ),
263 'type' => 'array',
264 'sanitize_callback' => 'wp_parse_id_list',
265 'validate_callback' => 'rest_validate_request_arg',
266 'items' => array(
267 'type' => 'integer',
268 ),
269 );
270 $params['ip_address_includes'] = array(
271 'description' => __( 'Limit response to objects that have a specified ip address.', 'woocommerce' ),
272 'type' => 'array',
273 'validate_callback' => 'rest_validate_request_arg',
274 'items' => array(
275 'type' => 'string',
276 ),
277 );
278
279 $params['ip_address_excludes'] = array(
280 'description' => __( 'Limit response to objects that don\'t have a specified ip address.', 'woocommerce' ),
281 'type' => 'array',
282 'validate_callback' => 'rest_validate_request_arg',
283 'items' => array(
284 'type' => 'string',
285 ),
286 );
287
288 return $params;
289 }
290 }
291