PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / trunk
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress vtrunk
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 / customers / list-customers.php
latepoint / lib / abilities / customers Last commit date
abstract-customer-ability.php 4 months ago connect-customer-to-wp-user.php 2 weeks ago create-customer.php 4 months ago delete-customer.php 2 weeks ago get-customer-bookings.php 2 weeks ago get-customer-by-email.php 2 weeks ago get-customer-orders.php 2 weeks ago get-customer.php 2 weeks ago get-total-customers-count.php 2 weeks ago list-customers.php 2 weeks ago search-customers.php 2 weeks ago update-customer.php 2 weeks ago
list-customers.php
90 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class LatePointAbilityListCustomers extends LatePointAbstractCustomerAbility {
7
8 protected function configure(): void {
9 $this->id = 'latepoint/list-customers';
10 $this->label = __( 'List customers', 'latepoint' );
11 $this->description = __( 'Returns a paginated list of customers with optional search/filter.', 'latepoint' );
12 $this->permission = 'customer__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 'search' => [
23 'type' => 'string',
24 'description' => __( 'Search by name, email, or phone.', 'latepoint' ),
25 ],
26 'status' => [
27 'type' => 'string',
28 'description' => __( 'Filter by customer status.', 'latepoint' ),
29 ],
30 ]
31 ),
32 ];
33 }
34
35 public function get_output_schema(): array {
36 return [
37 'type' => 'object',
38 'properties' => [
39 'customers' => [
40 'type' => 'array',
41 'items' => $this->customer_output_schema(),
42 ],
43 'total' => [ 'type' => 'integer' ],
44 'page' => [ 'type' => 'integer' ],
45 'per_page' => [ 'type' => 'integer' ],
46 ],
47 ];
48 }
49
50 public function execute( array $args ) {
51 $page = max( 1, (int) ( $args['page'] ?? 1 ) );
52 $per_page = min( 100, max( 1, (int) ( $args['per_page'] ?? 20 ) ) );
53 $offset = ( $page - 1 ) * $per_page;
54
55 $query = new OsCustomerModel();
56
57 if ( ! empty( $args['search'] ) ) {
58 $s = '%' . sanitize_text_field( $args['search'] ) . '%';
59 $query->where(
60 [
61 'OR' => [
62 'first_name LIKE' => $s,
63 'last_name LIKE' => $s,
64 'email LIKE' => $s,
65 'phone LIKE' => $s,
66 ],
67 ]
68 );
69 }
70 if ( ! empty( $args['status'] ) ) {
71 $query->where( [ 'status' => sanitize_text_field( $args['status'] ) ] );
72 }
73 $query->filter_allowed_records();
74
75 $customers = ( clone $query )
76 ->order_by( 'last_name ASC, first_name ASC' )
77 ->set_limit( $per_page )
78 ->set_offset( $offset )
79 ->get_results_as_models();
80 $total = $query->count();
81
82 return [
83 'customers' => array_map( [ $this, 'serialize_customer' ], $customers ),
84 'total' => (int) $total,
85 'page' => $page,
86 'per_page' => $per_page,
87 ];
88 }
89 }
90