activities_helper.php
3 months ago
agent_helper.php
3 months ago
analytics_helper.php
4 months ago
auth_helper.php
3 months ago
blocks_helper.php
3 months ago
booking_helper.php
3 months ago
bricks_helper.php
3 months ago
bundles_helper.php
3 months ago
calendar_helper.php
3 months ago
carts_helper.php
3 months ago
connector_helper.php
3 months ago
csv_helper.php
3 months ago
customer_helper.php
3 months ago
customer_import_helper.php
3 months ago
database_helper.php
3 months ago
debug_helper.php
3 months ago
defaults_helper.php
3 months ago
elementor_helper.php
3 months ago
email_helper.php
3 months ago
encrypt_helper.php
3 months ago
events_helper.php
3 months ago
form_helper.php
3 months ago
icalendar_helper.php
3 months ago
image_helper.php
3 months ago
invoices_helper.php
3 months ago
license_helper.php
3 months ago
location_helper.php
3 months ago
marketing_systems_helper.php
3 months ago
meeting_systems_helper.php
3 months ago
menu_helper.php
3 months ago
meta_helper.php
3 months ago
migrations_helper.php
3 months ago
money_helper.php
3 months ago
notifications_helper.php
3 months ago
nps_survey_helper.php
3 months ago
order_intent_helper.php
3 months ago
orders_helper.php
3 months ago
otp_helper.php
3 months ago
pages_helper.php
3 months ago
params_helper.php
3 months ago
payments_helper.php
3 months ago
price_breakdown_helper.php
3 months ago
process_jobs_helper.php
3 months ago
processes_helper.php
3 months ago
replacer_helper.php
3 months ago
resource_helper.php
3 months ago
roles_helper.php
3 months ago
router_helper.php
3 months ago
service_helper.php
3 months ago
sessions_helper.php
3 months ago
settings_helper.php
3 months ago
short_links_systems_helper.php
3 months ago
shortcodes_helper.php
3 months ago
sms_helper.php
3 months ago
steps_helper.php
3 months ago
stripe_connect_helper.php
3 months ago
styles_helper.php
3 months ago
support_topics_helper.php
3 months ago
time_helper.php
3 months ago
timeline_helper.php
3 months ago
transaction_helper.php
3 months ago
transaction_intent_helper.php
3 months ago
util_helper.php
3 months ago
version_specific_updates_helper.php
3 months ago
whatsapp_helper.php
3 months ago
work_periods_helper.php
3 months ago
wp_datetime.php
3 months ago
wp_user_helper.php
3 months ago
service_helper.php
164 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[] = [ |
| 149 | 'value' => $service->id, |
| 150 | 'label' => $label, |
| 151 | ]; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | return $services_list; |
| 156 | } |
| 157 | |
| 158 | public static function has_multiple_durations( int $service_id ): bool { |
| 159 | $service = new OsServiceModel( $service_id ); |
| 160 | $extra_durations = $service->get_extra_durations(); |
| 161 | |
| 162 | return ! empty( $extra_durations ); |
| 163 | } |
| 164 | } |