AmeliaBookingButtonRendererTrait.php
2 months ago
AmeliaBookingModule.php
7 months ago
AmeliaCatalogBookingModule.php
1 month ago
AmeliaCatalogModule.php
7 months ago
AmeliaCustomerPanelModule.php
7 months ago
AmeliaEmployeePanelModule.php
7 months ago
AmeliaEventsCalendarModule.php
1 month ago
AmeliaEventsListBookingButtonModule.php
2 months ago
AmeliaEventsListModule.php
1 month ago
AmeliaEventsModule.php
7 months ago
AmeliaSearchModule.php
7 months ago
AmeliaStepBookingButtonModule.php
2 months ago
AmeliaStepBookingModule.php
1 month ago
ModuleMetadata.php
1 month ago
SharedShortcodeModule.php
1 month ago
index.php
1 month ago
AmeliaBookingModule.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Divi5Amelia; |
| 4 | |
| 5 | use ET\Builder\Framework\DependencyManagement\Interfaces\DependencyInterface; |
| 6 | use ET\Builder\Packages\ModuleLibrary\ModuleRegistration; |
| 7 | |
| 8 | /** |
| 9 | * Class that handle "Amelia Booking" module output in frontend. |
| 10 | */ |
| 11 | class AmeliaBookingModule implements DependencyInterface |
| 12 | { |
| 13 | /** |
| 14 | * Register module. |
| 15 | * DependencyInterface interface ensures class method name `load()` is executed for initialization. |
| 16 | */ |
| 17 | public function load() |
| 18 | { |
| 19 | // Register module. |
| 20 | add_action('init', [AmeliaBookingModule::class, 'registerModule']); |
| 21 | } |
| 22 | |
| 23 | public static function registerModule() |
| 24 | { |
| 25 | // Path to module metadata that is shared between Frontend and Visual Builder. |
| 26 | $module_json_folder_path = dirname(__DIR__, 1) . '/visual-builder/src/modules/Booking'; |
| 27 | |
| 28 | ModuleRegistration::register_module( |
| 29 | $module_json_folder_path, |
| 30 | [ |
| 31 | 'render_callback' => [AmeliaBookingModule::class, 'renderCallback'], |
| 32 | ] |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Render module HTML output. |
| 38 | */ |
| 39 | public static function renderCallback($attrs, $content, $block, $elements) |
| 40 | { |
| 41 | $shortcode = '[ameliastepbooking'; |
| 42 | |
| 43 | $show_all = $attrs['type']['innerContent']['desktop']['value'] ?? null; |
| 44 | if ($show_all !== null && $show_all !== '0') { |
| 45 | $shortcode .= ' show=' . $show_all; |
| 46 | } |
| 47 | |
| 48 | $trigger = $attrs['trigger']['innerContent']['desktop']['value'] ?? null; |
| 49 | if ($trigger !== null && $trigger !== '') { |
| 50 | $shortcode .= ' trigger=' . esc_attr($trigger); |
| 51 | } |
| 52 | |
| 53 | // Layout |
| 54 | $layout = $attrs['layout']['innerContent']['desktop']['value'] ?? null; |
| 55 | if ($layout !== null && $layout !== '') { |
| 56 | $shortcode .= ' layout=' . $layout; |
| 57 | } |
| 58 | |
| 59 | // Trigger Type |
| 60 | $trigger_type = $attrs['trigger_type']['innerContent']['desktop']['value'] ?? null; |
| 61 | if ($trigger && $trigger_type !== null && $trigger_type !== '') { |
| 62 | $shortcode .= ' trigger_type=' . $trigger_type; |
| 63 | } |
| 64 | |
| 65 | // In Dialog |
| 66 | $in_dialog = $attrs['in_dialog']['innerContent']['desktop']['value'] ?? false; |
| 67 | if ($in_dialog === 'on') { |
| 68 | $shortcode .= ' in_dialog=1'; |
| 69 | } |
| 70 | |
| 71 | $preselect = $attrs['parameters']['innerContent']['desktop']['value'] ?? false; |
| 72 | if ($preselect === 'on') { |
| 73 | $category = $attrs['categories']['innerContent']['desktop']['value'] ?? []; |
| 74 | $service = $attrs['services']['innerContent']['desktop']['value'] ?? []; |
| 75 | $employee = $attrs['employees']['innerContent']['desktop']['value'] ?? []; |
| 76 | $location = $attrs['locations']['innerContent']['desktop']['value'] ?? []; |
| 77 | $package = $attrs['packages']['innerContent']['desktop']['value'] ?? []; |
| 78 | |
| 79 | if ($service && count($service) > 0) { |
| 80 | $shortcode .= ' service=' . implode(',', $service); |
| 81 | } elseif ($category && count($category) > 0) { |
| 82 | $shortcode .= ' category=' . implode(',', $category); |
| 83 | } |
| 84 | if ($employee && count($employee) > 0) { |
| 85 | $shortcode .= ' employee=' . implode(',', $employee); |
| 86 | } |
| 87 | if ($location && count($location) > 0) { |
| 88 | $shortcode .= ' location=' . implode(',', $location); |
| 89 | } |
| 90 | if ($package && count($package) > 0) { |
| 91 | $shortcode .= ' package=' . implode(',', $package); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | $shortcode .= ']'; |
| 96 | |
| 97 | return do_shortcode($shortcode); |
| 98 | } |
| 99 | } |
| 100 |