diff --git a/migrations/Version20240516075149.php b/migrations/Version20240516075149.php new file mode 100644 index 0000000..af5273e --- /dev/null +++ b/migrations/Version20240516075149.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE user ADD mute_notifications TINYINT(1) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE user DROP mute_notifications'); + } +} diff --git a/src/Controller/Administrative/ProfileController.php b/src/Controller/Administrative/ProfileController.php new file mode 100644 index 0000000..a499c87 --- /dev/null +++ b/src/Controller/Administrative/ProfileController.php @@ -0,0 +1,47 @@ +getUser(); + + $form = $this->createForm(UserProfileType::class, $user); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->flush(); + + $this->addFlash('success', 'Deine Daten wurden aktualisiert'); + $this->logger->info('Update user profile'); + + return $this->redirectToRoute($user->getDefaultRoute()); + } + + return $this->render('administrative/profile/index.html.twig', [ + 'user' => $user, + 'form' => $form->createView(), + ]); + } +} \ No newline at end of file diff --git a/src/Entity/User.php b/src/Entity/User.php index ad13988..6214a04 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -54,6 +54,9 @@ class User implements UserInterface, TimestampableEntityInterface #[ORM\Column(length: 32, nullable: true)] private ?string $hotelCode = null; + #[ORM\Column] + private bool $muteNotifications = false; + public function __construct() { $this->uuid = Uuid::v4(); @@ -264,4 +267,16 @@ class User implements UserInterface, TimestampableEntityInterface return $this; } + + public function isMuteNotifications(): bool + { + return $this->muteNotifications; + } + + public function setMuteNotifications(bool $muteNotifications): static + { + $this->muteNotifications = $muteNotifications; + + return $this; + } } diff --git a/src/EventListener/EmailNotificationSubscriber.php b/src/EventListener/EmailNotificationSubscriber.php index 1dded31..779aea6 100644 --- a/src/EventListener/EmailNotificationSubscriber.php +++ b/src/EventListener/EmailNotificationSubscriber.php @@ -68,6 +68,9 @@ class EmailNotificationSubscriber implements EventSubscriberInterface ; foreach ($managers as $manager) { + if (true === $manager->isMuteNotifications()) { + continue; + } $this->mailer->createAndSendEmail([ 'disposition' => $disposition, ], [ diff --git a/src/Form/UserProfileType.php b/src/Form/UserProfileType.php new file mode 100644 index 0000000..50997c1 --- /dev/null +++ b/src/Form/UserProfileType.php @@ -0,0 +1,27 @@ +add('muteNotifications', CheckboxType::class, [ + 'label' => 'keine E-Mail Benachrichtigungen erhalten', + 'required' => false, + ]); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => User::class, + ]); + } +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 4c651b9..34e2d70 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -21,6 +21,9 @@ class UserRepository extends ServiceEntityRepository parent::__construct($registry, User::class); } + /** + * @return User[] + */ public function getAdministrativeUsers(): array { $qb = $this->createQueryBuilder('u'); @@ -42,6 +45,11 @@ class UserRepository extends ServiceEntityRepository ; } + /** + * @param string $role + * @param string $hotelCode + * @return User[] + */ public function getUsersByRoleAndHotelCode(string $role, string $hotelCode): array { $hotelCodeBase = substr($hotelCode, 0, 3); diff --git a/src/Service/Cron/FeedbackReminderService.php b/src/Service/Cron/FeedbackReminderService.php index 3fc5782..7953fe2 100644 --- a/src/Service/Cron/FeedbackReminderService.php +++ b/src/Service/Cron/FeedbackReminderService.php @@ -62,6 +62,9 @@ class FeedbackReminderService } foreach ($hotelManagers as $manager) { + if (true === $manager->isMuteNotifications()) { + continue; + } $this->mailer->createAndSendEmail([ 'feedbacks' => $sortedFeedbacks[$manager->getHotelCode()], ], [ diff --git a/templates/administrative/profile/index.html.twig b/templates/administrative/profile/index.html.twig new file mode 100644 index 0000000..ae4e79c --- /dev/null +++ b/templates/administrative/profile/index.html.twig @@ -0,0 +1,26 @@ +{% extends 'administrative/layout.html.twig' %} + +{% block title %}Benutzerprofil {{ user }}{% endblock %} + +{% block content %} +
+ Meine Rolle(n): {{ user.rolesLabels|join(', ') }}
+
+ Mein Vertragspartner: {{ user.hotelCode | default('-') }}
+