feat: profile page for administrative users and muting of notifications
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240516075149 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
@@ -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()],
|
||||
], [
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{% extends 'administrative/layout.html.twig' %}
|
||||
|
||||
{% block title %}Benutzerprofil {{ user }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1 class="text-2xl font-bold pb-8">
|
||||
Benutzerprofil und -einstellungen
|
||||
</h1>
|
||||
<p class="pb-8">
|
||||
Meine Rolle(n): {{ user.rolesLabels|join(', ') }}
|
||||
<br>
|
||||
Mein Vertragspartner: {{ user.hotelCode | default('-') }}
|
||||
</p>
|
||||
<h2 class="text-lg font-bold pb-2">
|
||||
Einstellungen
|
||||
</h2>
|
||||
{{ form_start(form) }}
|
||||
<div class="flex flex-col space-y-4 pb-4">
|
||||
{{ form_row(form.muteNotifications) }}
|
||||
</div>
|
||||
<button type="submit" class="btn">
|
||||
speichern
|
||||
</button>
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
{% endblock %}
|
||||
@@ -14,6 +14,10 @@
|
||||
class="h-8 w-auto rounded-full"
|
||||
alt="{{ app.user.teamer.firstName }}">
|
||||
</a>
|
||||
{% elseif is_granted('ROLE_ADMINISTRATIVE') %}
|
||||
<a href="{{ path('app_administrative_profile_index') }}" title="Mein Profil">
|
||||
{{ icon('user', 'w-8 h-8') }}
|
||||
</a>
|
||||
{% endif %}
|
||||
<button type="button"
|
||||
class="lg:hidden"
|
||||
|
||||
Reference in New Issue
Block a user