PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.1
Booking for Appointments and Events Calendar – Amelia v2.1
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 / Domain / Factory / Settings / SettingsFactory.php
ameliabooking / src / Domain / Factory / Settings Last commit date
SettingsFactory.php 6 months ago
SettingsFactory.php
131 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Domain\Factory\Settings;
9
10 use AmeliaBooking\Domain\Entity\Settings\GeneralSettings;
11 use AmeliaBooking\Domain\Entity\Settings\GoogleMeetSettings;
12 use AmeliaBooking\Domain\Entity\Settings\LessonSpaceSettings;
13 use AmeliaBooking\Domain\Entity\Settings\MicrosoftTeamsSettings;
14 use AmeliaBooking\Domain\Entity\Settings\PaymentSettings;
15 use AmeliaBooking\Domain\Entity\Settings\Settings;
16 use AmeliaBooking\Domain\Entity\Settings\ZoomSettings;
17 use AmeliaBooking\Domain\ValueObjects\Json;
18
19 /**
20 * Class SettingsFactory
21 *
22 * @package AmeliaBooking\Domain\Factory\Settings
23 */
24 class SettingsFactory
25 {
26 /**
27 * @param Json $entityJsonData
28 * @param array $globalSettings
29 *
30 * @return Settings
31 */
32 public static function create($entityJsonData, $globalSettings)
33 {
34 $entitySettings = new Settings();
35 $generalSettings = new GeneralSettings();
36 $zoomSettings = new ZoomSettings();
37 $paymentSettings = new PaymentSettings();
38 $lessonSpaceSetings = new LessonSpaceSettings();
39 $googleMeetSettings = new GoogleMeetSettings();
40 $microsoftTeamsSettings = new MicrosoftTeamsSettings();
41
42 $data = $entityJsonData ? json_decode($entityJsonData->getValue(), true) : [];
43
44 $isOldEntitySettings = !isset($data['activation']['version']);
45
46 if (isset($data['general']['defaultAppointmentStatus'])) {
47 $generalSettings->setDefaultAppointmentStatus($data['general']['defaultAppointmentStatus']);
48 } else {
49 $generalSettings->setDefaultAppointmentStatus($globalSettings['general']['defaultAppointmentStatus']);
50 }
51
52 if (isset($data['general']['minimumTimeRequirementPriorToBooking'])) {
53 $generalSettings->setMinimumTimeRequirementPriorToBooking(
54 $data['general']['minimumTimeRequirementPriorToBooking']
55 );
56 } else {
57 $generalSettings->setMinimumTimeRequirementPriorToBooking(
58 $globalSettings['general']['minimumTimeRequirementPriorToBooking']
59 );
60 }
61
62 if (isset($data['general']['minimumTimeRequirementPriorToCanceling'])) {
63 $generalSettings->setMinimumTimeRequirementPriorToCanceling(
64 $data['general']['minimumTimeRequirementPriorToCanceling']
65 );
66 } else {
67 $generalSettings->setMinimumTimeRequirementPriorToCanceling(
68 $globalSettings['general']['minimumTimeRequirementPriorToCanceling']
69 );
70 }
71
72 if (isset($data['general']['minimumTimeRequirementPriorToRescheduling'])) {
73 $generalSettings->setMinimumTimeRequirementPriorToRescheduling(
74 $data['general']['minimumTimeRequirementPriorToRescheduling']
75 );
76 } else {
77 $generalSettings->setMinimumTimeRequirementPriorToRescheduling(
78 $globalSettings['general']['minimumTimeRequirementPriorToRescheduling']
79 );
80 }
81
82 if ($isOldEntitySettings && !isset($globalSettings['general']['minimumTimeRequirementPriorToCanceling'])) {
83 $generalSettings->setMinimumTimeRequirementPriorToRescheduling(
84 $generalSettings->getMinimumTimeRequirementPriorToCanceling()
85 );
86 }
87
88 if (!empty($data['general']['numberOfDaysAvailableForBooking'])) {
89 $generalSettings->setNumberOfDaysAvailableForBooking(
90 $data['general']['numberOfDaysAvailableForBooking']
91 );
92 } else {
93 $generalSettings->setNumberOfDaysAvailableForBooking(
94 $globalSettings['general']['numberOfDaysAvailableForBooking']
95 );
96 }
97
98 if (isset($data['zoom']['enabled'])) {
99 $zoomSettings->setEnabled($data['zoom']['enabled']);
100 } else {
101 $zoomSettings->setEnabled($globalSettings['zoom']['enabled']);
102 }
103
104 if (isset($data['lessonSpace']['enabled'])) {
105 $lessonSpaceSetings->setEnabled($data['lessonSpace']['enabled']);
106 } else {
107 $lessonSpaceSetings->setEnabled($globalSettings['featuresIntegrations']['lessonSpace']['enabled']);
108 }
109
110 if (isset($data['googleMeet']['enabled'])) {
111 $googleMeetSettings->setEnabled($data['googleMeet']['enabled']);
112 } else {
113 $googleMeetSettings->setEnabled($globalSettings['googleCalendar']['enableGoogleMeet']);
114 }
115
116 if (isset($data['microsoftTeams']['enabled'])) {
117 $microsoftTeamsSettings->setEnabled($data['microsoftTeams']['enabled']);
118 } else {
119 $microsoftTeamsSettings->setEnabled($globalSettings['outlookCalendar']['enableMicrosoftTeams']);
120 }
121
122 $entitySettings->setGeneralSettings($generalSettings);
123 $entitySettings->setZoomSettings($zoomSettings);
124 $entitySettings->setLessonSpaceSettings($lessonSpaceSetings);
125 $entitySettings->setGoogleMeetSettings($googleMeetSettings);
126 $entitySettings->setMicrosoftTeamsSettings($microsoftTeamsSettings);
127
128 return $entitySettings;
129 }
130 }
131