PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
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 / Booking / Booking.php
ameliabooking / extensions / divi_amelia / includes / modules / Booking Last commit date
Booking.php 7 months ago style.css 5 years ago
Booking.php
197 lines
1 <?php
2
3 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\GutenbergBlock;
4 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
5
6 class DIVI_Booking extends ET_Builder_Module
7 {
8
9 public $slug = 'divi_booking';
10 public $vb_support = 'on';
11
12 private $categories = array();
13 private $services = array();
14 private $employees = array();
15 private $locations = array();
16 private $showPackages = true;
17
18 public $type = array();
19
20
21 protected $module_credits = array(
22 'module_uri' => '',
23 'author' => '',
24 'author_uri' => '',
25 );
26
27 public function init()
28 {
29 $this->name = esc_html__(BackendStrings::get('booking_divi'), 'divi-divi_amelia');
30
31 $this->type['0'] = BackendStrings::get('show_all');
32 $this->type['services'] = BackendStrings::get('services');
33 $this->type['packages'] = BackendStrings::get('packages');
34
35 if (!is_admin()) {
36 return;
37 }
38
39 $data = GutenbergBlock::getEntitiesData()['data'];
40 $this->showPackages = !empty($data['packages']);
41
42 $this->categories['0'] = BackendStrings::get('show_all_categories');
43 foreach ($data['categories'] as $category) {
44 $this->categories[$category['id']] = $category['name']. ' (id: ' . $category['id'] . ')';
45 }
46 $this->services['0'] = BackendStrings::get('show_all_services');
47 foreach ($data['servicesList'] as $service) {
48 if ($service) {
49 $this->services[$service['id']] = $service['name']. ' (id: ' . $service['id'] . ')';
50 }
51 }
52 $this->employees['0'] = BackendStrings::get('show_all_employees');
53 foreach ($data['employees'] as $employee) {
54 $this->employees[$employee['id']] = $employee['firstName'] . ' ' . $employee['lastName'] . ' (id: ' . $employee['id'] . ')';
55 }
56 $this->locations['0'] = BackendStrings::get('show_all_locations');
57 foreach ($data['locations'] as $location) {
58 $this->locations[$location['id']] = $location['name']. ' (id: ' . $location['id'] . ')';
59 }
60 }
61
62 /**
63 * Advanced Fields Config
64 *
65 * @return array
66 */
67 public function get_advanced_fields_config()
68 {
69 return array(
70 'button' => false,
71 'link_options' => false
72 );
73 }
74
75 public function get_fields()
76 {
77 $array = array(
78 'booking_params' => array(
79 'label' => esc_html__(BackendStrings::get('filter'), 'divi-divi_amelia'),
80 'type' => 'yes_no_button',
81 'options' => array(
82 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
83 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
84 ),
85 'toggle_slug' => 'main_content',
86 'option_category' => 'basic_option',
87 ),
88 'categories' => array(
89 'label' => esc_html__(BackendStrings::get('select_category'), 'divi-divi_amelia'),
90 'type' => 'select',
91 'options' => $this->categories,
92 'toggle_slug' => 'main_content',
93 'option_category' => 'basic_option',
94 'show_if' => array(
95 'booking_params' => 'on',
96 ),
97 ),
98 'services' => array(
99 'label' => esc_html__(BackendStrings::get('select_service'), 'divi-divi_amelia'),
100 'type' => 'select',
101 'toggle_slug' => 'main_content',
102 'options' => $this->services,
103 'option_category' => 'basic_option',
104 'show_if' => array(
105 'booking_params' => 'on',
106 ),
107 ),
108 'employees' => array(
109 'label' => esc_html__(BackendStrings::get('select_employee'), 'divi-divi_amelia'),
110 'type' => 'select',
111 'options' => $this->employees,
112 'toggle_slug' => 'main_content',
113 'option_category' => 'basic_option',
114 'show_if' => array(
115 'booking_params' => 'on',
116 ),
117 ),
118 'locations' => array(
119 'label' => esc_html__(BackendStrings::get('select_location'), 'divi-divi_amelia'),
120 'type' => 'select',
121 'options' => $this->locations,
122 'toggle_slug' => 'main_content',
123 'option_category' => 'basic_option',
124 'show_if' => array(
125 'booking_params' => 'on',
126 ),
127 ),
128 );
129
130 if ($this->showPackages) {
131 $array['type'] = array(
132 'label' => esc_html__(BackendStrings::get('show_all'), 'divi-divi_amelia'),
133 'type' => 'select',
134 'options' => $this->type,
135 'toggle_slug' => 'main_content',
136 'option_category' => 'basic_option',
137 'show_if' => array(
138 'booking_params' => 'on'
139 ));
140 }
141
142 $array['trigger'] = array(
143 'label' => esc_html__(BackendStrings::get('manually_loading'), 'divi-divi_amelia'),
144 'type' => 'text',
145 'toggle_slug' => 'main_content',
146 'option_category' => 'basic_option',
147 'description' => BackendStrings::get('manually_loading_description'),
148 );
149
150 return $array;
151 }
152
153 public function checkValues($val)
154 {
155 if ($val !== null) {
156 return !is_numeric($val) ? (strpos($val, 'id:') ? substr(explode('id: ', $val)[1], 0, -1) : '0') : $val;
157 }
158 return '0';
159 }
160
161 public function render($attrs, $content = null, $render_slug = null)
162 {
163 $preselect = $this->props['booking_params'];
164 $shortcode = '[ameliabooking';
165 $showAll = isset($this->props['type']) ? $this->props['type'] : null;
166 $trigger = $this->props['trigger'];
167 if ($showAll !== null && $showAll !== '' && $showAll !== '0') {
168 $shortcode .= ' show='.$showAll;
169 }
170 if ($trigger !== null && $trigger !== '') {
171 $shortcode .= ' trigger='.$trigger;
172 }
173 if ($preselect === 'on') {
174 $category = $this->checkValues($this->props['categories']);
175 $service = $this->checkValues($this->props['services']);
176 $employee = $this->checkValues($this->props['employees']);
177 $location = $this->checkValues($this->props['locations']);
178
179 if ($service !== '0') {
180 $shortcode .= ' service=' . $service;
181 } else if ($category !== '0') {
182 $shortcode .= ' category=' . $category;
183 }
184 if ($employee !== '0') {
185 $shortcode .= ' employee=' . $employee;
186 }
187 if ($location !== '0') {
188 $shortcode .= ' location=' . $location;
189 }
190 }
191 $shortcode .= ']';
192 return do_shortcode($shortcode);
193 }
194 }
195
196 new DIVI_Booking;
197