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