booking = $booking;
$this->args = $args;
$this->offering = $this->booking->getOffering();
// Settings
$this->settings = Config::general();
// Plugin Profile
self::$profile = Profile::getInstance();
}
/**
* Display the Booking Module
*
* @return string
*/
public function display(): string
{
Assets::enqueueFrontend(['booking']);
['available' => $bookable, 'reason' => $reason] = $this->offering->isBookable();
// Is not Bookable
if (!$bookable)
{
$output = '
'
. EmptyState::info(esc_html__('Booking is currently unavailable for this offering.', 'daytidy'))
. '
';
return (string) apply_filters('DayTidy/F__DayTidy/Booking/Generator__display/not_bookable', $output, $reason);
}
// Steps Handler
$steps = $this->getSteps();
$output = self::view()->render($this->getPath(), [
'booking' => $this->booking,
'offering' => $this->offering,
'steps' => $steps,
'args' => $this->args,
]);
if (!SingleOfferingContext::current())
{
Assets::enqueueFrontend(['single-offering']);
$offering_id = $this->offering->id();
$context = new SingleOfferingContext($offering_id, ['standalone' => true], '');
$available_elements = SingleOfferingRegistry::elements();
$elements = ['booking' => $output];
foreach (['taxonomies', 'title', 'featured_image'] as $key)
{
$element = $available_elements[$key] ?? null;
if ($element)
{
$markup = trim((string) $element->render($context));
if ($markup !== '') $elements[$key] = $markup;
}
}
$description = trim(wp_strip_all_tags(strip_shortcodes((string) get_post_field('post_content', $offering_id))));
if ($description === '') $description = trim((string) get_post_field('post_excerpt', $offering_id));
if ($description !== '') $elements['content'] = '' . esc_html(wp_trim_words($description, 60)) . '
';
$output = self::view()->render('single-offering.style2', [
'context' => $context,
'sticky_sidebar' => !empty(SingleOfferingConfig::forOffering($offering_id)['sticky_sidebar']),
'elements' => $elements,
'has_booking' => true,
'summary' => '',
'content_heading' => __('About this offering', 'daytidy'),
'schedule_and_pricing' => [],
'schedule_pricing_heading' => '',
'schedule_heading' => '',
'pricing_heading' => '',
'custom_cost_heading' => false,
'offering_cost_title' => __('Offering cost', 'daytidy'),
'pricing_options' => [],
'has_pricing' => false,
'taxonomy_terms' => ['categories' => [], 'tags' => [], 'labels' => []],
'overview_cards' => [],
'has_overview' => isset($elements['featured_image']) || isset($elements['content']),
]);
$output = '' . $output . '
';
}
return '' . (string) apply_filters('DayTidy/F__DayTidy/Booking/Generator__display/output', $output, $this) . '
';
}
public function thankyou(string $message): string
{
// Steps Handler
$steps = $this->getSteps();
return $steps->thankyou($message);
}
public function getSteps(): Steps
{
return new Steps($this->booking, $this->settings);
}
/**
* Get Booking Method Path
*
* @return string
*/
private function getPath(): string
{
if ($this->booking->getBookingMethod() === BookingMethods::DATE_TIME_OPTION) return 'booking.module.methods.date-time-option';
if ($this->booking->getBookingMethod() === BookingMethods::OPTION_SESSION) return 'booking.module.methods.option-session';
return 'booking.module.methods.session-option';
}
}