AmeliaBookingButtonRendererTrait.php
3 months ago
AmeliaBookingModule.php
1 day ago
AmeliaCatalogBookingModule.php
1 day ago
AmeliaCatalogModule.php
1 day ago
AmeliaCatalogShortcodeHelper.php
1 day ago
AmeliaCustomerPanelModule.php
1 day ago
AmeliaEmployeePanelModule.php
1 day ago
AmeliaEventsCalendarModule.php
1 day ago
AmeliaEventsListBookingButtonModule.php
1 day ago
AmeliaEventsListModule.php
1 day ago
AmeliaEventsModule.php
1 day ago
AmeliaSearchModule.php
1 day ago
AmeliaStepBookingButtonModule.php
1 day ago
AmeliaStepBookingModule.php
1 day ago
ModuleMetadata.php
2 months ago
SharedShortcodeModule.php
2 months ago
index.php
1 day ago
AmeliaEventsModule.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Divi5Amelia; |
| 4 | |
| 5 | use AmeliaBooking\Infrastructure\WP\ShortcodeService\ShortcodeAliasService; |
| 6 | use ET\Builder\Framework\DependencyManagement\Interfaces\DependencyInterface; |
| 7 | use ET\Builder\Packages\ModuleLibrary\ModuleRegistration; |
| 8 | |
| 9 | /** |
| 10 | * Class that handle "Amelia Events" (legacy) module output in frontend. |
| 11 | */ |
| 12 | class AmeliaEventsModule implements DependencyInterface |
| 13 | { |
| 14 | /** |
| 15 | * Register module. |
| 16 | * DependencyInterface interface ensures class method name `load()` is executed for initialization. |
| 17 | */ |
| 18 | public function load() |
| 19 | { |
| 20 | // Register module. |
| 21 | add_action('init', [AmeliaEventsModule::class, 'registerModule']); |
| 22 | } |
| 23 | |
| 24 | public static function registerModule() |
| 25 | { |
| 26 | // Path to module metadata that is shared between Frontend and Visual Builder. |
| 27 | $module_json_folder_path = dirname(__DIR__, 1) . '/visual-builder/src/modules/Events'; |
| 28 | |
| 29 | ModuleRegistration::register_module( |
| 30 | $module_json_folder_path, |
| 31 | [ |
| 32 | 'render_callback' => [AmeliaEventsModule::class, 'renderCallback'], |
| 33 | ] |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Render module HTML output. |
| 39 | */ |
| 40 | public static function renderCallback($attrs, $content, $block, $elements) |
| 41 | { |
| 42 | $shortcode = '[' . ShortcodeAliasService::activeShortcodeTag('events', 'ameliaevents'); |
| 43 | |
| 44 | $type = $attrs['type']['innerContent']['desktop']['value'] ?? null; |
| 45 | if ($type !== null && $type !== '') { |
| 46 | $shortcode .= ' type=' . $type; |
| 47 | } else { |
| 48 | $shortcode .= ' type=list'; |
| 49 | } |
| 50 | |
| 51 | $trigger = $attrs['trigger']['innerContent']['desktop']['value'] ?? null; |
| 52 | if ($trigger !== null && $trigger !== '') { |
| 53 | $shortcode .= ' trigger=' . esc_attr($trigger); |
| 54 | } |
| 55 | |
| 56 | $bookingParams = $attrs['booking_params']['innerContent']['desktop']['value'] ?? 'off'; |
| 57 | if ($bookingParams === 'on') { |
| 58 | $event = $attrs['events']['innerContent']['desktop']['value'] ?? '0'; |
| 59 | if ($event !== '0') { |
| 60 | $shortcode .= ' event=' . $event; |
| 61 | } |
| 62 | |
| 63 | $tag = $attrs['tags']['innerContent']['desktop']['value'] ?? '0'; |
| 64 | if ($tag !== null && $tag !== '' && $tag !== '0') { |
| 65 | $shortcode .= ' tag="' . esc_attr($tag) . '"'; |
| 66 | } |
| 67 | |
| 68 | $recurring = $attrs['recurring']['innerContent']['desktop']['value'] ?? 'off'; |
| 69 | if ($recurring === 'on') { |
| 70 | $shortcode .= ' recurring=1'; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | $shortcode .= ']'; |
| 75 | |
| 76 | return do_shortcode($shortcode); |
| 77 | } |
| 78 | } |
| 79 |