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