AmeliaBookingButtonRendererTrait.php
3 months ago
AmeliaBookingModule.php
2 days ago
AmeliaCatalogBookingModule.php
2 days ago
AmeliaCatalogModule.php
2 days ago
AmeliaCatalogShortcodeHelper.php
2 days ago
AmeliaCustomerPanelModule.php
2 days ago
AmeliaEmployeePanelModule.php
2 days ago
AmeliaEventsCalendarModule.php
2 days ago
AmeliaEventsListBookingButtonModule.php
2 days ago
AmeliaEventsListModule.php
2 days ago
AmeliaEventsModule.php
2 days ago
AmeliaSearchModule.php
2 days ago
AmeliaStepBookingButtonModule.php
2 days ago
AmeliaStepBookingModule.php
2 days ago
ModuleMetadata.php
2 months ago
SharedShortcodeModule.php
2 months ago
index.php
2 days ago
AmeliaCatalogModule.php
81 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 Catalog" (legacy) module output in frontend. |
| 11 | */ |
| 12 | class AmeliaCatalogModule 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', [AmeliaCatalogModule::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/Catalog'; |
| 28 | |
| 29 | ModuleRegistration::register_module( |
| 30 | $module_json_folder_path, |
| 31 | [ |
| 32 | 'render_callback' => [AmeliaCatalogModule::class, 'renderCallback'], |
| 33 | ] |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Render module HTML output. |
| 39 | * This converts old divi_catalog to ameliacatalogbooking shortcode. |
| 40 | */ |
| 41 | public static function renderCallback($attrs, $content, $block, $elements) |
| 42 | { |
| 43 | $catalogView = $attrs['catalog_view']['innerContent']['desktop']['value'] ?? '0'; |
| 44 | $type = $attrs['type']['innerContent']['desktop']['value'] ?? null; |
| 45 | |
| 46 | $shortcode = '[' . ShortcodeAliasService::activeShortcodeTag('catalogbooking', 'ameliacatalogbooking'); |
| 47 | $shortcode .= AmeliaCatalogShortcodeHelper::buildCatalogBookingShowAttribute($catalogView, $type); |
| 48 | |
| 49 | // Handle catalog view |
| 50 | if ($catalogView && $catalogView !== '0') { |
| 51 | // Map the categories/services/packages based on view |
| 52 | if ($catalogView === 'category') { |
| 53 | $categories = $attrs['categories_catalog']['innerContent']['desktop']['value'] ?? []; |
| 54 | if ($categories && count($categories) > 0) { |
| 55 | $shortcode .= ' category=' . implode(',', $categories); |
| 56 | } |
| 57 | } elseif ($catalogView === 'service') { |
| 58 | $services = $attrs['services_catalog']['innerContent']['desktop']['value'] ?? []; |
| 59 | if ($services && count($services) > 0) { |
| 60 | $shortcode .= ' service=' . implode(',', $services); |
| 61 | } |
| 62 | } elseif ($catalogView === 'package') { |
| 63 | $packages = $attrs['packages_catalog']['innerContent']['desktop']['value'] ?? []; |
| 64 | if ($packages && count($packages) > 0) { |
| 65 | $shortcode .= ' package=' . implode(',', $packages); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Trigger |
| 71 | $trigger = $attrs['trigger']['innerContent']['desktop']['value'] ?? null; |
| 72 | if ($trigger !== null && $trigger !== '') { |
| 73 | $shortcode .= ' trigger=' . esc_attr($trigger); |
| 74 | } |
| 75 | |
| 76 | $shortcode .= ']'; |
| 77 | |
| 78 | return do_shortcode($shortcode); |
| 79 | } |
| 80 | } |
| 81 |