PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / AmeliaCatalogElementorWidget.php
ameliabooking / src / Infrastructure / WP / Elementor Last commit date
AmeliaBookingElementorWidget.php 2 years ago AmeliaCatalogBookingElementorWidget.php 1 year ago AmeliaCatalogElementorWidget.php 2 years ago AmeliaEventsCalendarBookingElementorWidget.php 1 year ago AmeliaEventsElementorWidget.php 2 years ago AmeliaEventsListBookingElementorWidget.php 2 years ago AmeliaStepBookingElementorWidget.php 2 years ago ElementorBlock.php 2 years ago
AmeliaCatalogElementorWidget.php
262 lines
1 <?php
2 /**
3 * @copyright © TMS-Plugins. All rights reserved.
4 * @licence See LICENCE.md for license details.
5 */
6
7 namespace Elementor;
8
9 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\GutenbergBlock;
10 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
11
12 /**
13 * Class AmeliaCatalogElementorWidget
14 *
15 * @package AmeliaBooking\Infrastructure\WP\Elementor
16 */
17 class AmeliaCatalogElementorWidget extends Widget_Base
18 {
19 protected $controls_data;
20
21 public function get_name() {
22 return 'ameliacatalog';
23 }
24
25 public function get_title() {
26 return BackendStrings::getWordPressStrings()['catalog_gutenberg_block']['title'];
27 }
28
29 public function get_icon() {
30 return 'amelia-logo-outdated';
31 }
32
33 public function get_categories() {
34 return [ 'amelia-elementor' ];
35 }
36 protected function register_controls() {
37
38 $controls_data = self::amelia_elementor_get_data();
39
40 $this->start_controls_section(
41 'amelia_catalog_section',
42 [
43 'label' => '<div class="amelia-elementor-content-outdated"><p class="amelia-elementor-content-title">'
44 . BackendStrings::getWordPressStrings()['catalog_gutenberg_block']['title']
45 . '</p><br><p class="amelia-elementor-content-p">'
46 . BackendStrings::getWordPressStrings()['catalog_gutenberg_block']['description']
47 . '</p><br><p class="amelia-elementor-content-p amelia-elementor-content-p-outdated">'
48 . BackendStrings::getWordPressStrings()['outdated_booking_gutenberg_block']
49 . '</p>',
50 ]
51 );
52
53 $options = [
54 'show_catalog' => BackendStrings::getWordPressStrings()['show_catalog'],
55 'show_category' => BackendStrings::getWordPressStrings()['show_category'],
56 'show_service' => BackendStrings::getWordPressStrings()['show_service'],
57 ];
58
59 if ($controls_data['packages']) {
60 $options['show_package'] = BackendStrings::getWordPressStrings()['show_package'];
61 }
62
63 $this->add_control(
64 'select_catalog',
65 [
66 'label' => BackendStrings::getWordPressStrings()['select_catalog_view'],
67 'type' => Controls_Manager::SELECT,
68 'label_block' => true,
69 'options' => $options,
70 'default' => 'show_catalog',
71 ]
72 );
73
74
75 $this->add_control(
76 'select_category',
77 [
78 'label' => BackendStrings::getWordPressStrings()['select_category'],
79 'type' => Controls_Manager::SELECT,
80 'options' => $controls_data['categories'],
81 'condition' => ['select_catalog' => 'show_category'],
82 'default' => array_keys($controls_data['categories']) ? array_keys($controls_data['categories'])[0] : 0,
83 ]
84 );
85
86 $this->add_control(
87 'select_service',
88 [
89 'label' => BackendStrings::getWordPressStrings()['select_service'],
90 'type' => Controls_Manager::SELECT,
91 'options' => $controls_data['services'],
92 'condition' => ['select_catalog' => 'show_service'],
93 'default' => array_keys($controls_data['services']) ? array_keys($controls_data['services'])[0] : 0,
94 ]
95 );
96
97 if ($controls_data['packages']) {
98 $this->add_control(
99 'select_package',
100 [
101 'label' => BackendStrings::getWordPressStrings()['select_package'],
102 'type' => Controls_Manager::SELECT,
103 'options' => $controls_data['packages'],
104 'condition' => ['select_catalog' => 'show_package'],
105 'default' => array_keys($controls_data['packages']) ? array_keys($controls_data['packages'])[0] : 0,
106 ]
107 );
108 }
109
110
111 $this->add_control(
112 'preselect',
113 [
114 'label' => BackendStrings::getWordPressStrings()['filter'],
115 'type' => Controls_Manager::SWITCHER,
116 'default' => false,
117 'label_on' => BackendStrings::getCommonStrings()['yes'],
118 'label_off' => BackendStrings::getCommonStrings()['no'],
119 ]
120 );
121
122 $this->add_control(
123 'select_employee',
124 [
125 'label' => BackendStrings::getWordPressStrings()['select_employee'],
126 'type' => Controls_Manager::SELECT,
127 'options' => $controls_data['employees'],
128 'condition' => ['preselect' => 'yes'],
129 'default' => '0',
130 ]
131 );
132
133 $this->add_control(
134 'select_location',
135 [
136 'label' => BackendStrings::getWordPressStrings()['select_location'],
137 'type' => Controls_Manager::SELECT,
138 'options' => $controls_data['locations'],
139 'condition' => ['preselect' => 'yes'],
140 'default' => '0',
141 ]
142 );
143
144 $this->add_control(
145 'load_manually',
146 [
147 'label' => BackendStrings::getWordPressStrings()['manually_loading'],
148 'label_block' => true,
149 'type' => Controls_Manager::TEXT,
150 'condition' => ['preselect' => 'yes'],
151 'placeholder' => '',
152 'description' => BackendStrings::getWordPressStrings()['manually_loading_description'],
153 ]
154 );
155
156 if ($controls_data['show']) {
157 $this->add_control(
158 'select_show',
159 [
160 'label' => BackendStrings::getWordPressStrings()['show_all'],
161 'type' => Controls_Manager::SELECT,
162 'options' => $controls_data['show'],
163 'condition' => ['preselect' => 'yes'],
164 'default' => '',
165 ]
166 );
167 }
168
169 $this->end_controls_section();
170 }
171
172 protected function render() {
173 $settings = $this->get_settings_for_display();
174
175 if ($settings['select_catalog'] === 'show_service' || $settings['select_catalog'] === 'show_package') {
176 $this->remove_control('select_show');
177 }
178
179 $trigger = $settings['load_manually'] !== '' ? ' trigger=' . $settings['load_manually'] : '';
180
181 $show = '';
182
183 if ($settings['select_catalog'] === 'show_catalog') {
184 $category_service = '';
185
186 $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show'];
187 }
188 elseif ($settings['select_catalog'] === 'show_category') {
189 $category_service = ' category=' . $settings['select_category'];
190
191 $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show'];
192 }
193 elseif ($settings['select_catalog'] === 'show_service') {
194 $category_service = ' service=' . $settings['select_service'];
195 }
196 elseif ($settings['select_catalog'] === 'show_package') {
197 $category_service = ' package=' . $settings['select_package'];
198 } else {
199 $category_service = '';
200 }
201
202 if ($settings['preselect']) {
203 $employee = $settings['select_employee'] === '0' ? '' : ' employee=' . $settings['select_employee'];
204 $location = $settings['select_location'] === '0' ? '' : ' location=' . $settings['select_location'];
205 }
206 else {
207 $employee = '';
208 $location = '';
209 $trigger = '';
210 }
211 echo esc_html('[ameliacatalog' . $show . $trigger . $category_service . $employee . $location . ']');
212 }
213
214
215 public static function amelia_elementor_get_data() {
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['packages'] = [];
234
235 foreach ($data['packages'] as $package) {
236 $elementorData['packages'][$package['id']] = $package['name'] . ' (id: ' . $package['id'] . ')';
237 }
238
239 $elementorData['employees'] = [];
240 $elementorData['employees'][0] = BackendStrings::getWordPressStrings()['show_all_employees'];
241
242 foreach ($data['employees'] as $provider) {
243 $elementorData['employees'][$provider['id']] = $provider['firstName'] . $provider['lastName'] . ' (id: ' . $provider['id'] . ')';
244 }
245
246 $elementorData['locations'] = [];
247 $elementorData['locations'][0] = BackendStrings::getWordPressStrings()['show_all_locations'];
248
249 foreach ($data['locations'] as $location) {
250 $elementorData['locations'][$location['id']] = $location['name'] . ' (id: ' . $location['id'] . ')';
251 }
252
253 $elementorData['show'] = $data['packages'] ? [
254 '' => BackendStrings::getWordPressStrings()['show_all'],
255 'services' => BackendStrings::getCommonStrings()['services'],
256 'packages' => BackendStrings::getCommonStrings()['packages']
257 ] : [];
258
259 return $elementorData;
260 }
261 }
262