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
AmeliaEventsCalendarModule.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Divi5Amelia; |
| 4 | |
| 5 | use ET\Builder\Packages\ModuleLibrary\ModuleRegistration; |
| 6 | |
| 7 | /** |
| 8 | * Class that handle "Amelia Events Calendar" module output in frontend. |
| 9 | */ |
| 10 | class AmeliaEventsCalendarModule extends SharedShortcodeModule |
| 11 | { |
| 12 | /** |
| 13 | * Register module. |
| 14 | * DependencyInterface interface ensures class method name `load()` is executed for initialization. |
| 15 | */ |
| 16 | public function load() |
| 17 | { |
| 18 | // Register module. |
| 19 | add_action('init', [AmeliaEventsCalendarModule::class, 'registerModule']); |
| 20 | } |
| 21 | |
| 22 | public static function registerModule() |
| 23 | { |
| 24 | // Path to module metadata that is shared between Frontend and Visual Builder. |
| 25 | $module_json_folder_path = dirname(__DIR__, 1) . '/visual-builder/src/modules/EventsCalendar'; |
| 26 | |
| 27 | ModuleRegistration::register_module( |
| 28 | $module_json_folder_path, |
| 29 | [ |
| 30 | 'render_callback' => [AmeliaEventsCalendarModule::class, 'renderCallback'], |
| 31 | ] |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Render module HTML output. |
| 37 | */ |
| 38 | public static function renderCallback($attrs, $content, $block, $elements) |
| 39 | { |
| 40 | $shortcode = '[ameliaeventscalendarbooking'; |
| 41 | |
| 42 | $shortcode .= self::getSharedShortcodeString($attrs); |
| 43 | |
| 44 | $booking_params = $attrs['booking_params']['innerContent']['desktop']['value'] ?? false; |
| 45 | if ($booking_params === 'on') { |
| 46 | $event = $attrs['events']['innerContent']['desktop']['value'] ?? []; |
| 47 | if ($event && count($event) > 0) { |
| 48 | $shortcode .= ' event=' . implode(',', $event); |
| 49 | } |
| 50 | |
| 51 | $tag = $attrs['tags']['innerContent']['desktop']['value'] ?? []; |
| 52 | if ($tag && count($tag) > 0) { |
| 53 | $shortcode .= ' tag="' . implode(',', array_map(function ($t) { |
| 54 | return '{' . $t . '}'; |
| 55 | }, $tag)) . '"'; |
| 56 | } |
| 57 | |
| 58 | $recurring = $attrs['recurring']['innerContent']['desktop']['value'] ?? false; |
| 59 | if ($recurring === 'on') { |
| 60 | $shortcode .= ' recurring=1'; |
| 61 | } |
| 62 | |
| 63 | $locations = $attrs['locations']['innerContent']['desktop']['value'] ?? []; |
| 64 | if ($locations && count($locations) > 0) { |
| 65 | $shortcode .= ' location=' . implode(',', $locations); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | $shortcode .= ']'; |
| 70 | |
| 71 | return do_shortcode($shortcode); |
| 72 | } |
| 73 | } |
| 74 |