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
9 months ago
csv_helper.php
9 months ago
customer_helper.php
9 months ago
customer_import_helper.php
4 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
9 months 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
7 months ago
router_helper.php
1 year ago
service_helper.php
1 year ago
sessions_helper.php
1 year ago
settings_helper.php
4 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
5 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
7 months ago
version_specific_updates_helper.php
9 months ago
whatsapp_helper.php
1 year ago
work_periods_helper.php
5 months ago
wp_datetime.php
1 year ago
wp_user_helper.php
1 year ago
timeline_helper.php
141 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Copyright (c) 2022 LatePoint LLC. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | class OsTimelineHelper{ |
| 8 | |
| 9 | /** |
| 10 | * @param \LatePoint\Misc\BookingRequest $booking_request |
| 11 | * @param \LatePoint\Misc\TimePeriod |
| 12 | * @param \LatePoint\Misc\BookingResource[] |
| 13 | * @param array $settings |
| 14 | * @return string |
| 15 | * @throws Exception |
| 16 | */ |
| 17 | public static function availability_timeline(\LatePoint\Misc\BookingRequest $booking_request, \LatePoint\Misc\TimePeriod $timeline_boundaries, array $resources, array $settings = []){ |
| 18 | $default_settings = [ |
| 19 | 'agent_to_show' => false, |
| 20 | 'book_on_click' => true, |
| 21 | 'show_ticks' => true |
| 22 | ]; |
| 23 | $settings = array_merge($default_settings, $settings); |
| 24 | $total_timeline_minutes = $timeline_boundaries->end_time - $timeline_boundaries->start_time; |
| 25 | $html = '<div class="agent-day-availability-w">'; |
| 26 | if($settings['agent_to_show']){ |
| 27 | // show agent avatar if agent was passed |
| 28 | $agent = $settings['agent_to_show']; |
| 29 | $html.= '<a href="'.OsRouterHelper::build_link(['agents', 'edit_form'], ['id' => $agent->id] ).'" class="agent-avatar-w with-hover-name" style="background-image: url('.$agent->get_avatar_url().');"><span>'.$agent->full_name.'</span></a>'; |
| 30 | } |
| 31 | $booking_slots = OsResourceHelper::get_ordered_booking_slots_from_resources($resources); |
| 32 | |
| 33 | $html.= '<div class="agent-timeslots">'; |
| 34 | |
| 35 | if($booking_slots){ |
| 36 | $total_slots = count($booking_slots); |
| 37 | $after_slot_html = false; |
| 38 | $slot_width = false; |
| 39 | $gap = false; |
| 40 | // find minimum gap |
| 41 | $minimum_slot_gap = \LatePoint\Misc\BookingSlot::find_minimum_gap_between_slots($booking_slots); |
| 42 | |
| 43 | if($booking_slots[0]->start_time != $timeline_boundaries->start_time){ |
| 44 | $slot_width = ($booking_slots[0]->start_time - $timeline_boundaries->start_time) / $total_timeline_minutes * 100; |
| 45 | $html.= self::timeline_timeslot_off($slot_width); |
| 46 | } |
| 47 | for($i = 0; $i<$total_slots; $i++){ |
| 48 | if($i == $total_slots - 1){ |
| 49 | // last slot in a day |
| 50 | $prev_width = $slot_width; |
| 51 | $slot_width = ($timeline_boundaries->end_time - $booking_slots[$i]->start_time) / $total_timeline_minutes * 100; |
| 52 | if($prev_width && $prev_width < $slot_width){ |
| 53 | $after_slot_html = self::timeline_timeslot_off($slot_width - $prev_width); |
| 54 | $slot_width = $prev_width; |
| 55 | } |
| 56 | }else{ |
| 57 | $gap = $booking_slots[$i + 1]->start_time - $booking_slots[$i]->start_time; |
| 58 | if($gap > $minimum_slot_gap){ |
| 59 | $slot_width = $minimum_slot_gap / $total_timeline_minutes * 100; |
| 60 | $after_slot_html = self::timeline_timeslot_off(($gap - $minimum_slot_gap) / $total_timeline_minutes * 100); |
| 61 | }else{ |
| 62 | $slot_width = ($booking_slots[$i + 1]->start_time - $booking_slots[$i]->start_time) / $total_timeline_minutes * 100; |
| 63 | } |
| 64 | } |
| 65 | $html.= self::timeline_timeslot($booking_slots[$i], $booking_request, ['show_ticks' => $settings['show_ticks'], 'book_on_click' => $settings['book_on_click'], 'slot_width' => $slot_width]); |
| 66 | if($after_slot_html){ |
| 67 | $html.=$after_slot_html; |
| 68 | $after_slot_html = false; |
| 69 | } |
| 70 | } |
| 71 | }else{ |
| 72 | $html.= self::availability_timeline_off(); |
| 73 | } |
| 74 | $html.= '</div>'; |
| 75 | $html.= '</div>'; |
| 76 | return $html; |
| 77 | } |
| 78 | |
| 79 | public static function availability_timeline_off(string $off_label = ''){ |
| 80 | $off_label = $off_label ? $off_label : __('Not Available', 'latepoint'); |
| 81 | return '<div class="agent-timeslot is-off full-day-off"><span class="agent-timeslot-label">'.$off_label.'</span></div>'; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /** |
| 86 | * @param \LatePoint\Misc\BookingSlot $booking_slot |
| 87 | * @param \LatePoint\Misc\BookingRequest $booking_request |
| 88 | * @param array $settings |
| 89 | * @return string |
| 90 | */ |
| 91 | public static function timeline_timeslot(\LatePoint\Misc\BookingSlot $booking_slot, \LatePoint\Misc\BookingRequest $booking_request, array $settings = []){ |
| 92 | $default_settings = [ |
| 93 | 'book_on_click' => true, |
| 94 | 'show_ticks' => true, |
| 95 | 'slot_width' => false |
| 96 | ]; |
| 97 | $settings = array_merge($default_settings, $settings); |
| 98 | |
| 99 | $ampm = OsTimeHelper::am_or_pm($booking_slot->start_time); |
| 100 | $tick_html = ''; |
| 101 | $timeslot_class = ''; |
| 102 | if($settings['show_ticks'] && ($booking_slot->start_time % 60) == 0){ |
| 103 | $timeslot_class.= ' with-tick'; |
| 104 | $tick_html = '<span class="agent-timeslot-tick"><strong>'. OsTimeHelper::minutes_to_hours($booking_slot->start_time) .'</strong>'.' '.$ampm.'</span>'; |
| 105 | } |
| 106 | |
| 107 | $data_attrs = ''; |
| 108 | if($booking_slot->can_accomodate($booking_request->total_attendees)){ |
| 109 | $timeslot_class.= ' is-available'; |
| 110 | if($settings['book_on_click']){ |
| 111 | // clicking a timeslot will result in opening a new booking slideout |
| 112 | $data_attrs = OsOrdersHelper::quick_order_btn_html(false, ['start_time'=> $booking_slot->start_time, |
| 113 | 'agent_id' => $booking_request->agent_id, |
| 114 | 'service_id' => $booking_request->service_id, |
| 115 | 'location_id' => $booking_request->location_id, |
| 116 | 'start_date' => $booking_request->start_date]); |
| 117 | }else{ |
| 118 | // fills in the data of a booking form slideout |
| 119 | $data_attrs = 'data-date="'.$booking_slot->start_date.'" data-formatted-date="'.OsTimeHelper::reformat_date_string($booking_slot->start_date, 'Y-m-d', OsSettingsHelper::get_date_format()).'" data-minutes="'.$booking_slot->start_time.'"'; |
| 120 | $timeslot_class.= ' fill-booking-time'; |
| 121 | } |
| 122 | }else{ |
| 123 | $timeslot_class.= ' is-booked'; |
| 124 | } |
| 125 | $style = $settings['slot_width'] ? 'width: '.$settings['slot_width'].'%' : ''; |
| 126 | $timeslot_html = '<div '.$data_attrs.' style="'.$style.'" class="agent-timeslot '.$timeslot_class.'"> |
| 127 | <span class="agent-timeslot-label"><div class="at-sub-value">'.OsTimeHelper::get_nice_date_with_optional_year($booking_slot->start_date).'</div><div class="at-main-value">'.OsTimeHelper::minutes_to_hours_and_minutes($booking_slot->start_time).'</div></span>'. |
| 128 | $tick_html.' |
| 129 | </div>'; |
| 130 | return $timeslot_html; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | public static function timeline_timeslot_off($slot_width){ |
| 137 | return '<div class="agent-timeslot is-off" style="width: '.esc_attr($slot_width).'%"><span class="agent-timeslot-label">'.__('Not Available', 'latepoint').'</span></div>'; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | } |