activities_helper.php
3 months ago
agent_helper.php
3 months ago
analytics_helper.php
1 week ago
auth_helper.php
6 days ago
blocks_helper.php
3 weeks ago
booking_helper.php
4 days ago
bricks_helper.php
3 months ago
bundles_helper.php
4 days ago
calendar_helper.php
2 days ago
carts_helper.php
3 months ago
connector_helper.php
3 months ago
csv_helper.php
3 months ago
customer_helper.php
1 month ago
customer_import_helper.php
1 month ago
database_helper.php
1 week 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 weeks 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 weeks 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
2 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
2 months ago
plugin_version_update_helper.php
2 months ago
price_breakdown_helper.php
3 months ago
process_jobs_helper.php
3 months ago
processes_helper.php
3 months ago
razorpay_connect_helper.php
1 week ago
replacer_helper.php
3 months ago
resource_helper.php
4 days ago
roles_helper.php
3 weeks ago
router_helper.php
3 months ago
service_helper.php
3 months ago
sessions_helper.php
3 months ago
settings_helper.php
1 week ago
short_links_systems_helper.php
3 months ago
shortcodes_helper.php
3 weeks ago
sms_helper.php
3 months ago
steps_helper.php
1 week ago
stripe_connect_helper.php
1 week ago
styles_helper.php
3 months ago
support_topics_helper.php
3 months ago
time_helper.php
2 months ago
timeline_helper.php
2 months ago
transaction_helper.php
1 month ago
transaction_intent_helper.php
3 months ago
util_helper.php
1 month ago
version_specific_updates_helper.php
3 months ago
whatsapp_helper.php
1 month ago
work_periods_helper.php
3 months ago
wp_datetime.php
3 months ago
wp_user_helper.php
3 months ago
timeline_helper.php
158 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 | |
| 26 | $html = '<div class="agent-day-availability-w">'; |
| 27 | |
| 28 | if ( $settings['agent_to_show'] ) { |
| 29 | // show agent avatar if agent was passed |
| 30 | $agent = $settings['agent_to_show']; |
| 31 | $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>'; |
| 32 | } |
| 33 | |
| 34 | $booking_slots = OsResourceHelper::get_ordered_booking_slots_from_resources( $resources ); |
| 35 | |
| 36 | $html .= '<div class="agent-timeslots">'; |
| 37 | |
| 38 | if ( $booking_slots && $total_timeline_minutes > 0 ) { |
| 39 | $total_slots = count( $booking_slots ); |
| 40 | $after_slot_html = false; |
| 41 | $slot_width = false; |
| 42 | $gap = false; |
| 43 | // find minimum gap |
| 44 | $minimum_slot_gap = \LatePoint\Misc\BookingSlot::find_minimum_gap_between_slots( $booking_slots ); |
| 45 | |
| 46 | if ( $booking_slots[0]->start_time != $timeline_boundaries->start_time ) { |
| 47 | $slot_width = ( $booking_slots[0]->start_time - $timeline_boundaries->start_time ) / $total_timeline_minutes * 100; |
| 48 | $html .= self::timeline_timeslot_off( $slot_width ); |
| 49 | } |
| 50 | for ( $i = 0; $i < $total_slots; $i++ ) { |
| 51 | if ( $i == $total_slots - 1 ) { |
| 52 | // last slot in a day |
| 53 | $prev_width = $slot_width; |
| 54 | $slot_width = ( $timeline_boundaries->end_time - $booking_slots[ $i ]->start_time ) / $total_timeline_minutes * 100; |
| 55 | if ( $prev_width && $prev_width < $slot_width ) { |
| 56 | $after_slot_html = self::timeline_timeslot_off( $slot_width - $prev_width ); |
| 57 | $slot_width = $prev_width; |
| 58 | } |
| 59 | } else { |
| 60 | $gap = $booking_slots[ $i + 1 ]->start_time - $booking_slots[ $i ]->start_time; |
| 61 | if ( $gap > $minimum_slot_gap ) { |
| 62 | $slot_width = $minimum_slot_gap / $total_timeline_minutes * 100; |
| 63 | $after_slot_html = self::timeline_timeslot_off( ( $gap - $minimum_slot_gap ) / $total_timeline_minutes * 100 ); |
| 64 | } else { |
| 65 | $slot_width = ( $booking_slots[ $i + 1 ]->start_time - $booking_slots[ $i ]->start_time ) / $total_timeline_minutes * 100; |
| 66 | } |
| 67 | } |
| 68 | $html .= self::timeline_timeslot( |
| 69 | $booking_slots[ $i ], |
| 70 | $booking_request, |
| 71 | [ |
| 72 | 'show_ticks' => $settings['show_ticks'], |
| 73 | 'book_on_click' => $settings['book_on_click'], |
| 74 | 'slot_width' => $slot_width, |
| 75 | ] |
| 76 | ); |
| 77 | if ( $after_slot_html ) { |
| 78 | $html .= $after_slot_html; |
| 79 | $after_slot_html = false; |
| 80 | } |
| 81 | } |
| 82 | } else { |
| 83 | $html .= self::availability_timeline_off(); |
| 84 | } |
| 85 | |
| 86 | $html .= '</div>'; |
| 87 | $html .= '</div>'; |
| 88 | |
| 89 | return $html; |
| 90 | } |
| 91 | |
| 92 | public static function availability_timeline_off( string $off_label = '' ) { |
| 93 | $off_label = $off_label ? $off_label : __( 'Not Available', 'latepoint' ); |
| 94 | return '<div class="agent-timeslot is-off full-day-off"><span class="agent-timeslot-label">' . $off_label . '</span></div>'; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /** |
| 99 | * @param \LatePoint\Misc\BookingSlot $booking_slot |
| 100 | * @param \LatePoint\Misc\BookingRequest $booking_request |
| 101 | * @param array $settings |
| 102 | * @return string |
| 103 | */ |
| 104 | public static function timeline_timeslot( \LatePoint\Misc\BookingSlot $booking_slot, \LatePoint\Misc\BookingRequest $booking_request, array $settings = [] ) { |
| 105 | $default_settings = [ |
| 106 | 'book_on_click' => true, |
| 107 | 'show_ticks' => true, |
| 108 | 'slot_width' => false, |
| 109 | ]; |
| 110 | $settings = array_merge( $default_settings, $settings ); |
| 111 | |
| 112 | $ampm = OsTimeHelper::am_or_pm( $booking_slot->start_time ); |
| 113 | $tick_html = ''; |
| 114 | $timeslot_class = ''; |
| 115 | if ( $settings['show_ticks'] && ( $booking_slot->start_time % 60 ) == 0 ) { |
| 116 | $timeslot_class .= ' with-tick'; |
| 117 | $tick_html = '<span class="agent-timeslot-tick"><strong>' . OsTimeHelper::minutes_to_hours( $booking_slot->start_time ) . '</strong> ' . $ampm . '</span>'; |
| 118 | } |
| 119 | |
| 120 | $data_attrs = ''; |
| 121 | if ( $booking_slot->can_accomodate( $booking_request->total_attendees ) ) { |
| 122 | $timeslot_class .= ' is-available'; |
| 123 | if ( $settings['book_on_click'] ) { |
| 124 | // clicking a timeslot will result in opening a new booking slideout |
| 125 | $data_attrs = OsOrdersHelper::quick_order_btn_html( |
| 126 | false, |
| 127 | [ |
| 128 | 'start_time' => $booking_slot->start_time, |
| 129 | 'agent_id' => $booking_request->agent_id, |
| 130 | 'service_id' => $booking_request->service_id, |
| 131 | 'location_id' => $booking_request->location_id, |
| 132 | 'start_date' => $booking_request->start_date, |
| 133 | ] |
| 134 | ); |
| 135 | } else { |
| 136 | // fills in the data of a booking form slideout |
| 137 | $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 . '"'; |
| 138 | $timeslot_class .= ' fill-booking-time'; |
| 139 | } |
| 140 | } else { |
| 141 | $timeslot_class .= ' is-booked'; |
| 142 | } |
| 143 | $style = $settings['slot_width'] ? 'width: ' . $settings['slot_width'] . '%' : ''; |
| 144 | $timeslot_html = '<div ' . $data_attrs . ' style="' . $style . '" class="agent-timeslot ' . $timeslot_class . '"> |
| 145 | <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>' . |
| 146 | $tick_html . ' |
| 147 | </div>'; |
| 148 | return $timeslot_html; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | public static function timeline_timeslot_off( $slot_width ) { |
| 155 | return '<div class="agent-timeslot is-off" style="width: ' . esc_attr( $slot_width ) . '%"><span class="agent-timeslot-label">' . __( 'Not Available', 'latepoint' ) . '</span></div>'; |
| 156 | } |
| 157 | } |
| 158 |