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
AmeliaEmployeePanelModule.php
84 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 Employee Panel" module output in frontend. |
| 11 | */ |
| 12 | class AmeliaEmployeePanelModule 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', [AmeliaEmployeePanelModule::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/EmployeePanel'; |
| 31 | |
| 32 | ModuleRegistration::register_module( |
| 33 | $module_json_folder_path, |
| 34 | [ |
| 35 | 'render_callback' => [AmeliaEmployeePanelModule::class, 'renderCallback'], |
| 36 | ] |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param mixed $value |
| 42 | * @return bool |
| 43 | */ |
| 44 | private static function checkValue($value): bool |
| 45 | { |
| 46 | return isset($value) && $value !== ''; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Render callback for the module |
| 51 | * |
| 52 | * @param array $attrs Module attributes from Visual Builder |
| 53 | * @return string Rendered HTML output |
| 54 | */ |
| 55 | public static function renderCallback(array $attrs): string |
| 56 | { |
| 57 | $shortcode = '[' . ShortcodeAliasService::activeShortcodeTag('employee_panel', 'ameliaemployeepanel') . ' version=2'; |
| 58 | |
| 59 | $trigger = $attrs['trigger']['innerContent']['desktop']['value'] ?? ''; |
| 60 | if (self::checkValue($trigger)) { |
| 61 | $shortcode .= ' trigger=' . esc_attr($trigger); |
| 62 | } |
| 63 | |
| 64 | $appointments = $attrs['appointments']['innerContent']['desktop']['value'] ?? true; |
| 65 | if ($appointments === true || $appointments === 'true' || $appointments === 'on' || $appointments === 1 || $appointments === '1') { |
| 66 | $shortcode .= ' appointments=1'; |
| 67 | } |
| 68 | |
| 69 | $events = $attrs['events']['innerContent']['desktop']['value'] ?? true; |
| 70 | if ($events === true || $events === 'true' || $events === 'on' || $events === 1 || $events === '1') { |
| 71 | $shortcode .= ' events=1'; |
| 72 | } |
| 73 | |
| 74 | $profile = $attrs['profile']['innerContent']['desktop']['value'] ?? false; |
| 75 | if ($profile === true || $profile === 'true' || $profile === 'on' || $profile === 1 || $profile === '1') { |
| 76 | $shortcode .= ' profile-hidden=1'; |
| 77 | } |
| 78 | |
| 79 | $shortcode .= ']'; |
| 80 | |
| 81 | return do_shortcode($shortcode); |
| 82 | } |
| 83 | } |
| 84 |