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