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