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 / src / Infrastructure / WP / Elementor / AmeliaCatalogBookingElementorWidget.php
ameliabooking / src / Infrastructure / WP / Elementor Last commit date
AmeliaBookingElementorWidget.php 6 months ago AmeliaCatalogBookingElementorWidget.php 3 weeks ago AmeliaCatalogElementorWidget.php 6 months ago AmeliaEventsCalendarBookingElementorWidget.php 3 weeks ago AmeliaEventsElementorWidget.php 3 weeks ago AmeliaEventsListBookingButtonElementorWidget.php 3 weeks ago AmeliaEventsListBookingElementorWidget.php 3 weeks ago AmeliaStepBookingButtonElementorWidget.php 1 month ago AmeliaStepBookingElementorWidget.php 3 weeks ago ElementorBlock.php 3 weeks ago ElementorSharedShortcodeWidget.php 3 weeks ago
AmeliaCatalogBookingElementorWidget.php
289 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 BackendStrings::get('catalog_booking_gutenberg_block')['title'];
30 }
31
32 public function get_icon()
33 {
34 return 'amelia-logo';
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 . BackendStrings::get('catalog_booking_gutenberg_block')['title']
52 . '</p><br><p class="amelia-elementor-content-p">'
53 . 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()
190 {
191 $settings = $this->get_settings_for_display();
192
193 if ($settings['select_catalog'] === 'show_package') {
194 $this->remove_control('select_show');
195 }
196
197 $skip_categories = $settings['skip_categories'] === 'yes' ? ' categories_hidden=1' : '';
198
199 $show = '';
200
201 if ($settings['select_catalog'] === 'show_catalog') {
202 $category_service = '';
203
204 $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show'];
205 } elseif ($settings['select_catalog'] === 'show_category' && !empty($settings['select_category'])) {
206 $category_service = ' category=' . (is_array($settings['select_category']) ?
207 implode(',', $settings['select_category']) : $settings['select_category']);
208
209 $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show'];
210 } elseif ($settings['select_catalog'] === 'show_service' && !empty($settings['select_service'])) {
211 $category_service = ' service=' . (is_array($settings['select_service']) ?
212 implode(',', $settings['select_service']) : $settings['select_service']);
213
214 $show = empty($settings['select_show']) || $settings['select_show'] === 'packages' ? '' : ' show=' . $settings['select_show'];
215 } elseif ($settings['select_catalog'] === 'show_package' && !empty($settings['select_package'])) {
216 $category_service = ' package=' . (is_array($settings['select_package']) ?
217 implode(',', $settings['select_package']) : $settings['select_package']);
218 } else {
219 $category_service = '';
220 }
221
222 if ($settings['preselect']) {
223 $employee = empty($settings['select_employee']) ? '' : ' employee=' . (is_array($settings['select_employee']) ?
224 implode(',', $settings['select_employee']) : $settings['select_employee']);
225 $location = empty($settings['select_location']) ? '' : ' location=' . (is_array($settings['select_location']) ?
226 implode(',', $settings['select_location']) : $settings['select_location']);
227 } else {
228 $employee = '';
229 $location = '';
230 }
231
232 $sharedSortcode = $this->getSharedShortcodeString($settings);
233
234 echo '[ameliacatalogbooking' .
235 $show .
236 $sharedSortcode .
237 $category_service .
238 $employee .
239 $location .
240 $skip_categories . ']';
241 }
242
243 public static function amelia_elementor_get_data()
244 {
245 $data = GutenbergBlock::getEntitiesData()['data'];
246 $elementorData = [];
247
248 $elementorData['categories'] = [];
249
250 foreach ($data['categories'] as $category) {
251 $elementorData['categories'][$category['id']] = $category['name'] . ' (id: ' . $category['id'] . ')';
252 }
253
254 $elementorData['services'] = [];
255
256 foreach ($data['servicesList'] as $service) {
257 if ($service) {
258 $elementorData['services'][$service['id']] = $service['name'] . ' (id: ' . $service['id'] . ')';
259 }
260 }
261
262 $elementorData['packages'] = [];
263
264 foreach ($data['packages'] as $package) {
265 $elementorData['packages'][$package['id']] = $package['name'] . ' (id: ' . $package['id'] . ')';
266 }
267
268 $elementorData['employees'] = [];
269 foreach ($data['employees'] as $provider) {
270 $elementorData['employees'][$provider['id']] = $provider['firstName'] . $provider['lastName'] . ' (id: ' . $provider['id'] . ')';
271 }
272
273 $elementorData['locations'] = [];
274 foreach ($data['locations'] as $location) {
275 $elementorData['locations'][$location['id']] = $location['name'] . ' (id: ' . $location['id'] . ')';
276 }
277
278 $elementorData['show'] = $data['packages'] ? [
279 '' => BackendStrings::get('show_all'),
280 'services' => BackendStrings::get('services'),
281 'packages' => BackendStrings::get('packages')
282 ] : [];
283
284 self::setSharedShortcodeData($data, $elementorData);
285
286 return $elementorData;
287 }
288 }
289