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
AmeliaEmployeePanelModule.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Divi5Amelia; |
| 4 | |
| 5 | use ET\Builder\Framework\DependencyManagement\Interfaces\DependencyInterface; |
| 6 | use ET\Builder\Packages\ModuleLibrary\ModuleRegistration; |
| 7 | |
| 8 | /** |
| 9 | * Class that handle "Amelia Employee Panel" module output in frontend. |
| 10 | */ |
| 11 | class AmeliaEmployeePanelModule implements DependencyInterface |
| 12 | { |
| 13 | /** |
| 14 | * Register module. |
| 15 | * DependencyInterface interface ensures class method name `load()` is executed for initialization. |
| 16 | */ |
| 17 | public function load() |
| 18 | { |
| 19 | // Register module. |
| 20 | add_action('init', [AmeliaEmployeePanelModule::class, 'registerModule']); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Register module. |
| 25 | */ |
| 26 | public static function registerModule() |
| 27 | { |
| 28 | // Path to module metadata that is shared between Frontend and Visual Builder. |
| 29 | $module_json_folder_path = dirname(__DIR__, 1) . '/visual-builder/src/modules/EmployeePanel'; |
| 30 | |
| 31 | ModuleRegistration::register_module( |
| 32 | $module_json_folder_path, |
| 33 | [ |
| 34 | 'render_callback' => [AmeliaEmployeePanelModule::class, 'renderCallback'], |
| 35 | ] |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param mixed $value |
| 41 | * @return bool |
| 42 | */ |
| 43 | private static function checkValue($value): bool |
| 44 | { |
| 45 | return isset($value) && $value !== ''; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Render callback for the module |
| 50 | * |
| 51 | * @param array $attrs Module attributes from Visual Builder |
| 52 | * @return string Rendered HTML output |
| 53 | */ |
| 54 | public static function renderCallback(array $attrs): string |
| 55 | { |
| 56 | $shortcode = '[ameliaemployeepanel version=2'; |
| 57 | |
| 58 | $trigger = $attrs['trigger']['innerContent']['desktop']['value'] ?? ''; |
| 59 | if (self::checkValue($trigger)) { |
| 60 | $shortcode .= ' trigger=' . esc_attr($trigger); |
| 61 | } |
| 62 | |
| 63 | $appointments = $attrs['appointments']['innerContent']['desktop']['value'] ?? true; |
| 64 | if ($appointments === true || $appointments === 'true' || $appointments === 'on' || $appointments === 1 || $appointments === '1') { |
| 65 | $shortcode .= ' appointments=1'; |
| 66 | } |
| 67 | |
| 68 | $events = $attrs['events']['innerContent']['desktop']['value'] ?? true; |
| 69 | if ($events === true || $events === 'true' || $events === 'on' || $events === 1 || $events === '1') { |
| 70 | $shortcode .= ' events=1'; |
| 71 | } |
| 72 | |
| 73 | $profile = $attrs['profile']['innerContent']['desktop']['value'] ?? false; |
| 74 | if ($profile === true || $profile === 'true' || $profile === 'on' || $profile === 1 || $profile === '1') { |
| 75 | $shortcode .= ' profile-hidden=1'; |
| 76 | } |
| 77 | |
| 78 | $shortcode .= ']'; |
| 79 | |
| 80 | return do_shortcode($shortcode); |
| 81 | } |
| 82 | } |
| 83 |