Passed
Push — master ( 8eea4e...c5db5f )
by Brian
05:55 queued 24s
created
includes/class-wpinv-api.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since    1.0.19
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * The main API class
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         $this->top_earners = new GetPaid_REST_Report_Top_Earners_Controller();
89 89
 
90 90
         // Fires after loading the rest api.
91
-        do_action( 'getpaid_rest_api_loaded', $this );
91
+        do_action('getpaid_rest_api_loaded', $this);
92 92
     }
93 93
 
94 94
 }
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-report-top-earners-controller.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -18,50 +18,50 @@
 block discarded – undo
18 18
  */
19 19
 class GetPaid_REST_Report_Top_Earners_Controller extends GetPaid_REST_Report_Top_Sellers_Controller {
20 20
 
21
-	/**
22
-	 * Route base.
23
-	 *
24
-	 * @var string
25
-	 */
26
-	protected $rest_base = 'reports/top_earners';
21
+    /**
22
+     * Route base.
23
+     *
24
+     * @var string
25
+     */
26
+    protected $rest_base = 'reports/top_earners';
27 27
 
28
-	/**
29
-	 * Get all data needed for this report and store in the class.
30
-	 */
31
-	protected function query_report_data() {
28
+    /**
29
+     * Get all data needed for this report and store in the class.
30
+     */
31
+    protected function query_report_data() {
32 32
 
33
-		$this->report_data = GetPaid_Reports_Helper::get_invoice_report_data(
34
-			array(
35
-				'data'              => array(
36
-					'quantity'      => array(
37
-						'type'            => 'invoice_item',
38
-						'function'        => 'SUM',
39
-						'name'            => 'invoice_item_qty',
40
-					),
41
-					'item_id'             => array(
42
-						'type'            => 'invoice_item',
43
-						'function'        => '',
44
-						'name'            => 'invoice_item_id',
45
-					),
46
-					'item_name'           => array(
47
-						'type'            => 'invoice_item',
48
-						'function'        => '',
49
-						'name'            => 'invoice_item_name',
50
-					),
51
-					'price'               => array(
52
-						'type'            => 'invoice_item',
53
-						'function'        => 'SUM',
54
-						'name'            => 'invoice_item_price',
55
-					),
56
-				),
57
-				'group_by'       => 'invoice_item_id',
58
-				'order_by'       => 'invoice_item_price DESC',
59
-				'query_type'     => 'get_results',
60
-				'limit'          => 10,
61
-				'filter_range'   => $this->report_range,
62
-			)
63
-		);
33
+        $this->report_data = GetPaid_Reports_Helper::get_invoice_report_data(
34
+            array(
35
+                'data'              => array(
36
+                    'quantity'      => array(
37
+                        'type'            => 'invoice_item',
38
+                        'function'        => 'SUM',
39
+                        'name'            => 'invoice_item_qty',
40
+                    ),
41
+                    'item_id'             => array(
42
+                        'type'            => 'invoice_item',
43
+                        'function'        => '',
44
+                        'name'            => 'invoice_item_id',
45
+                    ),
46
+                    'item_name'           => array(
47
+                        'type'            => 'invoice_item',
48
+                        'function'        => '',
49
+                        'name'            => 'invoice_item_name',
50
+                    ),
51
+                    'price'               => array(
52
+                        'type'            => 'invoice_item',
53
+                        'function'        => 'SUM',
54
+                        'name'            => 'invoice_item_price',
55
+                    ),
56
+                ),
57
+                'group_by'       => 'invoice_item_id',
58
+                'order_by'       => 'invoice_item_price DESC',
59
+                'query_type'     => 'get_results',
60
+                'limit'          => 10,
61
+                'filter_range'   => $this->report_range,
62
+            )
63
+        );
64 64
 
65
-	}
65
+    }
66 66
 
67 67
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
  * @since   2.0.0
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * GetPaid REST top earners controller class.
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-reports-controller.php 2 patches
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -18,188 +18,188 @@
 block discarded – undo
18 18
  */
19 19
 class GetPaid_REST_Reports_Controller extends GetPaid_REST_Controller {
20 20
 
21
-	/**
22
-	 * Route base.
23
-	 *
24
-	 * @var string
25
-	 */
26
-	protected $rest_base = 'reports';
27
-
28
-	/**
29
-	 * Registers the routes for the objects of the controller.
30
-	 *
31
-	 * @since 2.0.0
32
-	 *
33
-	 * @see register_rest_route()
34
-	 */
35
-	public function register_namespace_routes( $namespace ) {
36
-
37
-		// List all available reports.
38
-		register_rest_route(
39
-			$namespace,
40
-			$this->rest_base,
41
-			array(
42
-				array(
43
-					'methods'             => WP_REST_Server::READABLE,
44
-					'callback'            => array( $this, 'get_items' ),
45
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
46
-					'args'                => $this->get_collection_params(),
47
-				),
48
-				'schema' => array( $this, 'get_public_item_schema' ),
49
-			)
50
-		);
51
-
52
-	}
53
-
54
-	/**
55
-	 * Makes sure the current user has access to READ the report APIs.
56
-	 *
57
-	 * @since  2.0.0
58
-	 * @param WP_REST_Request $request Full data about the request.
59
-	 * @return WP_Error|boolean
60
-	 */
61
-	public function get_items_permissions_check( $request ) {
62
-
63
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
64
-			return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
65
-		}
66
-
67
-		return true;
68
-	}
69
-
70
-	/**
71
-	 * Get reports list.
72
-	 *
73
-	 * @since 2.0.0
74
-	 * @return array
75
-	 */
76
-	protected function get_reports() {
77
-
78
-		$reports = array(
79
-			array(
80
-				'slug'        => 'sales',
81
-				'description' => __( 'List of sales reports.', 'invoicing' ),
82
-			),
83
-			array(
84
-				'slug'        => 'top_sellers',
85
-				'description' => __( 'List of top selling items.', 'invoicing' ),
86
-			),
87
-			array(
88
-				'slug'        => 'top_earners',
89
-				'description' => __( 'List of top earning items.', 'invoicing' ),
90
-			),
91
-			array(
92
-				'slug'        => 'invoices/totals',
93
-				'description' => __( 'Invoice totals.', 'invoicing' ),
94
-			),
95
-			array(
96
-				'slug'        => 'items/totals',
97
-				'description' => __( 'Item totals.', 'invoicing' ),
98
-			),
99
-			array(
100
-				'slug'        => 'customers/totals',
101
-				'description' => __( 'Customer totals.', 'invoicing' ),
102
-			),
103
-			array(
104
-				'slug'        => 'discounts/totals',
105
-				'description' => __( 'Discount totals.', 'invoicing' ),
106
-			)
107
-		);
108
-
109
-		return apply_filters( 'getpaid_available_api_reports', $reports );
110
-
111
-	}
112
-
113
-	/**
114
-	 * Get all reports.
115
-	 *
116
-	 * @since 2.0.0
117
-	 * @param WP_REST_Request $request
118
-	 * @return array|WP_Error
119
-	 */
120
-	public function get_items( $request ) {
121
-		$data    = array();
122
-		$reports = $this->get_reports();
123
-
124
-		foreach ( $reports as $report ) {
125
-			$item   = $this->prepare_item_for_response( (object) $report, $request );
126
-			$data[] = $this->prepare_response_for_collection( $item );
127
-		}
128
-
129
-		return rest_ensure_response( $data );
130
-	}
131
-
132
-	/**
133
-	 * Prepare a report object for serialization.
134
-	 *
135
-	 * @since 2.0.0
136
-	 * @param stdClass $report Report data.
137
-	 * @param WP_REST_Request $request Request object.
138
-	 * @return WP_REST_Response $response Response data.
139
-	 */
140
-	public function prepare_item_for_response( $report, $request ) {
141
-		$data = array(
142
-			'slug'        => $report->slug,
143
-			'description' => $report->description,
144
-		);
145
-
146
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
147
-		$data = $this->add_additional_fields_to_object( $data, $request );
148
-		$data = $this->filter_response_by_context( $data, $context );
149
-
150
-		// Wrap the data in a response object.
151
-		$response = rest_ensure_response( $data );
152
-		$response->add_links( array(
153
-			'self' => array(
154
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $report->slug ) ),
155
-			),
156
-			'collection' => array(
157
-				'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
158
-			),
159
-		) );
160
-
161
-		return apply_filters( 'getpaid_rest_prepare_report', $response, $report, $request );
162
-	}
163
-
164
-	/**
165
-	 * Get the Report's schema, conforming to JSON Schema.
166
-	 *
167
-	 * @since 2.0.0
168
-	 * @return array
169
-	 */
170
-	public function get_item_schema() {
171
-		$schema = array(
172
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
173
-			'title'      => 'report',
174
-			'type'       => 'object',
175
-			'properties' => array(
176
-				'slug' => array(
177
-					'description' => __( 'An alphanumeric identifier for the resource.', 'invoicing' ),
178
-					'type'        => 'string',
179
-					'context'     => array( 'view' ),
180
-					'readonly'    => true,
181
-				),
182
-				'description' => array(
183
-					'description' => __( 'A human-readable description of the resource.', 'invoicing' ),
184
-					'type'        => 'string',
185
-					'context'     => array( 'view' ),
186
-					'readonly'    => true,
187
-				),
188
-			),
189
-		);
190
-
191
-		return $this->add_additional_fields_schema( $schema );
192
-	}
193
-
194
-	/**
195
-	 * Get the query params for collections.
196
-	 *
197
-	 * @since 2.0.0
198
-	 * @return array
199
-	 */
200
-	public function get_collection_params() {
201
-		return array(
202
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
203
-		);
204
-	}
21
+    /**
22
+     * Route base.
23
+     *
24
+     * @var string
25
+     */
26
+    protected $rest_base = 'reports';
27
+
28
+    /**
29
+     * Registers the routes for the objects of the controller.
30
+     *
31
+     * @since 2.0.0
32
+     *
33
+     * @see register_rest_route()
34
+     */
35
+    public function register_namespace_routes( $namespace ) {
36
+
37
+        // List all available reports.
38
+        register_rest_route(
39
+            $namespace,
40
+            $this->rest_base,
41
+            array(
42
+                array(
43
+                    'methods'             => WP_REST_Server::READABLE,
44
+                    'callback'            => array( $this, 'get_items' ),
45
+                    'permission_callback' => array( $this, 'get_items_permissions_check' ),
46
+                    'args'                => $this->get_collection_params(),
47
+                ),
48
+                'schema' => array( $this, 'get_public_item_schema' ),
49
+            )
50
+        );
51
+
52
+    }
53
+
54
+    /**
55
+     * Makes sure the current user has access to READ the report APIs.
56
+     *
57
+     * @since  2.0.0
58
+     * @param WP_REST_Request $request Full data about the request.
59
+     * @return WP_Error|boolean
60
+     */
61
+    public function get_items_permissions_check( $request ) {
62
+
63
+        if ( ! wpinv_current_user_can_manage_invoicing() ) {
64
+            return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
65
+        }
66
+
67
+        return true;
68
+    }
69
+
70
+    /**
71
+     * Get reports list.
72
+     *
73
+     * @since 2.0.0
74
+     * @return array
75
+     */
76
+    protected function get_reports() {
77
+
78
+        $reports = array(
79
+            array(
80
+                'slug'        => 'sales',
81
+                'description' => __( 'List of sales reports.', 'invoicing' ),
82
+            ),
83
+            array(
84
+                'slug'        => 'top_sellers',
85
+                'description' => __( 'List of top selling items.', 'invoicing' ),
86
+            ),
87
+            array(
88
+                'slug'        => 'top_earners',
89
+                'description' => __( 'List of top earning items.', 'invoicing' ),
90
+            ),
91
+            array(
92
+                'slug'        => 'invoices/totals',
93
+                'description' => __( 'Invoice totals.', 'invoicing' ),
94
+            ),
95
+            array(
96
+                'slug'        => 'items/totals',
97
+                'description' => __( 'Item totals.', 'invoicing' ),
98
+            ),
99
+            array(
100
+                'slug'        => 'customers/totals',
101
+                'description' => __( 'Customer totals.', 'invoicing' ),
102
+            ),
103
+            array(
104
+                'slug'        => 'discounts/totals',
105
+                'description' => __( 'Discount totals.', 'invoicing' ),
106
+            )
107
+        );
108
+
109
+        return apply_filters( 'getpaid_available_api_reports', $reports );
110
+
111
+    }
112
+
113
+    /**
114
+     * Get all reports.
115
+     *
116
+     * @since 2.0.0
117
+     * @param WP_REST_Request $request
118
+     * @return array|WP_Error
119
+     */
120
+    public function get_items( $request ) {
121
+        $data    = array();
122
+        $reports = $this->get_reports();
123
+
124
+        foreach ( $reports as $report ) {
125
+            $item   = $this->prepare_item_for_response( (object) $report, $request );
126
+            $data[] = $this->prepare_response_for_collection( $item );
127
+        }
128
+
129
+        return rest_ensure_response( $data );
130
+    }
131
+
132
+    /**
133
+     * Prepare a report object for serialization.
134
+     *
135
+     * @since 2.0.0
136
+     * @param stdClass $report Report data.
137
+     * @param WP_REST_Request $request Request object.
138
+     * @return WP_REST_Response $response Response data.
139
+     */
140
+    public function prepare_item_for_response( $report, $request ) {
141
+        $data = array(
142
+            'slug'        => $report->slug,
143
+            'description' => $report->description,
144
+        );
145
+
146
+        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
147
+        $data = $this->add_additional_fields_to_object( $data, $request );
148
+        $data = $this->filter_response_by_context( $data, $context );
149
+
150
+        // Wrap the data in a response object.
151
+        $response = rest_ensure_response( $data );
152
+        $response->add_links( array(
153
+            'self' => array(
154
+                'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $report->slug ) ),
155
+            ),
156
+            'collection' => array(
157
+                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
158
+            ),
159
+        ) );
160
+
161
+        return apply_filters( 'getpaid_rest_prepare_report', $response, $report, $request );
162
+    }
163
+
164
+    /**
165
+     * Get the Report's schema, conforming to JSON Schema.
166
+     *
167
+     * @since 2.0.0
168
+     * @return array
169
+     */
170
+    public function get_item_schema() {
171
+        $schema = array(
172
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
173
+            'title'      => 'report',
174
+            'type'       => 'object',
175
+            'properties' => array(
176
+                'slug' => array(
177
+                    'description' => __( 'An alphanumeric identifier for the resource.', 'invoicing' ),
178
+                    'type'        => 'string',
179
+                    'context'     => array( 'view' ),
180
+                    'readonly'    => true,
181
+                ),
182
+                'description' => array(
183
+                    'description' => __( 'A human-readable description of the resource.', 'invoicing' ),
184
+                    'type'        => 'string',
185
+                    'context'     => array( 'view' ),
186
+                    'readonly'    => true,
187
+                ),
188
+            ),
189
+        );
190
+
191
+        return $this->add_additional_fields_schema( $schema );
192
+    }
193
+
194
+    /**
195
+     * Get the query params for collections.
196
+     *
197
+     * @since 2.0.0
198
+     * @return array
199
+     */
200
+    public function get_collection_params() {
201
+        return array(
202
+            'context' => $this->get_context_param( array( 'default' => 'view' ) ),
203
+        );
204
+    }
205 205
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @since   2.0.0
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * GetPaid REST reports controller class.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @see register_rest_route()
34 34
 	 */
