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_amelia / includes / modules / StepBooking / StepBooking.php
ameliabooking / extensions / divi_amelia / includes / modules / StepBooking Last commit date
StepBooking.php 2 days ago style.css 4 years ago
StepBooking.php
287 lines
1 <?php
2
3 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\GutenbergBlock;
4 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
5
6 class DIVI_StepBooking extends ET_Builder_Module
7 {
8 public $slug = 'divi_step_booking';
9 public $vb_support = 'on';
10
11 private $categories = array();
12 private $services = array();
13 private $employees = array();
14 private $locations = array();
15 private $packages = array();
16 private $showPackages = true;
17
18 public $type = array();
19 private $trigger_types = array();
20 private $layout_options = array();
21
22 protected $module_credits = array(
23 'module_uri' => '',
24 'author' => '',
25 'author_uri' => '',
26 );
27
28 public function init()
29 {
30 $this->name = esc_html__(DIVI_AmeliaWhiteLabelHelper::label(BackendStrings::get('step_booking_divi')), 'divi-divi_amelia');
31
32 $this->type['0'] = BackendStrings::get('show_all');
33 $this->type['services'] = BackendStrings::get('services');
34 $this->type['packages'] = BackendStrings::get('packages');
35
36 // Initialize layout options
37 $this->layout_options = [
38 '1' => BackendStrings::get('layout_dropdown'),
39 '2' => BackendStrings::get('layout_list')
40 ];
41
42 if (!is_admin()) {
43 return;
44 }
45
46 $this->trigger_types = [
47 'id' => BackendStrings::get('trigger_type_id'),
48 'class' => BackendStrings::get('trigger_type_class')
49 ];
50
51 $data = GutenbergBlock::getEntitiesData()['data'];
52 $this->showPackages = !empty($data['packages']);
53
54 // $this->categories['0'] = BackendStrings::get('show_all_categories');
55 foreach ($data['categories'] as $category) {
56 $this->categories[$category['id']] = $category['name'] . ' (id: ' . $category['id'] . ')';
57 }
58 foreach ($data['servicesList'] as $service) {
59 if ($service) {
60 $this->services[$service['id']] = $service['name'] . ' (id: ' . $service['id'] . ')';
61 }
62 }
63 foreach ($data['employees'] as $employee) {
64 $this->employees[$employee['id']] = $employee['firstName'] . ' ' . $employee['lastName'] . ' (id: ' . $employee['id'] . ')';
65 }
66 foreach ($data['locations'] as $location) {
67 $this->locations[$location['id']] = $location['name'] . ' (id: ' . $location['id'] . ')';
68 }
69 foreach ($data['packages'] as $package) {
70 $this->packages[$package['id']] = $package['name'] . ' (id: ' . $package['id'] . ')';
71 }
72 }
73
74 /**
75 * Advanced Fields Config
76 *
77 * @return array
78 */
79 public function get_advanced_fields_config()
80 {
81 return array(
82 'button' => false,
83 'link_options' => false
84 );
85 }
86
87 public function get_fields()
88 {
89 $array = array(
90 'booking_params' => array(
91 'label' => esc_html__(BackendStrings::get('filter'), 'divi-divi_amelia'),
92 'type' => 'yes_no_button',
93 'options' => array(
94 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
95 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
96 ),
97 'toggle_slug' => 'main_content',
98 'option_category' => 'basic_option',
99 )
100 );
101
102 $array['categories'] = array(
103 'label' => esc_html__(BackendStrings::get('select_category'), 'divi-divi_amelia'),
104 'type' => 'amelia_multi_select',
105 'showAllText' => BackendStrings::get('show_all_categories'),
106 'options' => $this->categories,
107 'toggle_slug' => 'main_content',
108 'option_category' => 'basic_option',
109 'show_if' => array(
110 'booking_params' => 'on',
111 ),
112 );
113
114 $array['services'] = array(
115 'label' => esc_html__(BackendStrings::get('select_service'), 'divi-divi_amelia'),
116 'type' => 'amelia_multi_select',
117 'toggle_slug' => 'main_content',
118 'showAllText' => BackendStrings::get('show_all_services'),
119 'options' => $this->services,
120 'option_category' => 'basic_option',
121 'show_if' => array(
122 'booking_params' => 'on',
123 ),
124 );
125
126 $array['employees'] = array(
127 'label' => esc_html__(BackendStrings::get('select_employee'), 'divi-divi_amelia'),
128 'type' => 'amelia_multi_select',
129 'options' => $this->employees,
130 'toggle_slug' => 'main_content',
131 'showAllText' => BackendStrings::get('show_all_employees'),
132 'option_category' => 'basic_option',
133 'show_if' => array(
134 'booking_params' => 'on',
135 ),
136 );
137
138 $array['locations'] = array(
139 'label' => esc_html__(BackendStrings::get('select_location'), 'divi-divi_amelia'),
140 'type' => 'amelia_multi_select',
141 'options' => $this->locations,
142 'showAllText' => BackendStrings::get('show_all_locations'),
143 'toggle_slug' => 'main_content',
144 'option_category' => 'basic_option',
145 'show_if' => array(
146 'booking_params' => 'on',
147 ),
148 );
149
150
151 if ($this->showPackages) {
152 $array['packages'] = array(
153 'label' => esc_html__(BackendStrings::get('select_package'), 'divi-divi_amelia'),
154 'type' => 'amelia_multi_select',
155 'options' => $this->packages,
156 'toggle_slug' => 'main_content',
157 'option_category' => 'basic_option',
158 'showAllText' => BackendStrings::get('show_all_packages'),
159 'show_if' => array(
160 'booking_params' => 'on',
161 ),
162 );
163
164 $array['type'] = array(
165 'label' => esc_html__(BackendStrings::get('show_all'), 'divi-divi_amelia'),
166 'type' => 'select',
167 'options' => $this->type,
168 'toggle_slug' => 'main_content',
169 'option_category' => 'basic_option',
170 'show_if' => array(
171 'booking_params' => 'on'
172 ));
173 }
174
175 $array['layout'] = array(
176 'label' => esc_html__(BackendStrings::get('layout_select_label'), 'divi-divi_amelia'),
177 'type' => 'select',
178 'options' => $this->layout_options,
179 'toggle_slug' => 'main_content',
180 'option_category' => 'basic_option',
181 'default' => '1',
182 );
183
184 $array['trigger'] = array(
185 'label' => esc_html__(BackendStrings::get('manually_loading'), 'divi-divi_amelia'),
186 'type' => 'text',
187 'toggle_slug' => 'main_content',
188 'option_category' => 'basic_option',
189 'description' => BackendStrings::get('manually_loading_description'),
190 );
191
192 $array['trigger_type'] = array(
193 'label' => esc_html__(BackendStrings::get('trigger_type'), 'divi-divi_amelia'),
194 'type' => 'select',
195 'options' => $this->trigger_types,
196 'toggle_slug' => 'main_content',
197 'option_category' => 'basic_option',
198 );
199
200 $array['in_dialog'] = array(
201 'label' => esc_html__(DIVI_AmeliaWhiteLabelHelper::label(BackendStrings::get('in_dialog')), 'divi-divi_amelia'),
202 'type' => 'yes_no_button',
203 'options' => array(
204 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
205 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
206 ),
207 'toggle_slug' => 'main_content',
208 'option_category' => 'basic_option',
209 );
210
211 return $array;
212 }
213
214 public function checkValues($val)
215 {
216 if ($val !== null) {
217 $val = explode(',', $val);
218 if (is_array($val)) {
219 $newVals = [];
220 foreach ($val as $parameter) {
221 if ($parameter) {
222 $newVals[] = !is_numeric($parameter) ? (strpos($parameter, 'id:') ? substr(explode('id: ', $parameter)[1], 0, -1) : $parameter) : $parameter;
223 }
224 }
225 return count($newVals) > 0 ? $newVals : [];
226 }
227 return [];
228 }
229 return [];
230 }
231
232 public function render($attrs, $content = null, $render_slug = null)
233 {
234 $preselect = $this->props['booking_params'];
235 $shortcode = '[' . DIVI_AmeliaWhiteLabelHelper::shortcodeTag('stepbooking', 'ameliastepbooking');
236 $showAll = isset($this->props['type']) ? $this->props['type'] : null;
237 $trigger = $this->props['trigger'];
238 $trigger_type = $this->props['trigger_type'];
239 $in_dialog = $this->props['in_dialog'];
240 $layout = isset($this->props['layout']) ? $this->props['layout'] : '1'; // Default to dropdown layout
241
242 if ($showAll !== null && $showAll !== '' && $showAll !== '0') {
243 $shortcode .= ' show=' . $showAll;
244 }
245 if ($trigger !== null && $trigger !== '') {
246 $shortcode .= ' trigger=' . $trigger;
247 }
248 if (!empty($trigger) && !empty($trigger_type)) {
249 $shortcode .= ' trigger_type=' . $trigger_type;
250 }
251 if (!empty($trigger) && $in_dialog === 'on') {
252 $shortcode .= ' in_dialog=1';
253 }
254
255 // Add layout parameter to the shortcode
256 $shortcode .= ' layout=' . $layout;
257
258 if ($preselect === 'on') {
259 $category = !empty($this->props['categories']) ? $this->checkValues($this->props['categories']) : null;
260 $service = !empty($this->props['services']) ? $this->checkValues($this->props['services']) : null;
261 $employee = !empty($this->props['employees']) ? $this->checkValues($this->props['employees']) : null;
262 $location = !empty($this->props['locations']) ? $this->checkValues($this->props['locations']) : null;
263 $package = !empty($this->props['packages']) ? $this->checkValues($this->props['packages']) : null;
264
265 if ($service && count($service) > 0) {
266 $shortcode .= ' service=' . implode(',', $service);
267 } elseif ($category && count($category) > 0) {
268 $shortcode .= ' category=' . implode(',', $category);
269 }
270 if ($employee && count($employee) > 0) {
271 $shortcode .= ' employee=' . implode(',', $employee);
272 }
273 if ($location && count($location) > 0) {
274 $shortcode .= ' location=' . implode(',', $location);
275 }
276 if ($package && count($package) > 0) {
277 $shortcode .= ' package=' . implode(',', $package);
278 }
279 }
280 $shortcode .= ']';
281
282 return do_shortcode($shortcode);
283 }
284 }
285
286 new DIVI_StepBooking();
287