PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.0
Timetics – Appointment Booking Calendar & Scheduling v1.0.0
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / core / reports / api-report.php

api-report.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.0, at core/reports/api-report.php

86 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Api reports class
4 *
5 * @package Timetics
6 */
7
8 namespace Timetics\Core\Reports;
9
10 use Timetics\Base\Api;
11 use Timetics\Utils\Singleton;
12
13 /**
14 * Class Api Reports
15 */
16 class Api_Report extends Api {
17 use Singleton;
18
19 /**
20 * Store api namespace
21 *
22 * @var string
23 */
24 protected $namespace = 'timetics/v1';
25
26 /**
27 * Store rest base
28 *
29 * @var string
30 */
31 protected $rest_base = 'reports';
32
33 /**
34 * Register rest routes
35 *
36 * @return void
37 */
38 public function register_routes() {
39 /**
40 * Register route
41 *
42 * @var void
43 */
44 register_rest_route(
45 $this->namespace, $this->rest_base . '/overview', [
46 [
47 'methods' => \WP_REST_Server::READABLE,
48 'callback' => [$this, 'get_overview'],
49 'permission_callback' => function () {
50 return current_user_can( 'manage_timetics' );
51 },
52 ],
53 ]
54 );
55 }
56
57 /**
58 * Get overview
59 *
60 * @param WP_Rest_Request
61 *
62 * @return JSON
63 */
64 public function get_overview( $request ) {
65 $start_date = isset( $request['start_date'] ) ? sanitize_text_field( $request['start_date'] ) : '';
66
67 $end_date = isset( $request['end_date'] ) ? sanitize_text_field( $request['end_date'] ) : '';
68
69 $data = [
70 'total_meetings' => timetics_count_posts( ['post_type' => 'timetics-appointment'] ),
71 'total_bookings' => timetics_count_posts( ['post_type' => 'timetics-booking'] ),
72 'total_sales' => number_format(timetics_get_total_sale(), 2),
73 'total_customer' => timetics_count_users( ['role' => 'timetics-customer'] ),
74 'total_staff' => timetics_count_users( ['role' => 'timetics-staff'] ),
75 ];
76
77 $response = [
78 'status_code' => 200,
79 'success' => 1,
80 'data' => $data,
81 ];
82
83 return rest_ensure_response( $response );
84 }
85 }
86