PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / Application / Services / Settings / SettingsService.php
ameliabooking / src / Application / Services / Settings Last commit date
SettingsService.php 2 years ago
SettingsService.php
163 lines
1 <?php
2 /**
3 * @copyright © TMS-Plugins. All rights reserved.
4 * @licence See LICENCE.md for license details.
5 */
6
7 namespace AmeliaBooking\Application\Services\Settings;
8
9 use AmeliaBooking\Domain\Entity\User\AbstractUser;
10 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
11 use AmeliaBooking\Infrastructure\Common\Container;
12 use AmeliaBooking\Infrastructure\Repository\User\UserRepository;
13
14 /**
15 * Class SettingsService
16 *
17 * @package AmeliaBooking\Application\Services\Settings
18 */
19 class SettingsService
20 {
21 /** @var Container */
22 private $container;
23
24 /**
25 * ProviderApplicationService constructor.
26 *
27 * @param Container $container
28 *
29 * @throws \InvalidArgumentException
30 */
31 public function __construct(Container $container)
32 {
33 $this->container = $container;
34 }
35
36 /**
37 * @return array
38 * @throws \Exception
39 * @throws \Interop\Container\Exception\ContainerException +
40 */
41 public function getGlobalDaysOff()
42 {
43 $daysOff = [];
44
45 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
46 $settingsDS = $this->container->get('domain.settings.service');
47
48 $settingsDaysOff = $settingsDS->getCategorySettings('daysOff');
49
50 foreach ($settingsDaysOff as $settingsDayOff) {
51 $dayOffPeriod = new \DatePeriod(
52 DateTimeService::getCustomDateTimeObject($settingsDayOff['startDate']),
53 new \DateInterval('P1D'),
54 DateTimeService::getCustomDateTimeObject($settingsDayOff['endDate'])->modify('+1 day')
55 );
56
57 /** @var \DateTime $dayOffDate */
58 foreach ($dayOffPeriod as $dayOffDate) {
59 if ($settingsDayOff['repeat']) {
60 $dayOffDateFormatted = $dayOffDate->format('m-d');
61 $daysOff[$dayOffDateFormatted] = $dayOffDateFormatted;
62 } else {
63 $dayOffDateFormatted = $dayOffDate->format('Y-m-d');
64 $daysOff[$dayOffDateFormatted] = $dayOffDateFormatted;
65 }
66 }
67 }
68
69 return $daysOff;
70 }
71
72
73 /**
74 * @param array $daysOffNew
75 *
76 * @return array
77 * @throws \Exception
78 * @throws \Interop\Container\Exception\ContainerException +
79 */
80 public function getDaysOff($daysOffNew = null)
81 {
82 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
83 $settingsDS = $this->container->get('domain.settings.service');
84
85 $daysOff = $daysOffNew ?: $settingsDS->getCategorySettings('daysOff');
86 $utcDaysOff = [];
87
88
89 foreach ($daysOff as &$dayOff) {
90 $dayOff['startDate'] = $dayOff['startDate'] . ' 00:00:00';
91 $dayOff['endDate'] = $dayOff['endDate'] . ' 23:59:59';
92 if ($settingsDS->getSetting('general', 'showClientTimeZone')) {
93 $utcDaysOff[] = [
94 'startDate' => DateTimeService::getCustomDateTimeObjectInUtc($dayOff['startDate'])->format('Y-m-d H:i:s'),
95 'endDate' => DateTimeService::getCustomDateTimeObjectInUtc($dayOff['endDate'])->format('Y-m-d H:i:s'),
96 'repeat' => $dayOff['repeat'],
97 'name' => $dayOff['name']
98 ];
99 }
100 }
101 return !empty($utcDaysOff) ? $utcDaysOff : $daysOff;
102 }
103
104 /**
105 * @return array
106 * @throws \Exception
107 * @throws \Interop\Container\Exception\ContainerException +
108 */
109 public function getBccEmails()
110 {
111 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
112 $settingsDS = $this->container->get('domain.settings.service');
113
114 $bccEmail = $settingsDS->getSetting('notifications', 'bccEmail');
115
116 return ($bccEmail !== '') ? explode(',', $bccEmail) : [];
117 }
118
119 /**
120 * @return array
121 * @throws \Exception
122 * @throws \Interop\Container\Exception\ContainerException +
123 */
124 public function getEmptyPackageEmployees()
125 {
126 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
127 $settingsDS = $this->container->get('domain.settings.service');
128
129 $emptyPackageEmployees = $settingsDS->getSetting('notifications', 'emptyPackageEmployees');
130
131 $employees = [];
132 if ($emptyPackageEmployees !== '') {
133 /** @var UserRepository $userRepository */
134 $userRepository = $this->container->get('domain.users.repository');
135
136 $employeeIds = explode(',', $emptyPackageEmployees);
137 foreach ($employeeIds as $employeeId) {
138 $user = $userRepository->getById((int)$employeeId);
139 if ($user instanceof AbstractUser) {
140 $employees[] = $user->toArray();
141 }
142 }
143 }
144
145 return $employees;
146 }
147
148 /**
149 * @return array
150 * @throws \Exception
151 * @throws \Interop\Container\Exception\ContainerException +
152 */
153 public function getBccSms()
154 {
155 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
156 $settingsDS = $this->container->get('domain.settings.service');
157
158 $bccSms = $settingsDS->getSetting('notifications', 'bccSms');
159
160 return ($bccSms !== '') ? explode(',', $bccSms) : [];
161 }
162 }
163