feat: profile page for administrative users and muting of notifications
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\UserProfileType;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class ProfileController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/profile', name: 'app_administrative_profile_index')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,9 @@ class EmailNotificationSubscriber implements EventSubscriberInterface
|
||||
;
|
||||
|
||||
foreach ($managers as $manager) {
|
||||
if (true === $manager->isMuteNotifications()) {
|
||||
continue;
|
||||
}
|
||||
$this->mailer->createAndSendEmail([
|
||||
'disposition' => $disposition,
|
||||
], [
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\User;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class UserProfileType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->add('muteNotifications', CheckboxType::class, [
|
||||
'label' => 'keine E-Mail Benachrichtigungen erhalten',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => User::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -62,6 +62,9 @@ class FeedbackReminderService
|
||||
}
|
||||
|
||||
foreach ($hotelManagers as $manager) {
|
||||
if (true === $manager->isMuteNotifications()) {
|
||||
continue;
|
||||
}
|
||||
$this->mailer->createAndSendEmail([
|
||||
'feedbacks' => $sortedFeedbacks[$manager->getHotelCode()],
|
||||
], [
|
||||
|
||||
Reference in New Issue
Block a user