PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.31
Booking for Appointments and Events Calendar – Amelia v1.2.31
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
447 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 'googleClientId' => $this->getSetting('googleCalendar', 'clientID'),
172 'addToCalendar' => $this->getSetting('general', 'addToCalendar'),
173 'requiredPhoneNumberField' => $this->getSetting('general', 'requiredPhoneNumberField'),
174 'requiredEmailField' => $this->getSetting('general', 'requiredEmailField'),
175 'numberOfDaysAvailableForBooking' => $this->getSetting('general', 'numberOfDaysAvailableForBooking'),
176 'minimumTimeRequirementPriorToBooking' =>
177 $this->getSetting('general', 'minimumTimeRequirementPriorToBooking'),
178 'minimumTimeRequirementPriorToCanceling' =>
179 $this->getSetting('general', 'minimumTimeRequirementPriorToCanceling'),
180 'minimumTimeRequirementPriorToRescheduling' =>
181 $this->getSetting('general', 'minimumTimeRequirementPriorToRescheduling'),
182 'showClientTimeZone' => $this->getSetting('general', 'showClientTimeZone'),
183 'redirectUrlAfterAppointment' => $this->getSetting('general', 'redirectUrlAfterAppointment'),
184 'customFieldsUploadsPath' => $this->getSetting('general', 'customFieldsUploadsPath'),
185 'customFieldsAllowedExtensions' => $this->getSetting('general', 'customFieldsAllowedExtensions'),
186 'runInstantPostBookingActions' => $this->getSetting('general', 'runInstantPostBookingActions'),
187 'sortingPackages' => $this->getSetting('general', 'sortingPackages'),
188 'backLink' => $this->getSetting('general', 'backLink'),
189 'sortingServices' => $this->getSetting('general', 'sortingServices'),
190 'googleRecaptcha' => [
191 'enabled' => $this->getSetting('general', 'googleRecaptcha')['enabled'],
192 'invisible' => $this->getSetting('general', 'googleRecaptcha')['invisible'],
193 'siteKey' => $this->getSetting('general', 'googleRecaptcha')['siteKey'],
194 ],
195 'usedLanguages' => $this->getSetting('general', 'usedLanguages'),
196 ],
197 'googleMeet' => [
198 'enabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet'),
199 ],
200 'microsoftTeams' => [
201 'enabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
202 ],
203 'googleCalendar' => [
204 'enabled' =>
205 $this->getSetting('googleCalendar', 'clientID') &&
206 $this->getSetting('googleCalendar', 'clientSecret') &&
207 $this->getSetting('googleCalendar', 'calendarEnabled'),
208 'googleMeetEnabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet')
209 ],
210 'outlookCalendar' => [
211 'enabled' =>
212 $this->getSetting('outlookCalendar', 'clientID') &&
213 $this->getSetting('outlookCalendar', 'clientSecret') &&
214 $this->getSetting('outlookCalendar', 'calendarEnabled'),
215 'microsoftTeamsEnabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'),
216 ],
217 'appleCalendar' =>
218 $this->getSetting('appleCalendar', 'clientID') && $this->getSetting('appleCalendar', 'clientSecret'),
219 'zoom' => [
220 'enabled' => (
221 $this->getSetting('zoom', 'enabled') &&
222 $this->getSetting('zoom', 'accountId') &&
223 $this->getSetting('zoom', 'clientId') &&
224 $this->getSetting('zoom', 'clientSecret')
225 )
226 ],
227 'facebookPixel' => $this->getCategorySettings('facebookPixel'),
228 'googleAnalytics' => $this->getCategorySettings('googleAnalytics'),
229 'googleTag' => $this->getCategorySettings('googleTag'),
230 'lessonSpace' => [
231 'enabled' => $this->getSetting('lessonSpace', 'enabled') && $this->getSetting('lessonSpace', 'apiKey')
232 ],
233 'socialLogin' => [
234 'googleLoginEnabled' => $this->getSetting('socialLogin', 'enableGoogleLogin'),
235 'facebookLoginEnabled' => $this->getSetting('socialLogin', 'enableFacebookLogin'),
236 'facebookAppId' => $this->getSetting('socialLogin', 'facebookAppId'),
237 'facebookCredentialsEnabled' => $this->getSetting('socialLogin', 'facebookAppId') &&
238 $this->getSetting('socialLogin', 'facebookAppSecret'),
239 ],
240 'notifications' => [
241 'senderName' => $this->getSetting('notifications', 'senderName'),
242 'replyTo' => $this->getSetting('notifications', 'replyTo'),
243 'senderEmail' => $this->getSetting('notifications', 'senderEmail'),
244 'notifyCustomers' => $this->getSetting('notifications', 'notifyCustomers'),
245 'sendAllCF' => $this->getSetting('notifications', 'sendAllCF'),
246 'cancelSuccessUrl' => $this->getSetting('notifications', 'cancelSuccessUrl'),
247 'cancelErrorUrl' => $this->getSetting('notifications', 'cancelErrorUrl'),
248 'approveSuccessUrl' => $this->getSetting('notifications', 'approveSuccessUrl'),
249 'approveErrorUrl' => $this->getSetting('notifications', 'approveErrorUrl'),
250 'rejectSuccessUrl' => $this->getSetting('notifications', 'rejectSuccessUrl'),
251 'rejectErrorUrl' => $this->getSetting('notifications', 'rejectErrorUrl'),
252 'smsSignedIn' => $this->getSetting('notifications', 'smsSignedIn'),
253 'bccEmail' => $this->getSetting('notifications', 'bccEmail'),
254 'bccSms' => $this->getSetting('notifications', 'bccSms'),
255 'smsBalanceEmail' => $this->getSetting('notifications', 'smsBalanceEmail'),
256 'whatsAppPhoneID' => $this->getSetting('notifications', 'whatsAppPhoneID'),
257 'whatsAppAccessToken' => $this->getSetting('notifications', 'whatsAppAccessToken'),
258 'whatsAppBusinessID' => $this->getSetting('notifications', 'whatsAppBusinessID'),
259 'whatsAppLanguage' => $this->getSetting('notifications', 'whatsAppLanguage'),
260 'whatsAppEnabled' => $this->getSetting('notifications', 'whatsAppEnabled'),
261 ],
262 'payments' => [
263 'currency' => $this->getSetting('payments', 'symbol'),
264 'currencyCode' => $this->getSetting('payments', 'currency'),
265 'priceSymbolPosition' => $this->getSetting('payments', 'priceSymbolPosition'),
266 'priceNumberOfDecimals' => $this->getSetting('payments', 'priceNumberOfDecimals'),
267 'priceSeparator' => $this->getSetting('payments', 'priceSeparator'),
268 'hideCurrencySymbolFrontend' => $this->getSetting('payments', 'hideCurrencySymbolFrontend'),
269 'defaultPaymentMethod' => $this->getSetting('payments', 'defaultPaymentMethod'),
270 'onSite' => $this->getSetting('payments', 'onSite'),
271 'couponsCaseInsensitive' => $this->getSetting('payments', 'couponsCaseInsensitive'),
272 'coupons' => $this->getSetting('payments', 'coupons'),
273 'taxes' => $this->getSetting('payments', 'taxes'),
274 'cart' => $this->getSetting('payments', 'cart'),
275 'paymentLinks' => [
276 'enabled' => $this->getSetting('payments', 'paymentLinks')['enabled'],
277 'changeBookingStatus' => $this->getSetting('payments', 'paymentLinks')['changeBookingStatus'],
278 'redirectUrl' => $this->getSetting('payments', 'paymentLinks')['redirectUrl']
279 ],
280 'payPal' => [
281 'enabled' => $this->getSetting('payments', 'payPal')['enabled'],
282 'sandboxMode' => $this->getSetting('payments', 'payPal')['sandboxMode'],
283 'testApiClientId' => $this->getSetting('payments', 'payPal')['testApiClientId'],
284 'liveApiClientId' => $this->getSetting('payments', 'payPal')['liveApiClientId'],
285 ],
286 'stripe' => [
287 'enabled' => $this->getSetting('payments', 'stripe')['enabled'],
288 'testMode' => $this->getSetting('payments', 'stripe')['testMode'],
289 'livePublishableKey' => $this->getSetting('payments', 'stripe')['livePublishableKey'],
290 'testPublishableKey' => $this->getSetting('payments', 'stripe')['testPublishableKey'],
291 'connect' => $this->getSetting('payments', 'stripe')['connect'],
292 'address' => $this->getSetting('payments', 'stripe')['address'],
293 ],
294 'wc' => [
295 'enabled' => $this->getSetting('payments', 'wc')['enabled'],
296 'productId' => $this->getSetting('payments', 'wc')['productId'],
297 'page' => $this->getSetting('payments', 'wc')['page'],
298 'onSiteIfFree' => $this->getSetting('payments', 'wc')['onSiteIfFree']
299 ],
300 'mollie' => [
301 'enabled' => $this->getSetting('payments', 'mollie')['enabled'],
302 'cancelBooking' => $this->getSetting('payments', 'mollie')['cancelBooking'],
303 ],
304 'square' => [
305 'enabled' => $this->getSetting('payments', 'square')['enabled'],
306 'countryCode' => $this->getSetting('payments', 'square')['countryCode'],
307 'clientLiveId' => $this->getSetting('payments', 'square')['clientLiveId'],
308 'clientTestId' => $this->getSetting('payments', 'square')['clientTestId'],
309 'testMode' => $this->getSetting('payments', 'square')['testMode'],
310 'accessTokenSet' =>
311 !empty($this->getSetting('payments', 'square')['accessToken']) &&
312 !empty($this->getSetting('payments', 'square')['accessToken']['access_token']),
313 'locationId' => $this->getSetting('payments', 'square')['locationId']
314 ],
315 'razorpay' => [
316 'enabled' => $this->getSetting('payments', 'razorpay')['enabled'],
317 ],
318 ],
319 'role' => $userType,
320 'weekSchedule' => $this->getCategorySettings('weekSchedule'),
321 'wordpress' => [
322 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'),
323 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'),
324 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'),
325 'timezone' => $this->getSetting('wordpress', 'timeZoneString'),
326 'locale' => AMELIA_LOCALE
327 ],
328 'labels' => [
329 'enabled' => $this->getSetting('labels', 'enabled')
330 ],
331 'activation' => [
332 'showAmeliaSurvey' => $this->getSetting('activation', 'showAmeliaSurvey'),
333 'showAmeliaPromoCustomizePopup' => $this->getSetting('activation', 'showAmeliaPromoCustomizePopup'),
334 'showActivationSettings' => $this->getSetting('activation', 'showActivationSettings'),
335 'stash' => $this->getSetting('activation', 'stash'),
336 'disableUrlParams' => $this->getSetting('activation', 'disableUrlParams'),
337 'isNewInstallation' => $this->getSetting('activation', 'isNewInstallation'),
338 'hideUnavailableFeatures' => $this->getSetting('activation', 'hideUnavailableFeatures'),
339 'premiumBannerVisibility' => $this->getSetting('activation', 'premiumBannerVisibility'),
340 'dismissibleBannerVisibility' => $this->getSetting('activation', 'dismissibleBannerVisibility'),
341 ],
342 'roles' => [
343 'allowAdminBookAtAnyTime' => $this->getSetting('roles', 'allowAdminBookAtAnyTime'),
344 'allowAdminBookOverApp' => $this->getSetting('roles', 'allowAdminBookOverApp'),
345 'adminServiceDurationAsSlot' => $this->getSetting('roles', 'adminServiceDurationAsSlot'),
346 'allowConfigureSchedule' => $this->getSetting('roles', 'allowConfigureSchedule'),
347 'allowConfigureDaysOff' => $this->getSetting('roles', 'allowConfigureDaysOff'),
348 'allowConfigureSpecialDays' => $this->getSetting('roles', 'allowConfigureSpecialDays'),
349 'allowConfigureServices' => $this->getSetting('roles', 'allowConfigureServices'),
350 'allowWriteAppointments' => $this->getSetting('roles', 'allowWriteAppointments'),
351 'allowWriteCustomers' => $this->getSetting('roles', 'allowWriteCustomers'),
352 'automaticallyCreateCustomer' => $this->getSetting('roles', 'automaticallyCreateCustomer'),
353 'inspectCustomerInfo' => $this->getSetting('roles', 'inspectCustomerInfo'),
354 'allowCustomerReschedule' => $this->getSetting('roles', 'allowCustomerReschedule'),
355 'allowCustomerCancelPackages' => $this->getSetting('roles', 'allowCustomerCancelPackages'),
356 'allowCustomerDeleteProfile' => $this->getSetting('roles', 'allowCustomerDeleteProfile'),
357 'allowWriteEvents' => $this->getSetting('roles', 'allowWriteEvents'),
358 'customerCabinet' => [
359 'enabled' => $this->getSetting('roles', 'customerCabinet')['enabled'],
360 'loginEnabled' => $this->getSetting('roles', 'customerCabinet')['loginEnabled'],
361 'tokenValidTime' => $this->getSetting('roles', 'customerCabinet')['tokenValidTime'],
362 'pageUrl' => $this->getSetting('roles', 'customerCabinet')['pageUrl'],
363 ],
364 'providerCabinet' => [
365 'enabled' => $this->getSetting('roles', 'providerCabinet')['enabled'],
366 'loginEnabled' => $this->getSetting('roles', 'providerCabinet')['loginEnabled'],
367 'tokenValidTime' => $this->getSetting('roles', 'providerCabinet')['tokenValidTime'],
368 ],
369 'providerBadges' => $this->getSetting('roles', 'providerBadges'),
370 'enableNoShowTag' => $this->getSetting('roles', 'enableNoShowTag'),
371 'limitPerCustomerService' => $this->getSetting('roles', 'limitPerCustomerService'),
372 'limitPerCustomerPackage' => $this->getSetting('roles', 'limitPerCustomerPackage'),
373 'limitPerCustomerEvent' => $this->getSetting('roles', 'limitPerCustomerEvent'),
374 'limitPerEmployee' => $this->getSetting('roles', 'limitPerEmployee'),
375 ],
376 'customization' => $this->getCategorySettings('customization'),
377 'customizedData' => $this->getCategorySettings('customizedData'),
378 'appointments' => $this->getCategorySettings('appointments'),
379 'slotDateConstraints' => [
380 'minDate' => DateTimeService::getNowDateTimeObject()
381 ->modify("+{$this->getSetting('general', 'minimumTimeRequirementPriorToBooking')} seconds")
382 ->format('Y-m-d H:i:s'),
383 'maxDate' => DateTimeService::getNowDateTimeObject()
384 ->modify("+{$this->getSetting('general', 'numberOfDaysAvailableForBooking')} day")
385 ->format('Y-m-d H:i:s')
386 ],
387 'company' => [
388 'email' => $this->getSetting('company', 'email'),
389 'phone' => $this->getSetting('company', 'phone'),
390 ]
391 ];
392 }
393
394 /**
395 * @param $settingCategoryKey
396 * @param $settingKey
397 * @param $settingValue
398 *
399 * @return mixed|void
400 */
401 public function setSetting($settingCategoryKey, $settingKey, $settingValue)
402 {
403 $this->settingsCache[$settingCategoryKey][$settingKey] = $settingValue;
404 $settingsCopy = $this->settingsCache;
405
406 unset($settingsCopy['wordpress']);
407 update_option('amelia_settings', json_encode($settingsCopy));
408 }
409
410 /**
411 * @param $settingCategoryKey
412 * @param $settingValues
413 *
414 * @return mixed|void
415 */
416 public function setCategorySettings($settingCategoryKey, $settingValues)
417 {
418 $this->settingsCache[$settingCategoryKey] = $settingValues;
419 $settingsCopy = $this->settingsCache;
420
421 unset($settingsCopy['wordpress']);
422 update_option('amelia_settings', json_encode($settingsCopy));
423 }
424
425 /**
426 * @param array $settings
427 *
428 * @return mixed|void
429 */
430 public function setAllSettings($settings)
431 {
432 foreach ($settings as $settingCategoryKey => $settingValues) {
433 $this->settingsCache[$settingCategoryKey] = $settingValues;
434 }
435 $settingsCopy = $this->settingsCache;
436
437 Licence\DataModifier::restoreSettings($settingsCopy, self::getSavedSettings());
438
439 if (get_option('amelia_show_wpdt_promo') === false) {
440 update_option('amelia_show_wpdt_promo', 'yes');
441 }
442
443 unset($settingsCopy['wordpress']);
444 update_option('amelia_settings', json_encode($settingsCopy));
445 }
446 }
447