35
-	public function register_namespace_routes( $namespace ) {
35
+	public function register_namespace_routes($namespace) {
36 36
 
37 37
 		// List all available reports.
38 38
 		register_rest_route(
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
 			array(
42 42
 				array(
43 43
 					'methods'             => WP_REST_Server::READABLE,
44
-					'callback'            => array( $this, 'get_items' ),
45
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
44
+					'callback'            => array($this, 'get_items'),
45
+					'permission_callback' => array($this, 'get_items_permissions_check'),
46 46
 					'args'                => $this->get_collection_params(),
47 47
 				),
48
-				'schema' => array( $this, 'get_public_item_schema' ),
48
+				'schema' => array($this, 'get_public_item_schema'),
49 49
 			)
50 50
 		);
51 51
 
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
 	 * @param WP_REST_Request $request Full data about the request.
59 59
 	 * @return WP_Error|boolean
60 60
 	 */
61
-	public function get_items_permissions_check( $request ) {
61
+	public function get_items_permissions_check($request) {
62 62
 
63
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
64
-			return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
63
+		if (!wpinv_current_user_can_manage_invoicing()) {
64
+			return new WP_Error('rest_cannot_view', __('Sorry, you cannot list resources.', 'invoicing'), array('status' => rest_authorization_required_code()));
65 65
 		}
66 66
 
67 67
 		return true;
@@ -78,35 +78,35 @@  discard block
 block discarded – undo
78 78
 		$reports = array(
79 79
 			array(
80 80
 				'slug'        => 'sales',
81
-				'description' => __( 'List of sales reports.', 'invoicing' ),
81
+				'description' => __('List of sales reports.', 'invoicing'),
82 82
 			),
83 83
 			array(
84 84
 				'slug'        => 'top_sellers',
85
-				'description' => __( 'List of top selling items.', 'invoicing' ),
85
+				'description' => __('List of top selling items.', 'invoicing'),
86 86
 			),
87 87
 			array(
88 88
 				'slug'        => 'top_earners',
89
-				'description' => __( 'List of top earning items.', 'invoicing' ),
89
+				'description' => __('List of top earning items.', 'invoicing'),
90 90
 			),
91 91
 			array(
92 92
 				'slug'        => 'invoices/totals',
93
-				'description' => __( 'Invoice totals.', 'invoicing' ),
93
+				'description' => __('Invoice totals.', 'invoicing'),
94 94
 			),
95 95
 			array(
96 96
 				'slug'        => 'items/totals',
97
-				'description' => __( 'Item totals.', 'invoicing' ),
97
+				'description' => __('Item totals.', 'invoicing'),
98 98
 			),
99 99
 			array(
100 100
 				'slug'        => 'customers/totals',
101
-				'description' => __( 'Customer totals.', 'invoicing' ),
101
+				'description' => __('Customer totals.', 'invoicing'),
102 102
 			),
103 103
 			array(
104 104
 				'slug'        => 'discounts/totals',
105
-				'description' => __( 'Discount totals.', 'invoicing' ),
105
+				'description' => __('Discount totals.', 'invoicing'),
106 106
 			)
107 107
 		);
108 108
 
109
-		return apply_filters( 'getpaid_available_api_reports', $reports );
109
+		return apply_filters('getpaid_available_api_reports', $reports);
110 110
 
111 111
 	}
112 112
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
 	 * @param WP_REST_Request $request
118 118
 	 * @return array|WP_Error
119 119
 	 */
120
-	public function get_items( $request ) {
120
+	public function get_items($request) {
121 121
 		$data    = array();
122 122
 		$reports = $this->get_reports();
123 123
 
124
-		foreach ( $reports as $report ) {
125
-			$item   = $this->prepare_item_for_response( (object) $report, $request );
126
-			$data[] = $this->prepare_response_for_collection( $item );
124
+		foreach ($reports as $report) {
125
+			$item   = $this->prepare_item_for_response((object) $report, $request);
126
+			$data[] = $this->prepare_response_for_collection($item);
127 127
 		}
128 128
 
129
-		return rest_ensure_response( $data );
129
+		return rest_ensure_response($data);
130 130
 	}
131 131
 
132 132
 	/**
@@ -137,28 +137,28 @@  discard block
 block discarded – undo
137 137
 	 * @param WP_REST_Request $request Request object.
138 138
 	 * @return WP_REST_Response $response Response data.
139 139
 	 */
140
-	public function prepare_item_for_response( $report, $request ) {
140
+	public function prepare_item_for_response($report, $request) {
141 141
 		$data = array(
142 142
 			'slug'        => $report->slug,
143 143
 			'description' => $report->description,
144 144
 		);
145 145
 
146
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
147
-		$data = $this->add_additional_fields_to_object( $data, $request );
148
-		$data = $this->filter_response_by_context( $data, $context );
146
+		$context = !empty($request['context']) ? $request['context'] : 'view';
147
+		$data = $this->add_additional_fields_to_object($data, $request);
148
+		$data = $this->filter_response_by_context($data, $context);
149 149
 
150 150
 		// Wrap the data in a response object.
151
-		$response = rest_ensure_response( $data );
152
-		$response->add_links( array(
151
+		$response = rest_ensure_response($data);
152
+		$response->add_links(array(
153 153
 			'self' => array(
154
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $report->slug ) ),
154
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $report->slug)),
155 155
 			),
156 156
 			'collection' => array(
157
-				'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
157
+				'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
158 158
 			),
159
-		) );
159
+		));
160 160
 
161
-		return apply_filters( 'getpaid_rest_prepare_report', $response, $report, $request );
161
+		return apply_filters('getpaid_rest_prepare_report', $response, $report, $request);
162 162
 	}
163 163
 
164 164
 	/**
@@ -174,21 +174,21 @@  discard block
 block discarded – undo
174 174
 			'type'       => 'object',
175 175
 			'properties' => array(
176 176
 				'slug' => array(
177
-					'description' => __( 'An alphanumeric identifier for the resource.', 'invoicing' ),
177
+					'description' => __('An alphanumeric identifier for the resource.', 'invoicing'),
178 178
 					'type'        => 'string',
179
-					'context'     => array( 'view' ),
179
+					'context'     => array('view'),
180 180
 					'readonly'    => true,
181 181
 				),
182 182
 				'description' => array(
183
-					'description' => __( 'A human-readable description of the resource.', 'invoicing' ),
183
+					'description' => __('A human-readable description of the resource.', 'invoicing'),
184 184
 					'type'        => 'string',
185
-					'context'     => array( 'view' ),
185
+					'context'     => array('view'),
186 186
 					'readonly'    => true,
187 187
 				),
188 188
 			),
189 189
 		);
190 190
 
191
-		return $this->add_additional_fields_schema( $schema );
191
+		return $this->add_additional_fields_schema($schema);
192 192
 	}
193 193
 
194 194
 	/**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 */
200 200
 	public function get_collection_params() {
201 201
 		return array(
202
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
202
+			'context' => $this->get_context_param(array('default' => 'view')),
203 203
 		);
204 204
 	}
205 205
 }
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-report-top-sellers-controller.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -18,179 +18,179 @@
 block discarded – undo
18 18
  */
19 19
 class GetPaid_REST_Report_Top_Sellers_Controller extends GetPaid_REST_Report_Sales_Controller {
20 20
 
21
-	/**
22
-	 * Route base.
23
-	 *
24
-	 * @var string
25
-	 */
26
-	protected $rest_base = 'reports/top_sellers';
27
-
28
-	/**
29
-	 * Get top sellers report.
30
-	 *
31
-	 * @param WP_REST_Request $request
32
-	 * @return array|WP_Error
33
-	 */
34
-	public function get_items( $request ) {
35
-
36
-		// Prepare items.
37
-		$this->report_range = $this->get_date_range( $request );
38
-		$report_data        = $this->get_report_data();
39
-
40
-		$top_sellers = array();
41
-
42
-		foreach ( $report_data as $item ) {
43
-
44
-			$item_obj  = new WPInv_Item( $item );
45
-			$item_name = $item->invoice_item_name;
46
-			$item_qty  = absint( $item->invoice_item_qty );
47
-			$item_id   = absint( $item->invoice_item_id );
48
-			$price     = sanitize_text_field( wpinv_price( $item->invoice_item_price ) );
49
-
50
-			$item_obj  = new WPInv_Item( $item_id );
51
-
52
-			if ( $item_obj->exists() ) {
53
-				$item_name = $item_obj->get_name();
54
-			} else {
55
-				$item_id   = 0; 
56
-			}
57
-
58
-			$top_sellers[] = array(
59
-				'name'               =>sanitize_text_field( $item_name ),
60
-				'item_id'            => $item_id,
61
-				'quantity'           => $item_qty,
62
-				'earnings'           => wpinv_round_amount( $item->invoice_item_price ),
63
-				'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ),
64
-			);
65
-
66
-		}
67
-
68
-		$data = array();
69
-		foreach ( $top_sellers as $top_seller ) {
70
-			$item   = $this->prepare_item_for_response( (object) $top_seller, $request );
71
-			$data[] = $this->prepare_response_for_collection( $item );
72
-		}
73
-
74
-		return rest_ensure_response( $data );
75
-
76
-	}
77
-
78
-	/**
79
-	 * Prepare a report sales object for serialization.
80
-	 *
81
-	 * @param stdClass $top_seller
82
-	 * @param WP_REST_Request $request Request object.
83
-	 * @return WP_REST_Response $response Response data.
84
-	 */
85
-	public function prepare_item_for_response( $top_seller, $request ) {
86
-		$data    = (array) $top_seller;
87
-
88
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
89
-		$data    = $this->add_additional_fields_to_object( $data, $request );
90
-		$data    = $this->filter_response_by_context( $data, $context );
91
-
92
-		// Wrap the data in a response object.
93
-		$response = rest_ensure_response( $data );
94
-		$links = array(
95
-			'about' => array(
96
-				'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ),
97
-			),
98
-		);
99
-
100
-		if ( ! empty( $top_seller->item_id ) ) {
101
-			$links['item']   = array(
102
-				'href'       => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ),
103
-				'embeddable' => true,
104
-			);
105
-		}
106
-
107
-		$response->add_links( $links );
108
-		return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request );
109
-	}
110
-
111
-	/**
112
-	 * Get all data needed for this report and store in the class.
113
-	 */
114
-	protected function query_report_data() {
115
-
116
-		$this->report_data = GetPaid_Reports_Helper::get_invoice_report_data(
117
-			array(
118
-				'data'              => array(
119
-					'quantity'      => array(
120
-						'type'            => 'invoice_item',
121
-						'function'        => 'SUM',
122
-						'name'            => 'invoice_item_qty',
123
-					),
124
-					'item_id'             => array(
125
-						'type'            => 'invoice_item',
126
-						'function'        => '',
127
-						'name'            => 'invoice_item_id',
128
-					),
129
-					'item_name'           => array(
130
-						'type'            => 'invoice_item',
131
-						'function'        => '',
132
-						'name'            => 'invoice_item_name',
133
-					),
134
-					'price'               => array(
135
-						'type'            => 'invoice_item',
136
-						'function'        => 'SUM',
137
-						'name'            => 'invoice_item_price',
138
-					),
139
-				),
140
-				'group_by'       => 'invoice_item_id',
141
-				'order_by'       => 'invoice_item_qty DESC',
142
-				'query_type'     => 'get_results',
143
-				'limit'          => 10,
144
-				'filter_range'   => $this->report_range,
145
-			)
146
-		);
147
-
148
-	}
149
-
150
-	/**
151
-	 * Get the Report's schema, conforming to JSON Schema.
152
-	 *
153
-	 * @return array
154
-	 */
155
-	public function get_item_schema() {
156
-		$schema = array(
157
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
158
-			'title'      => $this->rest_base,
159
-			'type'       => 'object',
160
-			'properties' => array(
161
-				'name' => array(
162
-					'description' => __( 'Item name.', 'invoicing' ),
163
-					'type'        => 'string',
164
-					'context'     => array( 'view' ),
165
-					'readonly'    => true,
166
-				),
167
-				'item_id'         => array(
168
-					'description' => __( 'Item ID.', 'invoicing' ),
169
-					'type'        => 'integer',
170
-					'context'     => array( 'view' ),
171
-					'readonly'    => true,
172
-				),
173
-				'quantity' => array(
174
-					'description' => __( 'Total number of purchases.', 'invoicing' ),
175
-					'type'        => 'integer',
176
-					'context'     => array( 'view' ),
177
-					'readonly'    => true,
178
-				),
179
-				'earnings' => array(
180
-					'description' => __( 'Total earnings for the item.', 'invoicing' ),
181
-					'type'        => 'double',
182
-					'context'     => array( 'view' ),
183
-					'readonly'    => true,
184
-				),
185
-				'earnings_formatted"' => array(
186
-					'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ),
187
-					'type'        => 'string',
188
-					'context'     => array( 'view' ),
189
-					'readonly'    => true,
190
-				),
191
-			),
192
-		);
193
-
194
-		return $this->add_additional_fields_schema( $schema );
195
-	}
21
+    /**
22
+     * Route base.
23
+     *
24
+     * @var string
25
+     */
26
+    protected $rest_base = 'reports/top_sellers';
27
+
28
+    /**
29
+     * Get top sellers report.
30
+     *
31
+     * @param WP_REST_Request $request
32
+     * @return array|WP_Error
33
+     */
34
+    public function get_items( $request ) {
35
+
36
+        // Prepare items.
37
+        $this->report_range = $this->get_date_range( $request );
38
+        $report_data        = $this->get_report_data();
39
+
40
+        $top_sellers = array();
41
+
42
+        foreach ( $report_data as $item ) {
43
+
44
+            $item_obj  = new WPInv_Item( $item );
45
+            $item_name = $item->invoice_item_name;
46
+            $item_qty  = absint( $item->invoice_item_qty );
47
+            $item_id   = absint( $item->invoice_item_id );
48
+            $price     = sanitize_text_field( wpinv_price( $item->invoice_item_price ) );
49
+
50
+            $item_obj  = new WPInv_Item( $item_id );
51
+
52
+            if ( $item_obj->exists() ) {
53
+                $item_name = $item_obj->get_name();
54
+            } else {
55
+                $item_id   = 0; 
56
+            }
57
+
58
+            $top_sellers[] = array(
59
+                'name'               =>sanitize_text_field( $item_name ),
60
+                'item_id'            => $item_id,
61
+                'quantity'           => $item_qty,
62
+                'earnings'           => wpinv_round_amount( $item->invoice_item_price ),
63
+                'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ),
64
+            );
65
+
66
+        }
67
+
68
+        $data = array();
69
+        foreach ( $top_sellers as $top_seller ) {
70
+            $item   = $this->prepare_item_for_response( (object) $top_seller, $request );
71
+            $data[] = $this->prepare_response_for_collection( $item );
72
+        }
73
+
74
+        return rest_ensure_response( $data );
75
+
76
+    }
77
+
78
+    /**
79
+     * Prepare a report sales object for serialization.
80
+     *
81
+     * @param stdClass $top_seller
82
+     * @param WP_REST_Request $request Request object.
83
+     * @return WP_REST_Response $response Response data.
84
+     */
85
+    public function prepare_item_for_response( $top_seller, $request ) {
86
+        $data    = (array) $top_seller;
87
+
88
+        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
89
+        $data    = $this->add_additional_fields_to_object( $data, $request );
90
+        $data    = $this->filter_response_by_context( $data, $context );
91
+
92
+        // Wrap the data in a response object.
93
+        $response = rest_ensure_response( $data );
94
+        $links = array(
95
+            'about' => array(
96
+                'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ),
97
+            ),
98
+        );
99
+
100
+        if ( ! empty( $top_seller->item_id ) ) {
101
+            $links['item']   = array(
102
+                'href'       => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ),
103
+                'embeddable' => true,
104
+            );
105
+        }
106
+
107
+        $response->add_links( $links );
108
+        return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request );
109
+    }
110
+
111
+    /**
112
+     * Get all data needed for this report and store in the class.
113
+     */
114
+    protected function query_report_data() {
115
+
116
+        $this->report_data = GetPaid_Reports_Helper::get_invoice_report_data(
117
+            array(
118
+                'data'              => array(
119
+                    'quantity'      => array(
120
+                        'type'            => 'invoice_item',
121
+                        'function'        => 'SUM',
122
+                        'name'            => 'invoice_item_qty',
123
+                    ),
124
+                    'item_id'             => array(
125
+                        'type'            => 'invoice_item',
126
+                        'function'        => '',
127
+                        'name'            => 'invoice_item_id',
128
+                    ),
129
+                    'item_name'           => array(
130
+                        'type'            => 'invoice_item',
131
+                        'function'        => '',
132
+                        'name'            => 'invoice_item_name',
133
+                    ),
134
+                    'price'               => array(
135
+                        'type'            => 'invoice_item',
136
+                        'function'        => 'SUM',
137
+                        'name'            => 'invoice_item_price',
138
+                    ),
139
+                ),
140
+                'group_by'       => 'invoice_item_id',
141
+                'order_by'       => 'invoice_item_qty DESC',
142
+                'query_type'     => 'get_results',
143
+                'limit'          => 10,
144
+                'filter_range'   => $this->report_range,
145
+            )
146
+        );
147
+
148
+    }
149
+
150
+    /**
151
+     * Get the Report's schema, conforming to JSON Schema.
152
+     *
153
+     * @return array
154
+     */
155
+    public function get_item_schema() {
156
+        $schema = array(
157
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
158
+            'title'      => $this->rest_base,
159
+            'type'       => 'object',
160
+            'properties' => array(
161
+                'name' => array(
162
+                    'description' => __( 'Item name.', 'invoicing' ),
163
+                    'type'        => 'string',
164
+                    'context'     => array( 'view' ),
165
+                    'readonly'    => true,
166
+                ),
167
+                'item_id'         => array(
168
+                    'description' => __( 'Item ID.', 'invoicing' ),
169
+                    'type'        => 'integer',
170
+                    'context'     => array( 'view' ),
171
+                    'readonly'    => true,
172
+                ),
173
+                'quantity' => array(
174
+                    'description' => __( 'Total number of purchases.', 'invoicing' ),
175
+                    'type'        => 'integer',
176
+                    'context'     => array( 'view' ),
177
+                    'readonly'    => true,
178
+                ),
179
+                'earnings' => array(
180
+                    'description' => __( 'Total earnings for the item.', 'invoicing' ),
181
+                    'type'        => 'double',
182
+                    'context'     => array( 'view' ),
183
+                    'readonly'    => true,
184
+                ),
185
+                'earnings_formatted"' => array(
186
+                    'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ),
187
+                    'type'        => 'string',
188
+                    'context'     => array( 'view' ),
189
+                    'readonly'    => true,
190
+                ),
191
+            ),
192
+        );
193
+
194
+        return $this->add_additional_fields_schema( $schema );
195
+    }
196 196
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @since   2.0.0
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * GetPaid REST top sellers controller class.
@@ -31,47 +31,47 @@  discard block
 block discarded – undo
