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
AmeliaCustomerPanelModule.php
70 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 Customer Panel" module output in frontend. |
| 11 | */ |
| 12 | class AmeliaCustomerPanelModule 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', [AmeliaCustomerPanelModule::class, 'registerModule']); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Register module. |
| 26 | */ |
| 27 | public static function registerModule() |
| 28 | { |
| 29 | // Path to module metadata that is shared between Frontend and Visual Builder. |
| 30 | $module_json_folder_path = dirname(__DIR__, 1) . '/visual-builder/src/modules/CustomerPanel'; |
| 31 | |
| 32 | ModuleRegistration::register_module( |
| 33 | $module_json_folder_path, |
| 34 | [ |
| 35 | 'render_callback' => [AmeliaCustomerPanelModule::class, 'renderCallback'], |
| 36 | ] |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Render callback for the module |
| 42 | * |
| 43 | * @param array $attrs Module attributes from Visual Builder |
| 44 | * @return string Rendered HTML output |
| 45 | */ |
| 46 | public static function renderCallback(array $attrs): string |
| 47 | { |
| 48 | $shortcode = '[' . ShortcodeAliasService::activeShortcodeTag('customer_panel', 'ameliacustomerpanel') . ' version=2'; |
| 49 | |
| 50 | $trigger = $attrs['trigger']['innerContent']['desktop']['value'] ?? ''; |
| 51 | if ($trigger) { |
| 52 | $shortcode .= ' trigger=' . esc_attr($trigger); |
| 53 | } |
| 54 | |
| 55 | $appointments = $attrs['appointments']['innerContent']['desktop']['value'] ?? true; |
| 56 | if ($appointments === true || $appointments === 'true' || $appointments === 'on' || $appointments === 1 || $appointments === '1') { |
| 57 | $shortcode .= ' appointments=1'; |
| 58 | } |
| 59 | |
| 60 | $events = $attrs['events']['innerContent']['desktop']['value'] ?? true; |
| 61 | if ($events === true || $events === 'true' || $events === 'on' || $events === 1 || $events === '1') { |
| 62 | $shortcode .= ' events=1'; |
| 63 | } |
| 64 | |
| 65 | $shortcode .= ']'; |
| 66 | |
| 67 | return do_shortcode($shortcode); |
| 68 | } |
| 69 | } |
| 70 |