PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
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 / extensions / divi_amelia / includes / modules / EventsList / EventsList.php
ameliabooking / extensions / divi_amelia / includes / modules / EventsList Last commit date
EventsList.php 2 days ago style.css 3 years ago
EventsList.php
265 lines
1 <?php
2
3 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\GutenbergBlock;
4 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
5
6 class DIVI_EventsList extends ET_Builder_Module
7 {
8 public $slug = 'divi_events_list_booking';
9 public $vb_support = 'on';
10
11 private $events = array();
12 private $tags = array();
13
14 private $locations = array();
15
16
17 protected $module_credits = array(
18 'module_uri' => '',
19 'author' => '',
20 'author_uri' => '',
21 );
22
23 public function init()
24 {
25 $this->name = esc_html__(DIVI_AmeliaWhiteLabelHelper::label(BackendStrings::get('events_list_booking_divi')), 'divi-divi_amelia');
26
27 if (!is_admin()) {
28 return;
29 }
30
31 $data = GutenbergBlock::getEntitiesData()['data'];
32
33
34 foreach ($data['events'] as $event) {
35 $this->events[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart'];
36 }
37
38 foreach ($data['tags'] as $tag) {
39 $this->tags[$tag['name']] = $tag['name'] . ' (id: ' . $tag['id'] . ')';
40 }
41
42 foreach ($data['locations'] as $location) {
43 $this->locations[$location['id']] = $location['name'];
44 }
45 }
46
47 /**
48 * Advanced Fields Config
49 *
50 * @return array
51 */
52 public function get_advanced_fields_config()
53 {
54 return array(
55 'button' => false,
56 'link_options' => false
57 );
58 }
59
60 public function get_fields()
61 {
62 return array(
63 'booking_params' => array(
64 'label' => esc_html__(BackendStrings::get('filter'), 'divi-divi_amelia'),
65 'type' => 'yes_no_button',
66 'options' => array(
67 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
68 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
69 ),
70 'toggle_slug' => 'main_content',
71 'option_category' => 'basic_option',
72 ),
73 'event_to_show' => array(
74 'label' => esc_html__(BackendStrings::get('event_time_scope'), 'divi-divi_amelia'),
75 'type' => 'select',
76 'options' => array(
77 'all' => BackendStrings::get('all_events'),
78 'future' => BackendStrings::get('future_events'),
79 'past' => BackendStrings::get('past_events'),
80 'custom' => BackendStrings::get('custom_range'),
81 ),
82 'default' => 'all',
83 'toggle_slug' => 'main_content',
84 'option_category' => 'basic_option',
85 'show_if' => array(
86 'booking_params' => 'on',
87 ),
88 ),
89 'start_date' => array(
90 'label' => esc_html__(BackendStrings::get('red_start_date'), 'divi-divi_amelia'),
91 'type' => 'amelia_date_picker',
92 'toggle_slug' => 'main_content',
93 'option_category' => 'basic_option',
94 'show_if' => array(
95 'booking_params' => 'on',
96 'event_to_show' => 'custom',
97 ),
98 ),
99 'end_date' => array(
100 'label' => esc_html__(BackendStrings::get('red_end_date'), 'divi-divi_amelia'),
101 'type' => 'amelia_date_picker',
102 'toggle_slug' => 'main_content',
103 'option_category' => 'basic_option',
104 'show_if' => array(
105 'booking_params' => 'on',
106 'event_to_show' => 'custom',
107 ),
108 ),
109 'events' => array(
110 'label' => esc_html__(BackendStrings::get('select_event'), 'divi-divi_amelia'),
111 'type' => 'amelia_multi_select',
112 'showAllText' => BackendStrings::get('show_all_events'),
113 'options' => $this->events,
114 'toggle_slug' => 'main_content',
115 'option_category' => 'basic_option',
116 'show_if' => array(
117 'booking_params' => 'on',
118 ),
119 ),
120 'tags' => array(
121 'label' => esc_html__(BackendStrings::get('select_tag'), 'divi-divi_amelia'),
122 'type' => 'amelia_multi_select',
123 'showAllText' => BackendStrings::get('show_all_tags'),
124 'toggle_slug' => 'main_content',
125 'options' => $this->tags,
126 'option_category' => 'basic_option',
127 'brackets' => true,
128 'show_if' => array(
129 'booking_params' => 'on',
130 ),
131 ),
132 'recurring' => array(
133 'label' => esc_html__(BackendStrings::get('recurring_event'), 'divi-divi_amelia'),
134 'type' => 'yes_no_button',
135 'options' => array(
136 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
137 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
138 ),
139 'toggle_slug' => 'main_content',
140 'option_category' => 'basic_option',
141 'show_if' => array(
142 'booking_params' => 'on',
143 ),
144 ),
145 'locations' => array(
146 'label' => esc_html__(BackendStrings::get('select_location'), 'divi-divi_amelia'),
147 'type' => 'amelia_multi_select',
148 'showAllText' => BackendStrings::get('show_all_locations'),
149 'toggle_slug' => 'main_content',
150 'options' => $this->locations,
151 'option_category' => 'basic_option',
152 'show_if' => array(
153 'booking_params' => 'on',
154 ),
155 ),
156 'trigger' => array(
157 'label' => esc_html__(BackendStrings::get('manually_loading'), 'divi-divi_amelia'),
158 'type' => 'text',
159 'toggle_slug' => 'main_content',
160 'option_category' => 'basic_option',
161 'description' => BackendStrings::get('manually_loading_description'),
162 ),
163 'trigger_type' => array(
164 'label' => esc_html__(BackendStrings::get('trigger_type'), 'divi-divi_amelia'),
165 'type' => 'select',
166 'options' => array(
167 'id' => BackendStrings::get('trigger_type_id'),
168 'class' => BackendStrings::get('trigger_type_class')
169 ),
170 'toggle_slug' => 'main_content',
171 'option_category' => 'basic_option',
172 ),
173 'in_dialog' => array(
174 'label' => esc_html__(DIVI_AmeliaWhiteLabelHelper::label(BackendStrings::get('in_dialog')), 'divi-divi_amelia'),
175 'type' => 'yes_no_button',
176 'options' => array(
177 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
178 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
179 ),
180 'toggle_slug' => 'main_content',
181 'option_category' => 'basic_option',
182 ),
183 );
184 }
185
186 public function checkValues($val)
187 {
188 if ($val !== null) {
189 $val = explode(',', $val);
190 if (is_array($val)) {
191 $newVals = [];
192 foreach ($val as $parameter) {
193 if ($parameter) {
194 $newVals[] = !is_numeric($parameter) ? (strpos($parameter, 'id:') ? substr(explode('id: ', $parameter)[1], 0, -1) : $parameter) : $parameter;
195 }
196 }
197 return count($newVals) > 0 ? $newVals : [];
198 }
199 return [];
200 }
201 return [];
202 }
203
204 public function render($attrs, $content = null, $render_slug = null)
205 {
206 $preselect = $this->props['booking_params'];
207 $shortcode = '[' . DIVI_AmeliaWhiteLabelHelper::shortcodeTag('eventslistbooking', 'ameliaeventslistbooking');
208 $trigger = $this->props['trigger'];
209 $trigger_type = $this->props['trigger_type'];
210 $in_dialog = $this->props['in_dialog'];
211 if ($trigger !== null && $trigger !== '') {
212 $shortcode .= ' trigger=' . $trigger;
213 }
214 if (!empty($trigger) && !empty($trigger_type)) {
215 $shortcode .= ' trigger_type=' . $trigger_type;
216 }
217 if (!empty($trigger) && $in_dialog === 'on') {
218 $shortcode .= ' in_dialog=1';
219 }
220 if ($preselect === 'on') {
221 $event = $this->checkValues($this->props['events']);
222
223 // Add event_to_show range logic (only if no specific event is selected)
224 if (empty($event) && !empty($this->props['event_to_show']) && $this->props['event_to_show'] !== 'all') {
225 if ($this->props['event_to_show'] === 'custom') {
226 $startDate = !empty($this->props['start_date']) ? $this->props['start_date'] : '';
227 $endDate = !empty($this->props['end_date']) ? $this->props['end_date'] : '';
228
229 $has_valid_start = $startDate && preg_match('/^\d{4}-\d{2}-\d{2}$/', $startDate);
230 $has_valid_end = $endDate && preg_match('/^\d{4}-\d{2}-\d{2}$/', $endDate);
231
232 if (!$has_valid_start || !$has_valid_end) {
233 return '';
234 }
235
236 $shortcode .= ' range="' . $startDate . ' - ' . $endDate . '"';
237 } else {
238 $shortcode .= ' range="' . $this->props['event_to_show'] . '"';
239 }
240 }
241
242 $tag = $this->props['tags'];
243 if ($event && count($event) > 0) {
244 $shortcode .= ' event=' . implode(',', $event);
245 }
246 if ($tag) {
247 $shortcode .= ' tag="' . $tag . '"';
248 }
249 $recurring = $this->props['recurring'];
250 if ($recurring === 'on') {
251 $shortcode .= ' recurring=1';
252 }
253 $locations = $this->checkValues($this->props['locations']);
254 if ($locations && count($locations) > 0) {
255 $shortcode .= ' location=' . implode(',', $locations);
256 }
257 }
258 $shortcode .= ']';
259
260 return do_shortcode($shortcode);
261 }
262 }
263
264 new DIVI_EventsList();
265