PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / extensions / divi_5_amelia / server / AmeliaEventsListModule.php
ameliabooking / extensions / divi_5_amelia / server Last commit date
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
AmeliaEventsListModule.php
95 lines
1 <?php
2
3 namespace Divi5Amelia;
4
5 use AmeliaBooking\Infrastructure\WP\ShortcodeService\ShortcodeAliasService;
6 use ET\Builder\Packages\ModuleLibrary\ModuleRegistration;
7
8 /**
9 * Class that handle "Amelia Events List" module output in frontend.
10 */
11 class AmeliaEventsListModule extends SharedShortcodeModule
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', [AmeliaEventsListModule::class, 'registerModule']);
21 }
22
23 public static function registerModule()
24 {
25 // Path to module metadata that is shared between Frontend and Visual Builder.
26 $module_json_folder_path = dirname(__DIR__, 1) . '/visual-builder/src/modules/EventsList';
27
28 ModuleRegistration::register_module(
29 $module_json_folder_path,
30 [
31 'render_callback' => [AmeliaEventsListModule::class, 'renderCallback'],
32 ]
33 );
34 }
35
36 /**
37 * Render module HTML output.
38 */
39 public static function renderCallback($attrs, $content, $block, $elements)
40 {
41 $shortcode = '[' . ShortcodeAliasService::activeShortcodeTag('eventslistbooking', 'ameliaeventslistbooking');
42
43 $shortcode .= self::getSharedShortcodeString($attrs);
44
45 // Preselect/filter parameters
46 $booking_params = $attrs['booking_params']['innerContent']['desktop']['value'] ?? false;
47 if ($booking_params === 'on') {
48 $event = $attrs['events']['innerContent']['desktop']['value'] ?? [];
49 if ($event && count($event) > 0) {
50 $shortcode .= ' event=' . implode(',', $event);
51 }
52
53 $event_to_show = $attrs['event_to_show']['innerContent']['desktop']['value'] ?? 'all';
54 if (count($event) === 0 && $event_to_show !== 'all') {
55 if ($event_to_show === 'custom') {
56 $start_date = $attrs['start_date']['innerContent']['desktop']['value'] ?? '';
57 $end_date = $attrs['end_date']['innerContent']['desktop']['value'] ?? '';
58
59 $has_valid_start = $start_date && preg_match('/^\d{4}-\d{2}-\d{2}$/', $start_date);
60 $has_valid_end = $end_date && preg_match('/^\d{4}-\d{2}-\d{2}$/', $end_date);
61
62 if (!$has_valid_start || !$has_valid_end) {
63 return '';
64 }
65
66 $shortcode .= ' range="' . esc_attr($start_date) . ' - ' . esc_attr($end_date) . '"';
67 } else {
68 $shortcode .= ' range="' . esc_attr($event_to_show) . '"';
69 }
70 }
71
72 $tag = $attrs['tags']['innerContent']['desktop']['value'] ?? [];
73 if ($tag && count($tag) > 0) {
74 $shortcode .= ' tag="' . implode(',', array_map(function ($t) {
75 return '{' . $t . '}';
76 }, $tag)) . '"';
77 }
78
79 $recurring = $attrs['recurring']['innerContent']['desktop']['value'] ?? false;
80 if ($recurring === 'on') {
81 $shortcode .= ' recurring=1';
82 }
83
84 $locations = $attrs['locations']['innerContent']['desktop']['value'] ?? [];
85 if ($locations && count($locations) > 0) {
86 $shortcode .= ' location=' . implode(',', $locations);
87 }
88 }
89
90 $shortcode .= ']';
91
92 return do_shortcode($shortcode);
93 }
94 }
95