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