PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.24
Booking for Appointments and Events Calendar – Amelia v1.2.24
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 / SettingsService / SettingsStorage.php
ameliabooking / src / Infrastructure / WP / SettingsService Last commit date
SettingsStorage.php 1 year ago
SettingsStorage.php
427 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\WP\SettingsService;
4
5 use AmeliaBooking\Application\Services\Location\AbstractCurrentLocation;
6 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
7 use AmeliaBooking\Domain\Services\Settings\SettingsStorageInterface;
8 use AmeliaBooking\Infrastructure\Licence;
9
10 /**
11 * Class SettingsStorage
12 *
13 * @package AmeliaBooking\Infrastructure\WP\SettingsService
14 */
15 class SettingsStorage implements SettingsStorageInterface
16 {
17 /** @var array|mixed */
18 private $settingsCache;
19
20 /** @var AbstractCurrentLocation */
21 private $locationService;
22
23 private static $wpSettings = [
24 'dateFormat' => 'date_format',
25 'timeFormat' => 'time_format',
26 'startOfWeek' => 'start_of_week',
27 'timeZoneString' => 'timezone_string',
28 'gmtOffset' => 'gmt_offset'
29 ];
30
31 /**
32 * SettingsStorage constructor.
33 */
34 public function __construct()
35 {
36 $this->locationService = Licence\ApplicationService::getCurrentLocationService();
37
38 $this->settingsCache = self::getSavedSettings();
39
40 Licence\DataModifier::modifySettings($this->settingsCache);
41
42 foreach (self::$wpSettings as $ameliaSetting => $wpSetting) {
43 $this->settingsCache['wordpress'][$ameliaSetting] = get_option($wpSetting);
44 }
45
46 DateTimeService::setTimeZone($this->getAllSettings());
47 }
48
49 /**
50 * @return array
51 */
52 private function getSavedSettings()
53 {
54 return json_decode(get_option('amelia_settings'), true);
55 }
56
57 /**
58 * @param $settingCategoryKey
59 * @param $settingKey
60 *
61 * @return mixed
62 */
63 public function getSetting($settingCategoryKey, $settingKey)
64 {
65 return isset($this->settingsCache[$settingCategoryKey][$settingKey]) ?
66 $this->settingsCache[$settingCategoryKey][$settingKey] : null;
67 }
68
69 /**
70 * @param $settingCategoryKey
71 *
72 * @return mixed
73 */
74 public function getCategorySettings($settingCategoryKey)
75 {
76 return isset($this->settingsCache[$settingCategoryKey]) ?
77 $this->settingsCache[$settingCategoryKey] : null;
78 }
79
80 /**
81 * @return array|mixed|null
82 */
83 public function getAllSettings()
84 {
85 $settings = [];
86
87 if (null !== $this->settingsCache) {
88 foreach ((array)$this->settingsCache as $settingsCategoryName => $settingsCategory) {
89 if ($settingsCategoryName !== 'daysOff') {
90 foreach ((array)$settingsCategory as $settingName => $settingValue) {
91 $settings[$settingName] = $settingValue;
92 }
93 }
94 }
95
96 return $settings;
97 }
98
99 return null;
100 }
101
102 /**
103 * @return array|mixed|null
104 */
105 public function getAllSettingsCategorized()
106 {
107 return isset($this->settingsCache) ? $this->settingsCache : null;
108 }
109
110 /**
111 * Return settings for frontend
112 *
113 * @return array|mixed
114 */
115 public function getFrontendSettings()
116 {
117 $phoneCountryCode = $this->getSetting('general', 'phoneDefaultCountryCode');
118 $ipLocateApyKey = $this->getSetting('general', 'ipLocateApiKey');
119
120 $capabilities = [];
121 $additionalCapabilities = [];
122 if (is_admin()) {
123 $currentScreenId = get_current_screen()->id;
124 $currentScreen = substr($currentScreenId, strrpos($currentScreenId, '-') + 1);
125
126 $capabilities = [
127 'canRead' => current_user_can('amelia_read_' . $currentScreen),
128 'canReadOthers' => current_user_can('amelia_read_others_' . $currentScreen),
129 'canWrite' => current_user_can('amelia_write_' . $currentScreen),
130 'canWriteOthers' => current_user_can('amelia_write_others_' . $currentScreen),
131 'canDelete' => current_user_can('amelia_delete_' . $currentScreen),
132 'canWriteStatus' => current_user_can('amelia_write_status_' . $currentScreen),
133 ];
134
135 $additionalCapabilities = [
136 'canWriteCustomers' => current_user_can('amelia_write_customers'),
137 ];
138 }
139
140 $wpUser = wp_get_current_user();
141
142 $userType = 'customer';
143
144 if (in_array('administrator', $wpUser->roles, true) || is_super_admin($wpUser->ID)) {
145 $userType = 'admin';
146 } elseif (in_array('wpamelia-manager', $wpUser->roles, true)) {
147 $userType = 'manager';
148 } elseif (in_array('wpamelia-provider', $wpUser->roles, true)) {
149 $userType = 'provider';
150 }
151
152 return [
153 'capabilities' => $capabilities,
154 'additionalCapabilities' => $additionalCapabilities,
155 'daysOff' => $this->getCategorySettings('daysOff'),
156 'general' => [
157 'itemsPerPage' => $this->getSetting('general', 'itemsPerPage'),
158 'itemsPerPageBackEnd' => $this->getSetting('general', 'itemsPerPageBackEnd'),
159 'appointmentsPerPage' => $this->getSetting('general', 'appointmentsPerPage'),
160 'eventsPerPage' => $this->getSetting('general', 'eventsPerPage'),
161 'servicesPerPage' => $this->getSetting('general', 'servicesPerPage'),
162 'customersFilterLimit' => $this->getSetting('general', 'customersFilterLimit'),
163 'eventsFilterLimit' => $this->getSetting('general', 'eventsFilterLimit') ?: 1000,
164 'calendarEmployeesPreselected' => $this->getSetting('general', 'calendarEmployeesPreselected'),
165 'phoneDefaultCountryCode' => $phoneCountryCode === 'auto' ?
166 $this->locationService->getCurrentLocationCountryIso($ipLocateApyKey) : $phoneCountryCode,
167 'timeSlotLength' => $this->getSetting('general', 'timeSlotLength'),
168 'serviceDurationAsSlot' => $this->getSetting('general', 'serviceDurationAsSlot'),
169 'defaultAppointmentStatus' => $this->getSetting('general', 'defaultAppointmentStatus'),
170 'gMapApiKey' => $this->getSetting('general', 'gMapApiKey'),
171 'addToCalendar' => $this->getSetting('general', 'addToCalendar'),
172 'requiredPhoneNumberField' => $this->getSetting('general', 'requiredPhoneNumberField'),
173 'requiredEmailField' => $this->getSetting('general', 'requiredEmailField'),
174 'numberOfDaysAvailableForBooking' => $this->getSetting('general', 'numberOfDaysAvailableForBooking'),
175 'minimumTimeRequirementPriorToBooking' =>
176 $this->getSetting('general', 'minimumTimeRequirementPriorToBooking'),
177 'minimumTimeRequirementPriorToCanceling' =>
178 $this->getSetting('general', 'minimumTimeRequirementPriorToCanceling'),
179 'minimumTimeRequirementPriorToRescheduling' =>
180 $this->getSetting('general', 'minimumTimeRequirementPriorToRescheduling'),
181 'showClientTimeZone' => $this->getSetting('general', 'showClientTimeZone'),
182 'redirectUrlAfterAppointment' => $this->getSetting('general', 'redirectUrlAfterAppointment'),
183 'customFieldsUploadsPath' => $this->getSetting('general', 'customFieldsUploadsPath'),
184 'customFieldsAllowedExtensions' => $this->getSetting('general', 'customFieldsAllowedExtensions'),
185 'runInstantPostBookingActions' => $this->getSetting('general', 'runInstantPostBookingActions'),
186 'sortingPackages' => $this->getSetting('general', 'sortingPackages'),
187 'backLink' => $this->getSetting('general', 'backLink'),
188 'sortingServices' => $this->getSetting('general', 'sortingServices'),
189 'googleRecaptcha' => [
190 'enabled' => $this->getSetting('general', 'googleRecaptcha')['enabled'],
191 'invisible' => $this->getSetting('general', 'googleRecaptcha')['invisible'],
192 'siteKey' => $this->getSetting('general', 'googleRecaptcha')['siteKey'],
193 ],
194 'usedLanguages' => $this->getSetting('general', 'usedLanguages'),
195 ],
196 'googleMeet' => [
197 'enabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet'),
198 ],
199 'microsoftTeams' => [
200 'enabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
201 ],
202 'googleCalendar' => [
203 'enabled' => $this->getSetting('googleCalendar', 'clientID') && $this->getSetting('googleCalendar', 'clientSecret'),
204 'googleMeetEnabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet')
205 ],
206 'outlookCalendar' => [
207 'enabled' => $this->getSetting('outlookCalendar', 'clientID') && $this->getSetting('outlookCalendar', 'clientSecret'),
208 'microsoftTeamsEnabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
209 ],
210 'appleCalendar' =>
211 $this->getSetting('appleCalendar', 'clientID') && $this->getSetting('appleCalendar', 'clientSecret'),
212 'zoom' => [
213 'enabled' => (
214 $this->getSetting('zoom', 'enabled') &&
215 $this->getSetting('zoom', 'accountId') &&
216 $this->getSetting('zoom', 'clientId') &&
217 $this->getSetting('zoom', 'clientSecret')
218 )
219 ],
220 'facebookPixel' => $this->getCategorySettings('facebookPixel'),
221 'googleAnalytics' => $this->getCategorySettings('googleAnalytics'),
222 'googleTag' => $this->getCategorySettings('googleTag'),
223 'lessonSpace' => [
224 'enabled' => $this->getSetting('lessonSpace', 'enabled') && $this->getSetting('lessonSpace', 'apiKey')
225 ],
226 'notifications' => [
227 'senderName' => $this->getSetting('notifications', 'senderName'),
228 'replyTo' => $this->getSetting('notifications', 'replyTo'),
229 'senderEmail' => $this->getSetting('notifications', 'senderEmail'),
230 'notifyCustomers' => $this->getSetting('notifications', 'notifyCustomers'),
231 'sendAllCF' => $this->getSetting('notifications', 'sendAllCF'),
232 'cancelSuccessUrl' => $this->getSetting('notifications', 'cancelSuccessUrl'),
233 'cancelErrorUrl' => $this->getSetting('notifications', 'cancelErrorUrl'),
234 'approveSuccessUrl' => $this->getSetting('notifications', 'approveSuccessUrl'),
235 'approveErrorUrl' => $this->getSetting('notifications', 'approveErrorUrl'),
236 'rejectSuccessUrl' => $this->getSetting('notifications', 'rejectSuccessUrl'),
237 'rejectErrorUrl' => $this->getSetting('notifications', 'rejectErrorUrl'),
238 'smsSignedIn' => $this->getSetting('notifications', 'smsSignedIn'),
239 'bccEmail' => $this->getSetting('notifications', 'bccEmail'),
240 'bccSms' => $this->getSetting('notifications', 'bccSms'),
241 'smsBalanceEmail' => $this->getSetting('notifications', 'smsBalanceEmail'),
242 'whatsAppPhoneID' => $this->getSetting('notifications', 'whatsAppPhoneID'),
243 'whatsAppAccessToken' => $this->getSetting('notifications', 'whatsAppAccessToken'),
244 'whatsAppBusinessID' => $this->getSetting('notifications', 'whatsAppBusinessID'),
245 'whatsAppLanguage' => $this->getSetting('notifications', 'whatsAppLanguage'),
246 'whatsAppEnabled' => $this->getSetting('notifications', 'whatsAppEnabled'),
247 ],
248 'payments' => [
249 'currency' => $this->getSetting('payments', 'symbol'),
250 'currencyCode' => $this->getSetting('payments', 'currency'),
251 'priceSymbolPosition' => $this->getSetting('payments', 'priceSymbolPosition'),
252 'priceNumberOfDecimals' => $this->getSetting('payments', 'priceNumberOfDecimals'),
253 'priceSeparator' => $this->getSetting('payments', 'priceSeparator'),
254 'hideCurrencySymbolFrontend' => $this->getSetting('payments', 'hideCurrencySymbolFrontend'),
255 'defaultPaymentMethod' => $this->getSetting('payments', 'defaultPaymentMethod'),
256 'onSite' => $this->getSetting('payments', 'onSite'),
257 'couponsCaseInsensitive' => $this->getSetting('payments', 'couponsCaseInsensitive'),
258 'coupons' => $this->getSetting('payments', 'coupons'),
259 'taxes' => $this->getSetting('payments', 'taxes'),
260 'cart' => $this->getSetting('payments', 'cart'),
261 'paymentLinks' => [
262 'enabled' => $this->getSetting('payments', 'paymentLinks')['enabled'],
263 'changeBookingStatus' => $this->getSetting('payments', 'paymentLinks')['changeBookingStatus'],
264 'redirectUrl' => $this->getSetting('payments', 'paymentLinks')['redirectUrl']
265 ],
266 'payPal' => [
267 'enabled' => $this->getSetting('payments', 'payPal')['enabled'],
268 'sandboxMode' => $this->getSetting('payments', 'payPal')['sandboxMode'],
269 'testApiClientId' => $this->getSetting('payments', 'payPal')['testApiClientId'],
270 'liveApiClientId' => $this->getSetting('payments', 'payPal')['liveApiClientId'],
271 ],
272 'stripe' => [
273 'enabled' => $this->getSetting('payments', 'stripe')['enabled'],
274 'testMode' => $this->getSetting('payments', 'stripe')['testMode'],
275 'livePublishableKey' => $this->getSetting('payments', 'stripe')['livePublishableKey'],
276 'testPublishableKey' => $this->getSetting('payments', 'stripe')['testPublishableKey'],
277 'connect' => $this->getSetting('payments', 'stripe')['connect'],
278 'address' => $this->getSetting('payments', 'stripe')['address'],
279 ],
280 'wc' => [
281 'enabled' => $this->getSetting('payments', 'wc')['enabled'],
282 'productId' => $this->getSetting('payments', 'wc')['productId'],
283 'page' => $this->getSetting('payments', 'wc')['page'],
284 'onSiteIfFree' => $this->getSetting('payments', 'wc')['onSiteIfFree']
285 ],
286 'mollie' => [
287 'enabled' => $this->getSetting('payments', 'mollie')['enabled'],
288 'cancelBooking' => $this->getSetting('payments', 'mollie')['cancelBooking'],
289 ],
290 'square' => [
291 'enabled' => $this->getSetting('payments', 'square')['enabled'],
292 'testMode' => $this->getSetting('payments', 'square')['testMode'],
293 'accessTokenSet' => !empty($this->getSetting('payments', 'square')['accessToken']) && !empty($this->getSetting('payments', 'square')['accessToken']['access_token']),
294 'locationId' => $this->getSetting('payments', 'square')['locationId']
295 ],
296 'razorpay' => [
297 'enabled' => $this->getSetting('payments', 'razorpay')['enabled'],
298 ],
299 ],
300 'role' => $userType,
301 'weekSchedule' => $this->getCategorySettings('weekSchedule'),
302 'wordpress' => [
303 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'),
304 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'),
305 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'),
306 'timezone' => $this->getSetting('wordpress', 'timeZoneString'),
307 'locale' => AMELIA_LOCALE
308 ],
309 'labels' => [
310 'enabled' => $this->getSetting('labels', 'enabled')
311 ],
312 'activation' => [
313 'showAmeliaSurvey' => $this->getSetting('activation', 'showAmeliaSurvey'),
314 'showAmeliaPromoCustomizePopup' => $this->getSetting('activation', 'showAmeliaPromoCustomizePopup'),
315 'showActivationSettings' => $this->getSetting('activation', 'showActivationSettings'),
316 'stash' => $this->getSetting('activation', 'stash'),
317 'disableUrlParams' => $this->getSetting('activation', 'disableUrlParams'),
318 'isNewInstallation' => $this->getSetting('activation', 'isNewInstallation'),
319 'hideUnavailableFeatures' => $this->getSetting('activation', 'hideUnavailableFeatures'),
320 'premiumBannerVisibility' => $this->getSetting('activation', 'premiumBannerVisibility'),
321 'dismissibleBannerVisibility' => $this->getSetting('activation', 'dismissibleBannerVisibility'),
322 ],
323 'roles' => [
324 'allowAdminBookAtAnyTime' => $this->getSetting('roles', 'allowAdminBookAtAnyTime'),
325 'adminServiceDurationAsSlot' => $this->getSetting('roles', 'adminServiceDurationAsSlot'),
326 'allowConfigureSchedule' => $this->getSetting('roles', 'allowConfigureSchedule'),
327 'allowConfigureDaysOff' => $this->getSetting('roles', 'allowConfigureDaysOff'),
328 'allowConfigureSpecialDays' => $this->getSetting('roles', 'allowConfigureSpecialDays'),
329 'allowConfigureServices' => $this->getSetting('roles', 'allowConfigureServices'),
330 'allowWriteAppointments' => $this->getSetting('roles', 'allowWriteAppointments'),
331 'allowWriteCustomers' => $this->getSetting('roles', 'allowWriteCustomers'),
332 'automaticallyCreateCustomer' => $this->getSetting('roles', 'automaticallyCreateCustomer'),
333 'inspectCustomerInfo' => $this->getSetting('roles', 'inspectCustomerInfo'),
334 'allowCustomerReschedule' => $this->getSetting('roles', 'allowCustomerReschedule'),
335 'allowCustomerCancelPackages' => $this->getSetting('roles', 'allowCustomerCancelPackages'),
336 'allowCustomerDeleteProfile' => $this->getSetting('roles', 'allowCustomerDeleteProfile'),
337 'allowWriteEvents' => $this->getSetting('roles', 'allowWriteEvents'),
338 'customerCabinet' => [
339 'enabled' => $this->getSetting('roles', 'customerCabinet')['enabled'],
340 'loginEnabled' => $this->getSetting('roles', 'customerCabinet')['loginEnabled'],
341 'tokenValidTime' => $this->getSetting('roles', 'customerCabinet')['tokenValidTime'],
342 'pageUrl' => $this->getSetting('roles', 'customerCabinet')['pageUrl'],
343 ],
344 'providerCabinet' => [
345 'enabled' => $this->getSetting('roles', 'providerCabinet')['enabled'],
346 'loginEnabled' => $this->getSetting('roles', 'providerCabinet')['loginEnabled'],
347 'tokenValidTime' => $this->getSetting('roles', 'providerCabinet')['tokenValidTime'],
348 ],
349 'providerBadges' => $this->getSetting('roles', 'providerBadges'),
350 'enableNoShowTag' => $this->getSetting('roles', 'enableNoShowTag'),
351 'limitPerCustomerService' => $this->getSetting('roles', 'limitPerCustomerService'),
352 'limitPerCustomerPackage' => $this->getSetting('roles', 'limitPerCustomerPackage'),
353 'limitPerCustomerEvent' => $this->getSetting('roles', 'limitPerCustomerEvent'),
354 'limitPerEmployee' => $this->getSetting('roles', 'limitPerEmployee'),
355 ],
356 'customization' => $this->getCategorySettings('customization'),
357 'customizedData' => $this->getCategorySettings('customizedData'),
358 'appointments' => $this->getCategorySettings('appointments'),
359 'slotDateConstraints' => [
360 'minDate' => DateTimeService::getNowDateTimeObject()
361 ->modify("+{$this->getSetting('general', 'minimumTimeRequirementPriorToBooking')} seconds")
362 ->format('Y-m-d H:i:s'),
363 'maxDate' => DateTimeService::getNowDateTimeObject()
364 ->modify("+{$this->getSetting('general', 'numberOfDaysAvailableForBooking')} day")
365 ->format('Y-m-d H:i:s')
366 ],
367 'company' => [
368 'email' => $this->getSetting('company', 'email'),
369 'phone' => $this->getSetting('company', 'phone'),
370 ]
371 ];
372 }
373
374 /**
375 * @param $settingCategoryKey
376 * @param $settingKey
377 * @param $settingValue
378 *
379 * @return mixed|void
380 */
381 public function setSetting($settingCategoryKey, $settingKey, $settingValue)
382 {
383 $this->settingsCache[$settingCategoryKey][$settingKey] = $settingValue;
384 $settingsCopy = $this->settingsCache;
385
386 unset($settingsCopy['wordpress']);
387 update_option('amelia_settings', json_encode($settingsCopy));
388 }
389
390 /**
391 * @param $settingCategoryKey
392 * @param $settingValues
393 *
394 * @return mixed|void
395 */
396 public function setCategorySettings($settingCategoryKey, $settingValues)
397 {
398 $this->settingsCache[$settingCategoryKey] = $settingValues;
399 $settingsCopy = $this->settingsCache;
400
401 unset($settingsCopy['wordpress']);
402 update_option('amelia_settings', json_encode($settingsCopy));
403 }
404
405 /**
406 * @param array $settings
407 *
408 * @return mixed|void
409 */
410 public function setAllSettings($settings)
411 {
412 foreach ($settings as $settingCategoryKey => $settingValues) {
413 $this->settingsCache[$settingCategoryKey] = $settingValues;
414 }
415 $settingsCopy = $this->settingsCache;
416
417 Licence\DataModifier::restoreSettings($settingsCopy, self::getSavedSettings());
418
419 if (get_option('amelia_show_wpdt_promo') === false) {
420 update_option('amelia_show_wpdt_promo', 'yes' );
421 }
422
423 unset($settingsCopy['wordpress']);
424 update_option('amelia_settings', json_encode($settingsCopy));
425 }
426 }
427