PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.1.3
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.1.3
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 / trunk / lib / helpers / service_helper.php
latepoint / trunk / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago auth_helper.php 1 year 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 1 year ago carts_helper.php 1 year ago connector_helper.php 1 year ago csv_helper.php 1 year ago customer_helper.php 1 year ago database_helper.php 1 year ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 1 year ago encrypt_helper.php 1 year ago events_helper.php 1 year ago form_helper.php 1 year ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 1 year 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 1 year ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 1 year ago order_intent_helper.php 1 year ago orders_helper.php 1 year 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 1 year ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 1 year ago shortcodes_helper.php 1 year ago sms_helper.php 1 year ago steps_helper.php 1 year ago stripe_connect_helper.php 1 year ago styles_helper.php 1 year ago support_topics_helper.php 1 year ago time_helper.php 1 year ago timeline_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 1 year ago version_specific_updates_helper.php 1 year 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
133 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 return $agents->should_be_active()->filter_allowed_records()->get_results_as_models();
11 }
12 public static function get_max_capacity_by_service_id($service_id){
13 $service = new OsServiceModel($service_id);
14 return self::get_max_capacity($service);
15 }
16
17 public static function get_min_capacity_by_service_id($service_id){
18 $service = new OsServiceModel($service_id);
19 return self::get_min_capacity($service);
20 }
21
22 public static function get_minimum_duration_across_services(){
23 $service = new OsServiceModel();
24 $services = $service->should_be_active()->get_results_as_models();
25 $min_duration = false;
26 foreach($services as $service){
27 $min_duration = $min_duration ? min($min_duration, $service->duration) : $service->duration;
28 }
29 return $min_duration;
30 }
31
32 public static function get_summary_duration_label($duration){
33 if(!$duration) return '';
34 if(($duration >= 60) && !OsSettingsHelper::is_on('steps_show_duration_in_minutes')){
35 $hours = floor($duration / 60);
36 $minutes = $duration % 60;
37 $summary_duration_label = $hours.' ';
38 $summary_duration_label.= ($hours > 1) ? __('Hours', 'latepoint') : __('Hour', 'latepoint');
39 if($minutes) $summary_duration_label.= ', '.$minutes.' '.__('Minutes', 'latepoint');
40 }else{
41 $summary_duration_label = $duration.' '.__('Minutes', 'latepoint');
42 }
43 return $summary_duration_label;
44 }
45
46 public static function get_max_capacity($service){
47 if($service && !empty($service->capacity_max)){
48 return $service->capacity_max;
49 }
50 return 1;
51 }
52
53 public static function get_min_capacity($service){
54 if($service && !empty($service->capacity_min)){
55 return $service->capacity_min;
56 }
57 return 1;
58 }
59
60 public static function get_percent_of_capacity_booked($service, $total_attendees){
61 $total_attendees = empty($total_attendees) ? 1 : $total_attendees;
62 $max_capacity = self::get_max_capacity($service);
63 return min(100, round($total_attendees / $max_capacity * 100));
64 }
65
66 public static function get_default_colors(){
67 return array('#2752E4', '#C066F1', '#26B7DD', '#E8C634', '#19CED6', '#2FEAA3', '#252a3e', '#8d87a5', '#b9b784');
68 }
69
70 public static function get_default_duration_for_service($service_id){
71 $service = new OsServiceModel($service_id);
72 return $service->duration;
73 }
74
75 public static function service_option_html_for_select($service, $selected = false){
76 ?>
77 <div class="service-option <?php if($selected) { echo 'selected'; } ?>"
78 data-extra-durations="<?php echo esc_attr(wp_json_encode($service->get_extra_durations())); ?>"
79 data-id="<?php echo esc_attr($service->id); ?>"
80 data-buffer-before="<?php echo esc_attr($service->buffer_before); ?>"
81 data-buffer-after="<?php echo esc_attr($service->buffer_after); ?>"
82 data-capacity-min="<?php echo esc_attr($service->capacity_min); ?>"
83 data-capacity-max="<?php echo esc_attr($service->capacity_max); ?>"
84 data-duration-name="<?php echo esc_attr($service->duration_name); ?>"
85 data-duration="<?php echo esc_attr($service->duration); ?>">
86 <div class="service-color" style="background-color: <?php echo esc_attr($service->bg_color); ?>"></div>
87 <span><?php echo esc_html($service->name); ?></span>
88 </div>
89 <?php
90 }
91
92 /**
93 * @param $agent_id
94 * @return OsServiceModel[]
95 */
96 public static function get_services(bool $filter_allowed_records = false): array{
97 $services = new OsServiceModel();
98 if($filter_allowed_records) $services->filter_allowed_records();
99 $services = $services->get_results_as_models();
100 return $services;
101 }
102
103 /**
104 * @param bool $filter_allowed_records
105 * @param array $service_ids
106 *
107 * @return array
108 */
109 public static function get_services_list(bool $filter_allowed_records = false, array $service_ids = []): array{
110 $services = new OsServiceModel();
111 if($filter_allowed_records) $services->filter_allowed_records();
112
113 if (!empty($service_ids)) {
114 $services->where_in('id', $service_ids);
115 }
116
117 $services = $services->get_results_as_models();
118 $services_list = [];
119 if($services){
120 foreach($services as $service){
121 $services_list[] = ['value' => $service->id, 'label' => $service->name];
122 }
123 }
124 return $services_list;
125 }
126
127 public static function has_multiple_durations(int $service_id): bool {
128 $service = new OsServiceModel($service_id);
129 $extra_durations = $service->get_extra_durations();
130 return !empty($extra_durations);
131 }
132
133 }