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 / AmeliaStepBookingElementorWidget.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
AmeliaStepBookingElementorWidget.php
268 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 AmeliaStepBookingElementorWidget
15 *
16 * @package AmeliaBooking\Infrastructure\WP\Elementor
17 */
18 class AmeliaStepBookingElementorWidget extends ElementorSharedShortcodeWidget
19 {
20 protected $controls_data;
21
22 public function get_name()
23 {
24 return 'stepbooking';
25 }
26
27 public function get_title()
28 {
29 return AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('step_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_booking_section',
49 [
50 'label' => '<div class="amelia-elementor-content"><p class="amelia-elementor-content-title">'
51 . AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('step_booking_gutenberg_block')['title'])
52 . '</p><br><p class="amelia-elementor-content-p">'
53 . AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('step_booking_gutenberg_block')['description'])
54 . '</p>',
55 ]
56 );
57
58 $this->add_control(
59 'preselect',
60 [
61 'label' => BackendStrings::get('filter'),
62 'type' => Controls_Manager::SWITCHER,
63 'default' => false,
64 'label_on' => BackendStrings::get('yes'),
65 'label_off' => BackendStrings::get('no'),
66 ]
67 );
68
69 if ($controls_data['categories'] && sizeof($controls_data['categories']) > 1) {
70 $this->add_control(
71 'select_category',
72 [
73 'label' => BackendStrings::get('select_category'),
74 'type' => Controls_Manager::SELECT2,
75 'multiple' => true,
76 'options' => $controls_data['categories'],
77 'condition' => ['preselect' => 'yes'],
78 'placeholder' => BackendStrings::get('show_all_categories')
79 ]
80 );
81 }
82
83 if ($controls_data['services'] && sizeof($controls_data['services']) > 1) {
84 $this->add_control(
85 'select_service',
86 [
87 'label' => BackendStrings::get('select_service'),
88 'type' => Controls_Manager::SELECT2,
89 'multiple' => true,
90 'options' => $controls_data['services'],
91 'condition' => ['preselect' => 'yes'],
92 'placeholder' => BackendStrings::get('show_all_services'),
93 ]
94 );
95 }
96
97 if ($controls_data['employees'] && sizeof($controls_data['employees']) > 1) {
98 $this->add_control(
99 'select_employee',
100 [
101 'label' => BackendStrings::get('select_employee'),
102 'type' => Controls_Manager::SELECT2,
103 'multiple' => true,
104 'options' => $controls_data['employees'],
105 'condition' => ['preselect' => 'yes'],
106 'placeholder' => BackendStrings::get('show_all_employees'),
107 ]
108 );
109 }
110
111 if ($controls_data['locations'] && sizeof($controls_data['locations']) > 1) {
112 $this->add_control(
113 'select_location',
114 [
115 'label' => BackendStrings::get('select_location'),
116 'type' => Controls_Manager::SELECT2,
117 'multiple' => true,
118 'options' => $controls_data['locations'],
119 'condition' => ['preselect' => 'yes'],
120 'placeholder' => BackendStrings::get('show_all_locations'),
121 ]
122 );
123 }
124
125 if ($controls_data['show']) {
126 $this->add_control(
127 'select_package',
128 [
129 'label' => BackendStrings::get('select_package'),
130 'type' => Controls_Manager::SELECT2,
131 'multiple' => true,
132 'options' => $controls_data['packages'],
133 'condition' => ['preselect' => 'yes'],
134 'placeholder' => BackendStrings::get('show_all_packages'),
135 ]
136 );
137 }
138
139 if ($controls_data['show']) {
140 $this->add_control(
141 'select_show',
142 [
143 'label' => BackendStrings::get('show_all'),
144 'type' => Controls_Manager::SELECT,
145 'options' => $controls_data['show'],
146 'condition' => ['preselect' => 'yes'],
147 'default' => '',
148 ]
149 );
150 }
151
152 $this->add_control(
153 'layout',
154 [
155 'label' => BackendStrings::get('layout_select_label'),
156 'type' => Controls_Manager::SELECT,
157 'description' => BackendStrings::get('layout_description'),
158 'options' => $controls_data['layout_options'],
159 'default' => '1',
160 ]
161 );
162
163 $this->setSharedShortcodeElements($controls_data);
164
165 $this->end_controls_section();
166 }
167 protected function render(): void
168 {
169 if (Plugin::$instance->editor->is_edit_mode()) {
170 $alt = esc_attr(BackendStrings::get('step_booking_gutenberg_block')['title']);
171 printf(
172 '<picture>' .
173 '<source media="(max-width: 360px)" srcset="%s" />' .
174 '<img class="amelia-elementor-preview" src="%s" alt="%s" style="max-width:100%%;height:auto;display:block;margin:0 auto;" />' .
175 '</picture>',
176 esc_url(AMELIA_URL . 'public/img/shortcode/sbs-mobile-preview.svg'),
177 esc_url(AMELIA_URL . 'public/img/shortcode/sbs-preview.svg'),
178 $alt
179 );
180 return;
181 }
182
183 $settings = $this->get_settings_for_display();
184
185 $category = empty($settings['select_category']) ? '' : ' category=' . (is_array($settings['select_category']) ?
186 implode(',', $settings['select_category']) : $settings['select_category']);
187 $service = empty($settings['select_service']) ? '' : ' service=' . (is_array($settings['select_service']) ?
188 implode(',', $settings['select_service']) : $settings['select_service']);
189
190 $category_service = empty($settings['select_service']) ? $category : $service;
191
192 $employee = empty($settings['select_employee']) ? '' : ' employee=' . (is_array($settings['select_employee']) ?
193 implode(',', $settings['select_employee']) : $settings['select_employee']);
194 $location = empty($settings['select_location']) ? '' : ' location=' . (is_array($settings['select_location']) ?
195 implode(',', $settings['select_location']) : $settings['select_location']);
196 $package = empty($settings['select_package']) ? '' : ' package=' . (is_array($settings['select_package']) ?
197 implode(',', $settings['select_package']) : $settings['select_package']);
198
199 $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show'];
200
201 $layout = $settings['layout'] && $settings['layout'] !== '' ? ' layout=' . $settings['layout'] : '';
202
203 $sharedSortcode = $this->getSharedShortcodeString($settings);
204
205 $shortcode = '[' . AmeliaElementorWhiteLabelHelper::shortcodeTag('stepbooking', 'ameliastepbooking') . $layout . $sharedSortcode;
206 if ($settings['preselect']) {
207 echo $shortcode . $show . $category_service . $employee . $location . $package . ']';
208 } else {
209 echo $shortcode . ']';
210 }
211 }
212
213
214 public static function amelia_elementor_get_data()
215 {
216 $data = GutenbergBlock::getEntitiesData()['data'];
217 $elementorData = [];
218
219 $elementorData['categories'] = [];
220
221 foreach ($data['categories'] as $category) {
222 $elementorData['categories'][$category['id']] = $category['name'] . ' (id: ' . $category['id'] . ')';
223 }
224
225 $elementorData['services'] = [];
226
227 foreach ($data['servicesList'] as $service) {
228 if ($service) {
229 $elementorData['services'][$service['id']] = $service['name'] . ' (id: ' . $service['id'] . ')';
230 }
231 }
232
233 $elementorData['employees'] = [];
234
235 foreach ($data['employees'] as $provider) {
236 $elementorData['employees'][$provider['id']] = $provider['firstName'] . $provider['lastName'] . ' (id: ' . $provider['id'] . ')';
237 }
238
239 $elementorData['locations'] = [];
240
241 foreach ($data['locations'] as $location) {
242 $elementorData['locations'][$location['id']] = $location['name'] . ' (id: ' . $location['id'] . ')';
243 }
244
245 $elementorData['packages'] = [];
246
247 foreach ($data['packages'] as $package) {
248 $elementorData['packages'][$package['id']] = $package['name'] . ' (id: ' . $package['id'] . ')';
249 }
250
251
252 $elementorData['show'] = $data['packages'] ? [
253 '' => BackendStrings::get('show_all'),
254 'services' => BackendStrings::get('services'),
255 'packages' => BackendStrings::get('packages')
256 ] : [];
257
258 $elementorData['layout_options'] = [
259 '1' => BackendStrings::get('layout_dropdown'),
260 '2' => BackendStrings::get('layout_list')
261 ];
262
263 self::setSharedShortcodeData($data, $elementorData);
264
265 return $elementorData;
266 }
267 }
268