PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.9 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 / AmeliaStepBookingButtonModule.php
ameliabooking / extensions / divi_5_amelia / server Last commit date
AmeliaBookingButtonRendererTrait.php 3 months ago AmeliaBookingModule.php 1 week ago AmeliaCatalogBookingModule.php 1 week ago AmeliaCatalogModule.php 1 week ago AmeliaCatalogShortcodeHelper.php 1 week ago AmeliaCustomerPanelModule.php 1 week ago AmeliaEmployeePanelModule.php 1 week ago AmeliaEventsCalendarModule.php 1 week ago AmeliaEventsListBookingButtonModule.php 1 week ago AmeliaEventsListModule.php 1 week ago AmeliaEventsModule.php 1 week ago AmeliaSearchModule.php 1 week ago AmeliaStepBookingButtonModule.php 1 week ago AmeliaStepBookingModule.php 1 week ago ModuleMetadata.php 2 months ago SharedShortcodeModule.php 2 months ago index.php 1 week ago
AmeliaStepBookingButtonModule.php
211 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\FrontEnd\Module\Style;
8 use ET\Builder\Packages\Module\Layout\Components\ModuleElements\ModuleElements;
9 use ET\Builder\Packages\Module\Options\Element\ElementClassnames;
10 use ET\Builder\Packages\ModuleLibrary\ModuleRegistration;
11 use WP_Block;
12
13 /**
14 * Class that handles "Amelia Step Booking Button" module output in frontend.
15 */
16 class AmeliaStepBookingButtonModule implements DependencyInterface
17 {
18 use AmeliaBookingButtonRendererTrait;
19
20 private const BUTTON_BASE_CLASS = 'amelia-step-booking-button';
21
22 /**
23 * Register module.
24 */
25 public function load()
26 {
27 add_action('init', [AmeliaStepBookingButtonModule::class, 'registerModule']);
28 }
29
30 public static function registerModule()
31 {
32 $module_json_folder_path = dirname(__DIR__, 1) . '/visual-builder/src/modules/StepBookingButton';
33
34 ModuleRegistration::register_module(
35 $module_json_folder_path,
36 [
37 'render_callback' => [AmeliaStepBookingButtonModule::class, 'renderCallback'],
38 ]
39 );
40 }
41
42 /**
43 * Generate classnames for the module.
44 */
45 public static function module_classnames(array $args): void
46 {
47 $classnames_instance = $args['classnamesInstance'];
48 $attrs = $args['attrs'];
49
50 $classnames_instance->add(
51 ElementClassnames::classnames([
52 'attrs' => $attrs['module']['decoration'] ?? [],
53 ])
54 );
55 }
56
57 /**
58 * Module script data.
59 */
60 public static function module_script_data(array $args): void
61 {
62 $elements = $args['elements'];
63
64 $elements->script_data([
65 'attrName' => 'module',
66 ]);
67 }
68
69 /**
70 * Module styles.
71 */
72 public static function module_styles(array $args): void
73 {
74 $attrs = $args['attrs'] ?? [];
75 $elements = $args['elements'];
76 $settings = $args['settings'] ?? [];
77
78 Style::add([
79 'id' => $args['id'],
80 'name' => $args['name'],
81 'orderIndex' => $args['orderIndex'],
82 'storeInstance' => $args['storeInstance'],
83 'styles' => [
84 // Module styles.
85 $elements->style([
86 'attrName' => 'module',
87 'styleProps' => [
88 'disabledOn' => [
89 'disabledModuleVisibility' => $settings['disabledModuleVisibility'] ?? null,
90 ],
91 ],
92 ]),
93 // Button styles.
94 $elements->style([
95 'attrName' => 'button',
96 ]),
97 ],
98 ]);
99 }
100
101 /**
102 * Normalize toggle values coming from Divi attrs.
103 */
104 private static function isToggleEnabled($value): bool
105 {
106 if (true === $value || 1 === $value || '1' === $value || 'on' === $value || 'true' === $value) {
107 return true;
108 }
109
110 if (is_array($value)) {
111 if (isset($value['desktop']['value'])) {
112 return self::isToggleEnabled($value['desktop']['value']);
113 }
114
115 if (isset($value['value'])) {
116 return self::isToggleEnabled($value['value']);
117 }
118 }
119
120 return false;
121 }
122
123 /**
124 * Render module HTML output.
125 */
126 public static function renderCallback(array $attrs, string $content, WP_Block $block, ModuleElements $elements): string
127 {
128 $auto_trigger = wp_unique_id('amelia-step-booking-btn-');
129
130 $shortcode = '[' . ShortcodeAliasService::activeShortcodeTag('stepbooking', 'ameliastepbooking');
131 $shortcode .= ' trigger=' . sanitize_html_class($auto_trigger);
132 $shortcode .= ' trigger_type=id';
133 $shortcode .= ' in_dialog=1';
134
135 $layout = $attrs['layout']['innerContent']['desktop']['value'] ?? '1';
136 if ($layout !== null && $layout !== '') {
137 $shortcode .= ' layout=' . absint($layout);
138 }
139
140 $to_csv_ids = static function ($value): string {
141 $vals = is_array($value) ? $value : [$value];
142 $vals = array_filter(array_map('absint', $vals));
143
144 return implode(',', $vals);
145 };
146
147 $preselect = $attrs['parameters']['innerContent']['desktop']['value']
148 ?? $attrs['parameters']['innerContent']['value']
149 ?? $attrs['parameters']['innerContent']
150 ?? false;
151
152 if (self::isToggleEnabled($preselect)) {
153 $show = $attrs['type']['innerContent']['desktop']['value'] ?? '';
154 if ($show !== '' && $show !== '0') {
155 $shortcode .= ' show=' . sanitize_key((string) $show);
156 }
157
158 $category = $attrs['categories']['innerContent']['desktop']['value'] ?? [];
159 $service = $attrs['services']['innerContent']['desktop']['value'] ?? [];
160 $employee = $attrs['employees']['innerContent']['desktop']['value'] ?? [];
161 $location = $attrs['locations']['innerContent']['desktop']['value'] ?? [];
162 $package = $attrs['packages']['innerContent']['desktop']['value'] ?? [];
163
164 $service_csv = $to_csv_ids($service);
165 $category_csv = $to_csv_ids($category);
166 $employee_csv = $to_csv_ids($employee);
167 $location_csv = $to_csv_ids($location);
168 $package_csv = $to_csv_ids($package);
169
170 if ($service_csv !== '') {
171 $shortcode .= ' service=' . $service_csv;
172 } elseif ($category_csv !== '') {
173 $shortcode .= ' category=' . $category_csv;
174 }
175
176 if ($employee_csv !== '') {
177 $shortcode .= ' employee=' . $employee_csv;
178 }
179
180 if ($location_csv !== '') {
181 $shortcode .= ' location=' . $location_csv;
182 }
183
184 if ($package_csv !== '') {
185 $shortcode .= ' package=' . $package_csv;
186 }
187 }
188
189 $shortcode .= ']';
190
191 $button_html = self::renderTriggerButtonHtml(
192 $attrs,
193 $block,
194 $elements,
195 $auto_trigger,
196 self::BUTTON_BASE_CLASS,
197 __('Book Appointment', 'wpamelia')
198 );
199
200
201 return self::renderBookingButtonModuleShell(
202 $attrs,
203 $block,
204 $elements,
205 $button_html,
206 'amelia-step-booking-button_wrapper',
207 esc_html($shortcode)
208 );
209 }
210 }
211