31 31
 	 * @param WP_REST_Request $request
32 32
 	 * @return array|WP_Error
33 33
 	 */
34
-	public function get_items( $request ) {
34
+	public function get_items($request) {
35 35
 
36 36
 		// Prepare items.
37
-		$this->report_range = $this->get_date_range( $request );
37
+		$this->report_range = $this->get_date_range($request);
38 38
 		$report_data        = $this->get_report_data();
39 39
 
40 40
 		$top_sellers = array();
41 41
 
42
-		foreach ( $report_data as $item ) {
42
+		foreach ($report_data as $item) {
43 43
 
44
-			$item_obj  = new WPInv_Item( $item );
44
+			$item_obj  = new WPInv_Item($item);
45 45
 			$item_name = $item->invoice_item_name;
46
-			$item_qty  = absint( $item->invoice_item_qty );
47
-			$item_id   = absint( $item->invoice_item_id );
48
-			$price     = sanitize_text_field( wpinv_price( $item->invoice_item_price ) );
46
+			$item_qty  = absint($item->invoice_item_qty);
47
+			$item_id   = absint($item->invoice_item_id);
48
+			$price     = sanitize_text_field(wpinv_price($item->invoice_item_price));
49 49
 
50
-			$item_obj  = new WPInv_Item( $item_id );
50
+			$item_obj  = new WPInv_Item($item_id);
51 51
 
52
-			if ( $item_obj->exists() ) {
52
+			if ($item_obj->exists()) {
53 53
 				$item_name = $item_obj->get_name();
54 54
 			} else {
55 55
 				$item_id   = 0; 
56 56
 			}
57 57
 
58 58
 			$top_sellers[] = array(
59
-				'name'               =>sanitize_text_field( $item_name ),
59
+				'name'               =>sanitize_text_field($item_name),
60 60
 				'item_id'            => $item_id,
61 61
 				'quantity'           => $item_qty,
62
-				'earnings'           => wpinv_round_amount( $item->invoice_item_price ),
63
-				'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ),
62
+				'earnings'           => wpinv_round_amount($item->invoice_item_price),
63
+				'earnings_formatted' => sanitize_text_field(wpinv_price($price)),
64 64
 			);
65 65
 
66 66
 		}
67 67
 
68 68
 		$data = array();
69
-		foreach ( $top_sellers as $top_seller ) {
70
-			$item   = $this->prepare_item_for_response( (object) $top_seller, $request );
71
-			$data[] = $this->prepare_response_for_collection( $item );
69
+		foreach ($top_sellers as $top_seller) {
70
+			$item   = $this->prepare_item_for_response((object) $top_seller, $request);
71
+			$data[] = $this->prepare_response_for_collection($item);
72 72
 		}
73 73
 
74
-		return rest_ensure_response( $data );
74
+		return rest_ensure_response($data);
75 75
 
76 76
 	}
77 77
 
@@ -82,30 +82,30 @@  discard block
 block discarded – undo
82 82
 	 * @param WP_REST_Request $request Request object.
83 83
 	 * @return WP_REST_Response $response Response data.
84 84
 	 */
85
-	public function prepare_item_for_response( $top_seller, $request ) {
85
+	public function prepare_item_for_response($top_seller, $request) {
86 86
 		$data    = (array) $top_seller;
87 87
 
88
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
89
-		$data    = $this->add_additional_fields_to_object( $data, $request );
90
-		$data    = $this->filter_response_by_context( $data, $context );
88
+		$context = !empty($request['context']) ? $request['context'] : 'view';
89
+		$data    = $this->add_additional_fields_to_object($data, $request);
90
+		$data    = $this->filter_response_by_context($data, $context);
91 91
 
92 92
 		// Wrap the data in a response object.
93
-		$response = rest_ensure_response( $data );
93
+		$response = rest_ensure_response($data);
94 94
 		$links = array(
95 95
 			'about' => array(
96
-				'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ),
96
+				'href' => rest_url(sprintf('%s/reports', $this->namespace)),
97 97
 			),
98 98
 		);
99 99
 
100
-		if ( ! empty( $top_seller->item_id ) ) {
101
-			$links['item']   = array(
102
-				'href'       => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ),
100
+		if (!empty($top_seller->item_id)) {
101
+			$links['item'] = array(
102
+				'href'       => rest_url(sprintf('/%s/items/%s', $this->namespace, $top_seller->item_id)),
103 103
 				'embeddable' => true,
104 104
 			);
105 105
 		}
106 106
 
107
-		$response->add_links( $links );
108
-		return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request );
107
+		$response->add_links($links);
108
+		return apply_filters('getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request);
109 109
 	}
110 110
 
111 111
 	/**
@@ -159,38 +159,38 @@  discard block
 block discarded – undo
159 159
 			'type'       => 'object',
160 160
 			'properties' => array(
161 161
 				'name' => array(
162
-					'description' => __( 'Item name.', 'invoicing' ),
162
+					'description' => __('Item name.', 'invoicing'),
163 163
 					'type'        => 'string',
164
-					'context'     => array( 'view' ),
164
+					'context'     => array('view'),
165 165
 					'readonly'    => true,
166 166
 				),
167 167
 				'item_id'         => array(
168
-					'description' => __( 'Item ID.', 'invoicing' ),
168
+					'description' => __('Item ID.', 'invoicing'),
169 169
 					'type'        => 'integer',
170
-					'context'     => array( 'view' ),
170
+					'context'     => array('view'),
171 171
 					'readonly'    => true,
172 172
 				),
173 173
 				'quantity' => array(
174
-					'description' => __( 'Total number of purchases.', 'invoicing' ),
174
+					'description' => __('Total number of purchases.', 'invoicing'),
175 175
 					'type'        => 'integer',
176
-					'context'     => array( 'view' ),
176
+					'context'     => array('view'),
177 177
 					'readonly'    => true,
178 178
 				),
179 179
 				'earnings' => array(
180
-					'description' => __( 'Total earnings for the item.', 'invoicing' ),
180
+					'description' => __('Total earnings for the item.', 'invoicing'),
181 181
 					'type'        => 'double',
182
-					'context'     => array( 'view' ),
182
+					'context'     => array('view'),
183 183
 					'readonly'    => true,
184 184
 				),
185 185
 				'earnings_formatted"' => array(
186
-					'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ),
186
+					'description' => __('Total earnings (formatted) for the item.', 'invoicing'),
187 187
 					'type'        => 'string',
188
-					'context'     => array( 'view' ),
188
+					'context'     => array('view'),
189 189
 					'readonly'    => true,
190 190
 				),
191 191
 			),
192 192
 		);
193 193
 
194
-		return $this->add_additional_fields_schema( $schema );
194
+		return $this->add_additional_fields_schema($schema);
195 195
 	}
196 196
 }
Please login to merge, or discard this patch.