PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.2
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 / helpers / service_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago auth_helper.php 9 months ago blocks_helper.php 1 year ago booking_helper.php 1 year ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 9 months ago carts_helper.php 1 year ago connector_helper.php 1 year ago csv_helper.php 9 months ago customer_helper.php 9 months ago customer_import_helper.php 9 months ago database_helper.php 9 months ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 9 months ago encrypt_helper.php 1 year ago events_helper.php 1 year ago form_helper.php 9 months ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 9 months ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 9 months ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 9 months ago order_intent_helper.php 9 months ago orders_helper.php 1 year ago otp_helper.php 9 months ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 9 months ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 9 months ago short_links_systems_helper.php 9 months ago shortcodes_helper.php 9 months ago sms_helper.php 1 year ago steps_helper.php 9 months ago stripe_connect_helper.php 9 months ago styles_helper.php 9 months ago support_topics_helper.php 1 year ago time_helper.php 9 months ago timeline_helper.php 9 months ago transaction_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 9 months ago version_specific_updates_helper.php 9 months ago whatsapp_helper.php 1 year ago work_periods_helper.php 1 year ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
service_helper.php
162 lines
1 <?php
2
3 class OsServiceHelper {
4
5 /**
6 * @return OsServiceModel[]
7 */
8 public static function get_allowed_active_services(): array {
9 $agents = new OsServiceModel();
10
11 return $agents->should_be_active()->filter_allowed_records()->get_results_as_models();
12 }
13
14 public static function get_max_capacity_by_service_id( $service_id ) {
15 $service = new OsServiceModel( $service_id );
16
17 return self::get_max_capacity( $service );
18 }
19
20 public static function get_min_capacity_by_service_id( $service_id ) {
21 $service = new OsServiceModel( $service_id );
22
23 return self::get_min_capacity( $service );
24 }
25
26 public static function get_minimum_duration_across_services() {
27 $service = new OsServiceModel();
28 $services = $service->should_be_active()->get_results_as_models();
29 $min_duration = false;
30 foreach ( $services as $service ) {
31 $min_duration = $min_duration ? min( $min_duration, $service->duration ) : $service->duration;
32 }
33
34 return $min_duration;
35 }
36
37 public static function get_summary_duration_label( $duration ) {
38 if ( ! $duration ) {
39 return '';
40 }
41 if ( ( $duration >= 60 ) && ! OsSettingsHelper::is_on( 'steps_show_duration_in_minutes' ) ) {
42 $hours = floor( $duration / 60 );
43 $minutes = $duration % 60;
44 $summary_duration_label = $hours . ' ';
45 $summary_duration_label .= ( $hours > 1 ) ? __( 'Hours', 'latepoint' ) : __( 'Hour', 'latepoint' );
46 if ( $minutes ) {
47 $summary_duration_label .= ', ' . $minutes . ' ' . __( 'Minutes', 'latepoint' );
48 }
49 } else {
50 $summary_duration_label = $duration . ' ' . __( 'Minutes', 'latepoint' );
51 }
52
53 return $summary_duration_label;
54 }
55
56 public static function get_max_capacity( $service ) {
57 if ( $service && ! empty( $service->capacity_max ) ) {
58 return $service->capacity_max;
59 }
60
61 return 1;
62 }
63
64 public static function get_min_capacity( $service ) {
65 if ( $service && ! empty( $service->capacity_min ) ) {
66 return $service->capacity_min;
67 }
68
69 return 1;
70 }
71
72 public static function get_percent_of_capacity_booked( $service, $total_attendees ) {
73 $total_attendees = empty( $total_attendees ) ? 1 : $total_attendees;
74 $max_capacity = self::get_max_capacity( $service );
75
76 return min( 100, round( $total_attendees / $max_capacity * 100 ) );
77 }
78
79 public static function get_default_colors() {
80 return array( '#2752E4', '#C066F1', '#26B7DD', '#E8C634', '#19CED6', '#2FEAA3', '#252a3e', '#8d87a5', '#b9b784' );
81 }
82
83 public static function get_default_duration_for_service( $service_id ) {
84 $service = new OsServiceModel( $service_id );
85
86 return $service->duration;
87 }
88
89 public static function service_option_html_for_select( $service, $selected = false ) {
90 ?>
91 <div class="service-option <?php if ( $selected ) {
92 echo 'selected';
93 } ?>"
94 data-extra-durations="<?php echo esc_attr( wp_json_encode( $service->get_extra_durations() ) ); ?>"
95 data-id="<?php echo esc_attr( $service->id ); ?>"
96 data-buffer-before="<?php echo esc_attr( $service->buffer_before ); ?>"
97 data-buffer-after="<?php echo esc_attr( $service->buffer_after ); ?>"
98 data-capacity-min="<?php echo esc_attr( $service->capacity_min ); ?>"
99 data-capacity-max="<?php echo esc_attr( $service->capacity_max ); ?>"
100 data-duration-name="<?php echo esc_attr( $service->duration_name ); ?>"
101 data-duration="<?php echo esc_attr( $service->duration ); ?>">
102 <div class="service-color" style="background-color: <?php echo esc_attr( $service->bg_color ); ?>"></div>
103 <span><?php echo esc_html( $service->name ); ?></span>
104 </div>
105 <?php
106 }
107
108 /**
109 * @param $agent_id
110 *
111 * @return OsServiceModel[]
112 */
113 public static function get_services( bool $filter_allowed_records = false ): array {
114 $services = new OsServiceModel();
115 if ( $filter_allowed_records ) {
116 $services->filter_allowed_records();
117 }
118 $services = $services->get_results_as_models();
119
120 return $services;
121 }
122
123 /**
124 * @param bool $filter_allowed_records
125 * @param array $service_ids
126 *
127 * @return array
128 */
129 public static function get_services_list( bool $filter_allowed_records = false, array $service_ids = [], bool $exclude_disabled = false ): array {
130 $services = new OsServiceModel();
131 if ( $filter_allowed_records ) {
132 $services->filter_allowed_records();
133 }
134
135 if ( ! empty( $service_ids ) ) {
136 $services->where_in( 'id', $service_ids );
137 }
138
139 if ( $exclude_disabled ) {
140 $services->where( [ 'status' => LATEPOINT_SERVICE_STATUS_ACTIVE ] );
141 }
142
143 $services = $services->order_by('status asc, name asc')->get_results_as_models();
144 $services_list = [];
145 if ( $services ) {
146 foreach ( $services as $service ) {
147 $label = ( $service->status == LATEPOINT_LOCATION_STATUS_DISABLED ) ? ( $service->name . ' [' . esc_html__( 'Disabled', 'latepoint' ) . ']' ) : $service->name;
148 $services_list[] = [ 'value' => $service->id, 'label' => $label ];
149 }
150 }
151
152 return $services_list;
153 }
154
155 public static function has_multiple_durations( int $service_id ): bool {
156 $service = new OsServiceModel( $service_id );
157 $extra_durations = $service->get_extra_durations();
158
159 return ! empty( $extra_durations );
160 }
161
162 }