PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.8
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.8
5.6.8 5.6.7 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 / activities / list-activities.php
latepoint / lib / abilities / activities Last commit date
abstract-activity-ability.php 4 months ago get-activity.php 4 months ago list-activities.php 4 months ago
list-activities.php
103 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class LatePointAbilityListActivities extends LatePointAbstractActivityAbility {
7
8 protected function configure(): void {
9 $this->id = 'latepoint/list-activities';
10 $this->label = __( 'List activities', 'latepoint' );
11 $this->description = __( 'Returns a paginated list of activity log entries with optional filters.', 'latepoint' );
12 $this->permission = 'activity__view';
13 $this->read_only = true;
14 }
15
16 public function get_input_schema(): array {
17 return [
18 'type' => 'object',
19 'properties' => array_merge(
20 self::pagination(),
21 [
22 'entity_type' => [
23 'type' => 'string',
24 'description' => __( 'Entity type to filter by (e.g. booking, customer).', 'latepoint' ),
25 ],
26 'entity_id' => [ 'type' => 'integer' ],
27 'date_from' => [
28 'type' => 'string',
29 'format' => 'date',
30 ],
31 'date_to' => [
32 'type' => 'string',
33 'format' => 'date',
34 ],
35 ]
36 ),
37 ];
38 }
39
40 public function get_output_schema(): array {
41 return [
42 'type' => 'object',
43 'properties' => [
44 'activities' => [
45 'type' => 'array',
46 'items' => $this->activity_output_schema(),
47 ],
48 'total' => [ 'type' => 'integer' ],
49 'page' => [ 'type' => 'integer' ],
50 'per_page' => [ 'type' => 'integer' ],
51 ],
52 ];
53 }
54
55 public function execute( array $args ) {
56 $page = max( 1, (int) ( $args['page'] ?? 1 ) );
57 $per_page = min( 100, max( 1, (int) ( $args['per_page'] ?? 20 ) ) );
58 $offset = ( $page - 1 ) * $per_page;
59
60 $query = new OsActivityModel();
61
62 if ( ! empty( $args['entity_type'] ) && ! empty( $args['entity_id'] ) ) {
63 $entity_type = sanitize_text_field( $args['entity_type'] );
64 $entity_id = (int) $args['entity_id'];
65 switch ( $entity_type ) {
66 case 'booking':
67 $query->where( [ 'booking_id' => $entity_id ] );
68 break;
69 case 'customer':
70 $query->where( [ 'customer_id' => $entity_id ] );
71 break;
72 case 'agent':
73 $query->where( [ 'agent_id' => $entity_id ] );
74 break;
75 case 'order':
76 $query->where( [ 'order_id' => $entity_id ] );
77 break;
78 }
79 }
80
81 if ( ! empty( $args['date_from'] ) ) {
82 $query->where( [ 'created_at >=' => sanitize_text_field( $args['date_from'] ) . ' 00:00:00' ] );
83 }
84 if ( ! empty( $args['date_to'] ) ) {
85 $query->where( [ 'created_at <=' => sanitize_text_field( $args['date_to'] ) . ' 23:59:59' ] );
86 }
87
88 $activities = ( clone $query )
89 ->order_by( 'created_at DESC' )
90 ->set_limit( $per_page )
91 ->set_offset( $offset )
92 ->get_results_as_models();
93 $total = $query->count();
94
95 return [
96 'activities' => array_map( [ $this, 'serialize_activity' ], $activities ),
97 'total' => (int) $total,
98 'page' => $page,
99 'per_page' => $per_page,
100 ];
101 }
102 }
103