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
AmeliaEventsModule.php
78 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 Events" (legacy) module output in frontend. |
| 10 | */ |
| 11 | class AmeliaEventsModule 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', [AmeliaEventsModule::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/Events'; |
| 27 | |
| 28 | ModuleRegistration::register_module( |
| 29 | $module_json_folder_path, |
| 30 | [ |
| 31 | 'render_callback' => [AmeliaEventsModule::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 = '[ameliaevents'; |
| 42 | |
| 43 | $type = $attrs['type']['innerContent']['desktop']['value'] ?? null; |
| 44 | if ($type !== null && $type !== '') { |
| 45 | $shortcode .= ' type=' . $type; |
| 46 | } else { |
| 47 | $shortcode .= ' type=list'; |
| 48 | } |
| 49 | |
| 50 | $trigger = $attrs['trigger']['innerContent']['desktop']['value'] ?? null; |
| 51 | if ($trigger !== null && $trigger !== '') { |
| 52 | $shortcode .= ' trigger=' . esc_attr($trigger); |
| 53 | } |
| 54 | |
| 55 | $bookingParams = $attrs['booking_params']['innerContent']['desktop']['value'] ?? 'off'; |
| 56 | if ($bookingParams === 'on') { |
| 57 | $event = $attrs['events']['innerContent']['desktop']['value'] ?? '0'; |
| 58 | if ($event !== '0') { |
| 59 | $shortcode .= ' event=' . $event; |
| 60 | } |
| 61 | |
| 62 | $tag = $attrs['tags']['innerContent']['desktop']['value'] ?? '0'; |
| 63 | if ($tag !== null && $tag !== '' && $tag !== '0') { |
| 64 | $shortcode .= ' tag="' . esc_attr($tag) . '"'; |
| 65 | } |
| 66 | |
| 67 | $recurring = $attrs['recurring']['innerContent']['desktop']['value'] ?? 'off'; |
| 68 | if ($recurring === 'on') { |
| 69 | $shortcode .= ' recurring=1'; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | $shortcode .= ']'; |
| 74 | |
| 75 | return do_shortcode($shortcode); |
| 76 | } |
| 77 | } |
| 78 |