PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 6 months ago
SettingsService.php
159 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\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 */
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 */
79 public function getDaysOff($daysOffNew = null)
80 {
81 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
82 $settingsDS = $this->container->get('domain.settings.service');
83
84 $daysOff = $daysOffNew ?: $settingsDS->getCategorySettings('daysOff');
85 $utcDaysOff = [];
86
87
88 foreach ($daysOff as &$dayOff) {
89 $dayOff['startDate'] = $dayOff['startDate'] . ' 00:00:00';
90 $dayOff['endDate'] = $dayOff['endDate'] . ' 23:59:59';
91 if ($settingsDS->getSetting('general', 'showClientTimeZone')) {
92 $utcDaysOff[] = [
93 'startDate' => DateTimeService::getCustomDateTimeObjectInUtc($dayOff['startDate'])->format('Y-m-d H:i:s'),
94 'endDate' => DateTimeService::getCustomDateTimeObjectInUtc($dayOff['endDate'])->format('Y-m-d H:i:s'),
95 'repeat' => $dayOff['repeat'],
96 'name' => $dayOff['name']
97 ];
98 }
99 }
100 return !empty($utcDaysOff) ? $utcDaysOff : $daysOff;
101 }
102
103 /**
104 * @return array
105 * @throws \Exception +
106 */
107 public function getBccEmails()
108 {
109 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
110 $settingsDS = $this->container->get('domain.settings.service');
111
112 $bccEmail = $settingsDS->getSetting('notifications', 'bccEmail');
113
114 return ($bccEmail !== '') ? explode(',', $bccEmail) : [];
115 }
116
117 /**
118 * @return array
119 * @throws \Exception +
120 */
121 public function getEmptyPackageEmployees()
122 {
123 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
124 $settingsDS = $this->container->get('domain.settings.service');
125
126 $emptyPackageEmployees = $settingsDS->getSetting('notifications', 'emptyPackageEmployees');
127
128 $employees = [];
129 if ($emptyPackageEmployees !== '') {
130 /** @var UserRepository $userRepository */
131 $userRepository = $this->container->get('domain.users.repository');
132
133 $employeeIds = explode(',', $emptyPackageEmployees);
134 foreach ($employeeIds as $employeeId) {
135 $user = $userRepository->getById((int)$employeeId);
136 if ($user instanceof AbstractUser) {
137 $employees[] = $user->toArray();
138 }
139 }
140 }
141
142 return $employees;
143 }
144
145 /**
146 * @return array
147 * @throws \Exception +
148 */
149 public function getBccSms()
150 {
151 /** @var \AmeliaBooking\Domain\Services\Settings\SettingsService $settingsDS */
152 $settingsDS = $this->container->get('domain.settings.service');
153
154 $bccSms = $settingsDS->getSetting('notifications', 'bccSms');
155
156 return ($bccSms !== '') ? explode(',', $bccSms) : [];
157 }
158 }
159