PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.9 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 / src / Infrastructure / WP / Elementor / AmeliaCatalogBookingElementorWidget.php
ameliabooking / src / Infrastructure / WP / Elementor Last commit date
AmeliaBookingElementorWidget.php 1 week ago AmeliaCatalogBookingElementorWidget.php 1 week ago AmeliaCatalogElementorWidget.php 1 week ago AmeliaElementorWhiteLabelHelper.php 1 week ago AmeliaEventsCalendarBookingElementorWidget.php 1 week ago AmeliaEventsElementorWidget.php 1 week ago AmeliaEventsListBookingButtonElementorWidget.php 1 week ago AmeliaEventsListBookingElementorWidget.php 1 week ago AmeliaStepBookingButtonElementorWidget.php 1 week ago AmeliaStepBookingElementorWidget.php 1 week ago ElementorBlock.php 1 week ago ElementorSharedShortcodeWidget.php 2 months ago
AmeliaCatalogBookingElementorWidget.php
302 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace Elementor;
9
10 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\GutenbergBlock;
11 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
12
13 /**
14 * Class AmeliaCatalogBookingElementorWidget
15 *
16 * @package AmeliaBooking\Infrastructure\WP\Elementor
17 */
18 class AmeliaCatalogBookingElementorWidget extends ElementorSharedShortcodeWidget
19 {
20 protected $controls_data;
21
22 public function get_name()
23 {
24 return 'catalogbooking';
25 }
26
27 public function get_title()
28 {
29 return AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('catalog_booking_gutenberg_block')['title']);
30 }
31
32 public function get_icon()
33 {
34 return AmeliaElementorWhiteLabelHelper::icon();
35 }
36
37 public function get_categories()
38 {
39 return [ 'amelia-elementor' ];
40 }
41
42 protected function register_controls()
43 {
44
45 $controls_data = self::amelia_elementor_get_data();
46
47 $this->start_controls_section(
48 'amelia_catalog_section',
49 [
50 'label' => '<div class="amelia-elementor-content"><p class="amelia-elementor-content-title">'
51 . AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('catalog_booking_gutenberg_block')['title'])
52 . '</p><br><p class="amelia-elementor-content-p">'
53 . AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('catalog_booking_gutenberg_block')['description'])
54 . '</p>',
55 ]
56 );
57
58 $options = [
59 'show_catalog' => BackendStrings::get('show_catalog'),
60 'show_category' => BackendStrings::get('show_categories'),
61 'show_service' => BackendStrings::get('show_services'),
62 ];
63
64 if ($controls_data['packages']) {
65 $options['show_package'] = BackendStrings::get('show_packages');
66 }
67
68 if ($controls_data['categories'] && sizeof($controls_data['locations']) > 1) {
69 }
70
71 $this->add_control(
72 'select_catalog',
73 [
74 'label' => BackendStrings::get('select_catalog_view'),
75 'type' => Controls_Manager::SELECT,
76 'label_block' => true,
77 'options' => $options,
78 'default' => 'show_catalog',
79 ]
80 );
81
82 $this->add_control(
83 'select_category',
84 [
85 'label' => BackendStrings::get('select_category'),
86 'type' => Controls_Manager::SELECT2,
87 'multiple' => true,
88 'options' => $controls_data['categories'],
89 'condition' => ['select_catalog' => 'show_category'],
90 'default' => array_keys($controls_data['categories']) ? [array_keys($controls_data['categories'])[0]] : 0,
91 ]
92 );
93
94 if ($controls_data['services'] && sizeof($controls_data['services']) > 1) {
95 $this->add_control(
96 'select_service',
97 [
98 'label' => BackendStrings::get('select_service'),
99 'type' => Controls_Manager::SELECT2,
100 'multiple' => true,
101 'options' => $controls_data['services'],
102 'condition' => ['select_catalog' => 'show_service'],
103 'default' => array_keys($controls_data['services']) ? [array_keys($controls_data['services'])[0]] : 0,
104 ]
105 );
106 }
107
108 if ($controls_data['packages']) {
109 $this->add_control(
110 'select_package',
111 [
112 'label' => BackendStrings::get('select_package'),
113 'type' => Controls_Manager::SELECT2,
114 'multiple' => true,
115 'options' => $controls_data['packages'],
116 'condition' => ['select_catalog' => 'show_package'],
117 'default' => array_keys($controls_data['packages']) ? [array_keys($controls_data['packages'])[0]] : 0,
118 ]
119 );
120 }
121
122 $this->add_control(
123 'preselect',
124 [
125 'label' => BackendStrings::get('filter'),
126 'type' => Controls_Manager::SWITCHER,
127 'default' => false,
128 'label_on' => BackendStrings::get('yes'),
129 'label_off' => BackendStrings::get('no'),
130 ]
131 );
132
133 $this->add_control(
134 'skip_categories',
135 [
136 'label' => BackendStrings::get('skip_categories'),
137 'type' => Controls_Manager::SWITCHER,
138 'default' => false,
139 'label_on' => BackendStrings::get('yes'),
140 'label_off' => BackendStrings::get('no'),
141 'condition' => ['preselect' => 'yes'],
142 ]
143 );
144
145 if ($controls_data['employees'] && sizeof($controls_data['employees']) > 1) {
146 $this->add_control(
147 'select_employee',
148 [
149 'label' => BackendStrings::get('select_employee'),
150 'type' => Controls_Manager::SELECT2,
151 'multiple' => true,
152 'options' => $controls_data['employees'],
153 'condition' => ['preselect' => 'yes'],
154 ]
155 );
156 }
157
158 if ($controls_data['locations'] && sizeof($controls_data['locations']) > 1) {
159 $this->add_control(
160 'select_location',
161 [
162 'label' => BackendStrings::get('select_location'),
163 'type' => Controls_Manager::SELECT2,
164 'multiple' => true,
165 'options' => $controls_data['locations'],
166 'condition' => ['preselect' => 'yes'],
167 ]
168 );
169 }
170
171 if ($controls_data['show']) {
172 $this->add_control(
173 'select_show',
174 [
175 'label' => BackendStrings::get('show_all'),
176 'type' => Controls_Manager::SELECT,
177 'options' => $controls_data['show'],
178 'condition' => ['preselect' => 'yes'],
179 'default' => '',
180 ]
181 );
182 }
183
184 $this->setSharedShortcodeElements($controls_data);
185
186 $this->end_controls_section();
187 }
188
189 protected function render(): void
190 {
191 if (Plugin::$instance->editor->is_edit_mode()) {
192 $alt = esc_attr(BackendStrings::get('catalog_booking_gutenberg_block')['title']);
193 printf(
194 '<picture>' .
195 '<source media="(max-width: 360px)" srcset="%s" />' .
196 '<img class="amelia-elementor-preview" src="%s" alt="%s" style="max-width:100%%;height:auto;display:block;margin:0 auto;" />' .
197 '</picture>',
198 esc_url(AMELIA_URL . 'public/img/shortcode/cbf-mobile-preview.svg'),
199 esc_url(AMELIA_URL . 'public/img/shortcode/cbf-preview.svg'),
200 $alt
201 );
202 return;
203 }
204
205 $settings = $this->get_settings_for_display();
206
207 if ($settings['select_catalog'] === 'show_package') {
208 $this->remove_control('select_show');
209 }
210
211 $skip_categories = $settings['skip_categories'] === 'yes' ? ' categories_hidden=1' : '';
212
213 $show = '';
214
215 if ($settings['select_catalog'] === 'show_catalog') {
216 $category_service = '';
217
218 $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show'];
219 } elseif ($settings['select_catalog'] === 'show_category' && !empty($settings['select_category'])) {
220 $category_service = ' category=' . (is_array($settings['select_category']) ?
221 implode(',', $settings['select_category']) : $settings['select_category']);
222
223 $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show'];
224 } elseif ($settings['select_catalog'] === 'show_service' && !empty($settings['select_service'])) {
225 $category_service = ' service=' . (is_array($settings['select_service']) ?
226 implode(',', $settings['select_service']) : $settings['select_service']);
227
228 $show = empty($settings['select_show']) || $settings['select_show'] === 'packages' ? '' : ' show=' . $settings['select_show'];
229 } elseif ($settings['select_catalog'] === 'show_package' && !empty($settings['select_package'])) {
230 $category_service = ' package=' . (is_array($settings['select_package']) ?
231 implode(',', $settings['select_package']) : $settings['select_package']);
232 } else {
233 $category_service = '';
234 }
235
236 if ($settings['preselect']) {
237 $employee = empty($settings['select_employee']) ? '' : ' employee=' . (is_array($settings['select_employee']) ?
238 implode(',', $settings['select_employee']) : $settings['select_employee']);
239 $location = empty($settings['select_location']) ? '' : ' location=' . (is_array($settings['select_location']) ?
240 implode(',', $settings['select_location']) : $settings['select_location']);
241 } else {
242 $employee = '';
243 $location = '';
244 }
245 $sharedSortcode = $this->getSharedShortcodeString($settings);
246
247 echo do_shortcode('[' . AmeliaElementorWhiteLabelHelper::shortcodeTag('catalogbooking', 'ameliacatalogbooking') .
248 $show .
249 $sharedSortcode .
250 $category_service .
251 $employee .
252 $location .
253 $skip_categories . ']');
254 }
255
256 public static function amelia_elementor_get_data()
257 {
258 $data = GutenbergBlock::getEntitiesData()['data'];
259 $elementorData = [];
260
261 $elementorData['categories'] = [];
262
263 foreach ($data['categories'] as $category) {
264 $elementorData['categories'][$category['id']] = $category['name'] . ' (id: ' . $category['id'] . ')';
265 }
266
267 $elementorData['services'] = [];
268
269 foreach ($data['servicesList'] as $service) {
270 if ($service) {
271 $elementorData['services'][$service['id']] = $service['name'] . ' (id: ' . $service['id'] . ')';
272 }
273 }
274
275 $elementorData['packages'] = [];
276
277 foreach ($data['packages'] as $package) {
278 $elementorData['packages'][$package['id']] = $package['name'] . ' (id: ' . $package['id'] . ')';
279 }
280
281 $elementorData['employees'] = [];
282 foreach ($data['employees'] as $provider) {
283 $elementorData['employees'][$provider['id']] = $provider['firstName'] . $provider['lastName'] . ' (id: ' . $provider['id'] . ')';
284 }
285
286 $elementorData['locations'] = [];
287 foreach ($data['locations'] as $location) {
288 $elementorData['locations'][$location['id']] = $location['name'] . ' (id: ' . $location['id'] . ')';
289 }
290
291 $elementorData['show'] = $data['packages'] ? [
292 '' => BackendStrings::get('show_all'),
293 'services' => BackendStrings::get('services'),
294 'packages' => BackendStrings::get('packages')
295 ] : [];
296
297 self::setSharedShortcodeData($data, $elementorData);
298
299 return $elementorData;
300 }
301 }
302