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