mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 14:36:13 +00:00
WIP add notification preferences table to user profile form
This commit is contained in:
parent
c9c565809a
commit
cf780b6e36
@ -11,14 +11,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Controller;
|
namespace Chill\MainBundle\Controller;
|
||||||
|
|
||||||
use Chill\MainBundle\Form\UserPhonenumberType;
|
use Chill\MainBundle\Form\UserProfileType;
|
||||||
use Chill\MainBundle\Security\ChillSecurity;
|
use Chill\MainBundle\Security\ChillSecurity;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
use Symfony\Component\Form\FormInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
@ -41,16 +39,15 @@ final class UserProfileController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->security->getUser();
|
$user = $this->security->getUser();
|
||||||
$editForm = $this->createPhonenumberEditForm($user);
|
$editForm = $this->createForm(UserProfileType::class, $user);
|
||||||
|
$editForm->add('submit', SubmitType::class);
|
||||||
$editForm->handleRequest($request);
|
$editForm->handleRequest($request);
|
||||||
|
|
||||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||||
$phonenumber = $editForm->get('phonenumber')->getData();
|
$em = $this->managerRegistry->getManager();
|
||||||
|
$em->persist($user);
|
||||||
$user->setPhonenumber($phonenumber);
|
$em->flush();
|
||||||
|
$this->addFlash('success', $this->translator->trans('user.profile.Profile successfully updated!'));
|
||||||
$this->managerRegistry->getManager()->flush();
|
|
||||||
$this->addFlash('success', $this->translator->trans('user.profile.Phonenumber successfully updated!'));
|
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_main_user_profile');
|
return $this->redirectToRoute('chill_main_user_profile');
|
||||||
}
|
}
|
||||||
@ -60,13 +57,4 @@ final class UserProfileController extends AbstractController
|
|||||||
'form' => $editForm->createView(),
|
'form' => $editForm->createView(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createPhonenumberEditForm(UserInterface $user): FormInterface
|
|
||||||
{
|
|
||||||
return $this->createForm(
|
|
||||||
UserPhonenumberType::class,
|
|
||||||
$user,
|
|
||||||
)
|
|
||||||
->add('submit', SubmitType::class, ['label' => $this->translator->trans('Save')]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -616,6 +616,17 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNotificationFlags(): array
|
||||||
|
{
|
||||||
|
return $this->notificationFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNotificationFlags(array $notificationFlags)
|
||||||
|
{
|
||||||
|
$this->notificationFlags = $notificationFlags;
|
||||||
|
}
|
||||||
|
|
||||||
public function getNotificationFlagData(string $flag): array
|
public function getNotificationFlagData(string $flag): array
|
||||||
{
|
{
|
||||||
return $this->notificationFlags[$flag] ?? [];
|
return $this->notificationFlags[$flag] ?? [];
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Form\Type;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Form\DataMapper\NotificationFlagDataMapper;
|
||||||
|
use Chill\MainBundle\Form\DataMapper\NotificationPreferenceDataMapper;
|
||||||
|
use Chill\MainBundle\Notification\NotificationFlagManager;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Form\DataMapperInterface;
|
||||||
|
|
||||||
|
class NotificationFlagsType extends AbstractType
|
||||||
|
{
|
||||||
|
private array $notificationFlagProviders;
|
||||||
|
|
||||||
|
public function __construct(NotificationFlagManager $notificationFlagManager)
|
||||||
|
{
|
||||||
|
$this->notificationFlagProviders = $notificationFlagManager->getAllNotificationFlagProviders();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
// $builder->setDataMapper(new NotificationFlagDataMapper($this->notificationFlagProviders));
|
||||||
|
|
||||||
|
foreach ($this->notificationFlagProviders as $flagProvider) {
|
||||||
|
$flag = $flagProvider->getFlag();
|
||||||
|
$builder->add($flag, FormType::class, [
|
||||||
|
'label' => $flagProvider->getLabel(),
|
||||||
|
'mapped' => false,
|
||||||
|
'required' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$builder->get($flag)
|
||||||
|
->add('immediate_email', CheckboxType::class, [
|
||||||
|
'label' => false,
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->add('daily_email', CheckboxType::class, [
|
||||||
|
'label' => false,
|
||||||
|
'required' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'empty_data' => [],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
41
src/Bundle/ChillMainBundle/Form/UserProfileType.php
Normal file
41
src/Bundle/ChillMainBundle/Form/UserProfileType.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Form;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Form\Type\ChillPhoneNumberType;
|
||||||
|
use Chill\MainBundle\Form\Type\NotificationFlagsType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
class UserProfileType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('phonenumber', ChillPhoneNumberType::class, [
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
|
->add('notificationFlags', NotificationFlagsType::class, [
|
||||||
|
'label' => false,
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => \Chill\MainBundle\Entity\User::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -21,9 +21,9 @@ final readonly class NotificationFlagManager
|
|||||||
private array $notificationFlagProviders;
|
private array $notificationFlagProviders;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
iterable $notificaitonFlagProviders,
|
iterable $notificationFlagProviders,
|
||||||
) {
|
) {
|
||||||
$this->notificationFlagProviders = iterator_to_array($notificaitonFlagProviders);
|
$this->notificationFlagProviders = iterator_to_array($notificationFlagProviders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllNotificationFlagProviders(): array
|
public function getAllNotificationFlagProviders(): array
|
||||||
|
@ -45,6 +45,32 @@
|
|||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
{{ form_row(form.phonenumber) }}
|
{{ form_row(form.phonenumber) }}
|
||||||
|
|
||||||
|
<h2 class="mb-4">{{ 'user.profile.notification_preferences'|trans }}</h2>
|
||||||
|
<table class="table table-bordered border-dark align-middle">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{{ 'notification.flags.type'|trans }}</th>
|
||||||
|
<th>{{ 'notification.flags.preferences.immediate_email'|trans }}</th>
|
||||||
|
<th>{{ 'notification.flags.preferences.daily_email'|trans }}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for flag in form.notificationFlags %}
|
||||||
|
<tr>
|
||||||
|
<td class="col-sm-6">
|
||||||
|
<label>{{ form_label(flag) }}</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ form_widget(flag.immediate_email) }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ form_widget(flag.daily_email) }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li>
|
<li>
|
||||||
{{ form_widget(form.submit, { 'attr': { 'class': 'btn btn-save' } } ) }}
|
{{ form_widget(form.submit, { 'attr': { 'class': 'btn btn-save' } } ) }}
|
||||||
|
@ -139,6 +139,11 @@ services:
|
|||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
|
|
||||||
|
Chill\MainBundle\Form\DataMapper\NotificationFlagDataMapper:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
|
||||||
|
Chill\MainBundle\Form\UserProfileType: ~
|
||||||
Chill\MainBundle\Form\AbsenceType: ~
|
Chill\MainBundle\Form\AbsenceType: ~
|
||||||
Chill\MainBundle\Form\DataMapper\RegroupmentDataMapper: ~
|
Chill\MainBundle\Form\DataMapper\RegroupmentDataMapper: ~
|
||||||
Chill\MainBundle\Form\RegroupmentType: ~
|
Chill\MainBundle\Form\RegroupmentType: ~
|
||||||
|
@ -51,9 +51,10 @@ Label: Nom
|
|||||||
user:
|
user:
|
||||||
profile:
|
profile:
|
||||||
title: Mon profil
|
title: Mon profil
|
||||||
Phonenumber successfully updated!: Numéro de téléphone mis à jour!
|
Profile successfully updated!: Votre profil a été mis à jour!
|
||||||
no job: Pas de métier assigné
|
no job: Pas de métier assigné
|
||||||
no scope: Pas de cercle assigné
|
no scope: Pas de cercle assigné
|
||||||
|
notification_preferences: Préférences pour mes notifications
|
||||||
|
|
||||||
user_group:
|
user_group:
|
||||||
inactive: Inactif
|
inactive: Inactif
|
||||||
@ -715,6 +716,21 @@ notification:
|
|||||||
mark_as_read: Marquer comme lu
|
mark_as_read: Marquer comme lu
|
||||||
mark_as_unread: Marquer comme non-lu
|
mark_as_unread: Marquer comme non-lu
|
||||||
|
|
||||||
|
flags:
|
||||||
|
type: Type de notification
|
||||||
|
referrer-acc-course: Notification lors de la désignation comme référent
|
||||||
|
acc-course-work-eval: Notification sur un document d'évaluation
|
||||||
|
acc-course-work: Notification sur un action d'accompagnement
|
||||||
|
activity: Notification sur un échange
|
||||||
|
acc-course: Notification sur un parcours d'accompagnement
|
||||||
|
person-address-move: Notification lors que l'usager qui localise un parcours a déménagé
|
||||||
|
person: Notification sur un usager
|
||||||
|
workflow-trans: Notification sur une transition d'un workflow
|
||||||
|
preferences:
|
||||||
|
immediate_email: Recevoir un email immédiatement
|
||||||
|
daily_email: Recevoir un récapitulatif quotidien
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export:
|
export:
|
||||||
address_helper:
|
address_helper:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user