PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.5.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.5.2
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / abilities / analytics / get-daily-chart-data.php
latepoint / lib / abilities / analytics Last commit date
abstract-analytics-ability.php 3 months ago get-daily-chart-data.php 3 months ago get-dashboard-stats.php 3 months ago get-pending-bookings-count.php 3 months ago get-top-services.php 3 months ago
get-daily-chart-data.php
89 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class LatePointAbilityGetDailyChartData extends LatePointAbstractAnalyticsAbility {
7
8 protected function configure(): void {
9 $this->id = 'latepoint/get-daily-chart-data';
10 $this->label = __( 'Get daily chart data', 'latepoint' );
11 $this->description = __( 'Returns daily booking counts or revenue for charting over a date range.', 'latepoint' );
12 $this->permission = 'booking__view';
13 $this->read_only = true;
14 }
15
16 public function get_input_schema(): array {
17 return [
18 'type' => 'object',
19 'properties' => [
20 'date_from' => [
21 'type' => 'string',
22 'format' => 'date',
23 ],
24 'date_to' => [
25 'type' => 'string',
26 'format' => 'date',
27 ],
28 'metric' => [
29 'type' => 'string',
30 'enum' => [ 'bookings', 'revenue' ],
31 ],
32 ],
33 'required' => [ 'date_from', 'date_to' ],
34 ];
35 }
36
37 public function get_output_schema(): array {
38 return [
39 'type' => 'object',
40 'properties' => [
41 'days' => [
42 'type' => 'array',
43 'items' => [
44 'type' => 'object',
45 'properties' => [
46 'date' => [
47 'type' => 'string',
48 'format' => 'date',
49 ],
50 'value' => [ 'type' => 'number' ],
51 ],
52 ],
53 ],
54 ],
55 ];
56 }
57
58 public function execute( array $args ) {
59 $date_from = sanitize_text_field( $args['date_from'] );
60 $date_to = sanitize_text_field( $args['date_to'] );
61 $metric = ! empty( $args['metric'] ) ? sanitize_text_field( $args['metric'] ) : 'bookings';
62 $filter = new \LatePoint\Misc\Filter();
63
64 if ( $metric === 'revenue' ) {
65 $rows = OsBookingHelper::get_stat_for_period( 'price', $date_from, $date_to, $filter, 'start_date' );
66 $days = [];
67 if ( is_array( $rows ) ) {
68 foreach ( $rows as $row ) {
69 $days[] = [
70 'date' => $row['start_date'] ?? $row[0] ?? '',
71 'value' => (float) ( $row['price'] ?? $row['value'] ?? $row[1] ?? 0 ),
72 ];
73 }
74 }
75 } else {
76 $rows = OsBookingHelper::get_total_bookings_per_day_for_period( $date_from, $date_to, $filter );
77 $days = array_map(
78 fn( $row ) => [
79 'date' => ( (array) $row )['start_date'] ?? '',
80 'value' => (float) ( ( (array) $row )['bookings_per_day'] ?? 0 ),
81 ],
82 $rows
83 );
84 }
85
86 return [ 'days' => $days ];
87 }
88 }
89