WIP: Implement profile editing

This commit is contained in:
Björn Fromme
2023-10-02 15:07:02 +02:00
parent 953aa9c8e0
commit d3a0021b7d
12 changed files with 311 additions and 47 deletions
@@ -10,6 +10,7 @@ use App\Model\AjaxModalResponseDto;
use App\Model\UploadSessionDto; use App\Model\UploadSessionDto;
use App\Service\Upload\UploadHandler; use App\Service\Upload\UploadHandler;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -20,7 +21,8 @@ class AddController extends AbstractController
{ {
public function __construct( public function __construct(
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
private readonly UploadHandler $uploadHandler private readonly UploadHandler $uploadHandler,
private readonly LoggerInterface $logger
) { ) {
} }
@@ -52,6 +54,11 @@ class AddController extends AbstractController
$this->entityManager->persist($license); $this->entityManager->persist($license);
$this->entityManager->flush(); $this->entityManager->flush();
$this->addFlash('success', 'Die Lizenz wurde hinzugefügt.');
$this->logger->info('Add license', [
'user' => $user->getUserIdentifier(),
]);
$redirectUrl = $this->generateUrl('app_teamer_profile_skills'); $redirectUrl = $this->generateUrl('app_teamer_profile_skills');
$response->setCloseAndRedirect($redirectUrl); $response->setCloseAndRedirect($redirectUrl);
} else { } else {
@@ -0,0 +1,35 @@
<?php
namespace App\Controller\Teamer\Profile\License;
use App\Entity\License;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class DeleteController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('//teamer/profile/license/delete/{uuid}', name: 'app_teamer_profile_license_delete')]
#[IsGranted('DELETE', subject: 'license')]
public function index(License $license): Response
{
$this->entityManager->remove($license);
$this->entityManager->flush();
$this->addFlash('success', 'Die Lizenz wurde gelöscht.');
$this->logger->info('Delete license', [
'user' => $this->getUser()->getUserIdentifier(),
]);
return $this->redirectToRoute('app_teamer_profile_skills');
}
}
@@ -3,6 +3,10 @@
namespace App\Controller\Teamer\Profile; namespace App\Controller\Teamer\Profile;
use App\Entity\User; use App\Entity\User;
use App\Form\TeamerJobProfileType;
use App\Repository\JobProfileRepository;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -11,6 +15,13 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
class SkillsController extends AbstractController class SkillsController extends AbstractController
{ {
public function __construct(
private readonly JobProfileRepository $jobProfileRepository,
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/teamer/profile/skills', name: 'app_teamer_profile_skills')] #[Route('/teamer/profile/skills', name: 'app_teamer_profile_skills')]
#[IsGranted('ROLE_TEAMER')] #[IsGranted('ROLE_TEAMER')]
public function index(Request $request): Response public function index(Request $request): Response
@@ -19,8 +30,38 @@ class SkillsController extends AbstractController
$user = $this->getUser(); $user = $this->getUser();
$teamer = $user->getTeamer(); $teamer = $user->getTeamer();
$jobProfiles = $this->jobProfileRepository->getList();
$selectableJobProfiles = [];
foreach ($jobProfiles as $profile) {
$selectableJobProfiles[$profile->getId()] = true;
if (null !== $profile->getRequiredTraining() && false === $teamer->hasTraining($profile->getRequiredTraining())) {
$selectableJobProfiles[$profile->getId()] = false;
}
foreach ($profile->getRequiredLicenses() as $license) {
if (false === $teamer->hasLicenseOfType($license)) {
$selectableJobProfiles[$profile->getId()] = false;
}
}
}
$form = $this->createForm(TeamerJobProfileType::class, $teamer, ['job_profiles' => $jobProfiles, 'selectable_job_profiles' => $selectableJobProfiles]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->flush();
$this->addFlash('success', 'Dein Profil wurde aktualisiert.');
$this->logger->info('Update teamer profile', [
'user' => $user->getUserIdentifier(),
]);
return $this->redirectToRoute('app_teamer_profile_skills');
}
return $this->render('teamer/profile/skills.html.twig', [ return $this->render('teamer/profile/skills.html.twig', [
'teamer' => $teamer, 'teamer' => $teamer,
'form' => $form,
]); ]);
} }
} }
+12 -1
View File
@@ -86,7 +86,7 @@ class Teamer implements TimestampableEntityInterface
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Availability::class)] #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Availability::class)]
private Collection $availabilities; private Collection $availabilities;
#[ORM\OneToOne(cascade: ['persist', 'remove'])] #[ORM\OneToOne(cascade: ['persist', 'remove'], fetch: 'EAGER')]
#[Assert\NotNull(message: 'Bitte lade ein Foto von dir hoch', groups: ['profile', 'profile_preflight'])] #[Assert\NotNull(message: 'Bitte lade ein Foto von dir hoch', groups: ['profile', 'profile_preflight'])]
private ?Upload $photo = null; private ?Upload $photo = null;
@@ -465,6 +465,17 @@ class Teamer implements TimestampableEntityInterface
return $this; return $this;
} }
public function hasTraining(Training $training): bool
{
foreach ($this->getTrainingAttendances() as $attendance) {
if ($attendance->getTraining() === $training) {
return true;
}
}
return false;
}
/** /**
* @return Collection<int, License> * @return Collection<int, License>
*/ */
+78
View File
@@ -0,0 +1,78 @@
<?php
namespace App\Form;
use App\Entity\JobProfile;
use App\Entity\Teamer;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Translation\TranslatableMessage;
class TeamerJobProfileType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$selectableProfiles = $options['selectable_job_profiles'];
$builder
->add('jobProfiles', EntityType::class, [
'label' => false,
'class' => JobProfile::class,
// Append potential training or license requirements to profile labels
'choice_label' => function($choice, string $key, mixed $value): TranslatableMessage|string {
$label = $choice->getName();
$requirements = [];
if (null !== $training = $choice->getRequiredTraining()) {
$requirements[].= $training->getName();
}
foreach ($choice->getRequiredLicenses() as $license) {
$requirements[] = sprintf('Offizielle %slehrer*innenlizenz', ucfirst($license));
}
if ($requirements) {
$label .= sprintf(' (%s: %s)', 1 === count($requirements) ?
'Voraussetzung' : 'Voraussetzungen', implode(', ', $requirements));
}
return $label;
},
// Set disabled attribute on profiles that require a training or licenses the teamer doesnt have
'choice_attr' => function($choice, string $key, mixed $value) use ($selectableProfiles) {
if (true === $selectableProfiles[$choice->getId()]) {
return [];
}
return ['disabled' => 'disabled'];
},
'expanded' => true,
'multiple' => true,
])
->add('status', ChoiceType::class, [
'label' => 'Status',
'choices' => [
'Neuteamer' => Teamer::STATUS_NEW,
'Bestandsteamer' => Teamer::STATUS_EXISTING,
],
])
->add('remarks', TextareaType::class, [
'label' => 'Wünsche/Anmerkungen',
'required' => false,
'attr' => [
'rows' => 3,
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Teamer::class,
'job_profiles' => [],
'selectable_job_profiles' => [],
]);
}
}
-14
View File
@@ -63,13 +63,6 @@ class TeamerProfileType extends AbstractType
'label' => 'Krankenversicherung', 'label' => 'Krankenversicherung',
'required' => false, 'required' => false,
]) ])
->add('remarks', TextareaType::class, [
'label' => 'Wünsche/Anmerkungen',
'required' => false,
'attr' => [
'rows' => 3,
],
])
->add('address', AddressType::class, [ ->add('address', AddressType::class, [
'label' => false, 'label' => false,
]) ])
@@ -99,13 +92,6 @@ class TeamerProfileType extends AbstractType
'XXL' => 'XXL', 'XXL' => 'XXL',
], ],
]) ])
->add('status', ChoiceType::class, [
'label' => 'Status',
'choices' => [
'Neuteamer' => Teamer::STATUS_NEW,
'Bestandsteamer' => Teamer::STATUS_EXISTING,
],
])
; ;
} }
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Security\Voter;
use App\Entity\License;
use App\Entity\User;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class LicenseVoter extends Voter
{
public const VIEW = 'VIEW';
public const DELETE = 'DELETE';
public function __construct(private readonly Security $security)
{}
protected function supports(string $attribute, mixed $subject): bool
{
if (!$subject instanceof License) {
return false;
}
return in_array($attribute, [static::VIEW, static::DELETE]);
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
if (true === $this->security->isGranted('ROLE_ADMINISTRATIVE')) {
return true;
}
/** @var License $license */
$license = $subject;
/** @var User $user */
$user = $this->security->getUser();
return $license->getTeamer() === $user->getTeamer();
}
}
+2 -2
View File
@@ -3,8 +3,8 @@
{{ stimulus_controller('ajax-modal') }} {{ stimulus_controller('ajax-modal') }}
> >
<div class="absolute inset-0 w-full h-full bg-black/80" {{ stimulus_action('ajax-modal', 'hide', 'click') }}></div> <div class="absolute inset-0 w-full h-full bg-black/80" {{ stimulus_action('ajax-modal', 'hide', 'click') }}></div>
<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 px-4 shadow w-full max-w-xl"> <div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 px-4 w-full max-w-xl">
<div class="bg-white p-8"> <div class="bg-white p-8 rounded-md">
<div class="flex justify-between pb-4"> <div class="flex justify-between pb-4">
<div class="text-2xl font-bold" {{ stimulus_target('ajax-modal', 'title') }}></div> <div class="text-2xl font-bold" {{ stimulus_target('ajax-modal', 'title') }}></div>
<button type="button" <button type="button"
@@ -3,7 +3,7 @@
{{ stimulus_controller('confirmation-modal') }} {{ stimulus_controller('confirmation-modal') }}
> >
<div class="absolute top-0 left-0 inset-0 bg-black/80" {{ stimulus_action('confirmation-modal', 'hide', 'click') }}></div> <div class="absolute top-0 left-0 inset-0 bg-black/80" {{ stimulus_action('confirmation-modal', 'hide', 'click') }}></div>
<div class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white p-8 shadow w-full max-w-3xl rounded"> <div class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white p-8 w-full max-w-3xl rounded-md">
<div class="flex justify-between border-b border-gray-200 pb-2 mb-4"> <div class="flex justify-between border-b border-gray-200 pb-2 mb-4">
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">
{{ icon('alert', 'w-8 h-8') }} {{ icon('alert', 'w-8 h-8') }}
@@ -16,10 +16,10 @@
<form method="post" {{ stimulus_target('confirmation-modal', 'form') }}> <form method="post" {{ stimulus_target('confirmation-modal', 'form') }}>
<div {{ stimulus_target('confirmation-modal', 'content') }}></div> <div {{ stimulus_target('confirmation-modal', 'content') }}></div>
<div class="mt-6 flex items-center justify-between"> <div class="mt-6 flex items-center justify-between">
<button type="submit" class="btn"> <button type="submit" class="btn bg-red-500">
Ja Ja
</button> </button>
<button type="button" class="btn btn--secondary" {{ stimulus_action('confirmation-modal', 'hide') }}> <button type="button" class="btn" {{ stimulus_action('confirmation-modal', 'hide') }}>
Abbrechen Abbrechen
</button> </button>
</div> </div>
+14 -1
View File
@@ -67,6 +67,19 @@
{%- endif -%} {%- endif -%}
{%- endblock textarea_widget -%} {%- endblock textarea_widget -%}
{%- block checkbox_widget -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' h-4 w-4 rounded border-gray-300 text-primary')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' ring-red-500 focus:ring-red-500' }) -%}
{% else %}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' focus:ring-primary' }) -%}
{%- endif -%}
{%- if attr.disabled is defined and attr.disabled == true -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%}
{%- endif -%}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
{%- endblock checkbox_widget -%}
{%- block choice_widget_collapsed -%} {%- block choice_widget_collapsed -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6')|trim }) -%} {%- set attr = attr|merge({'class': (attr.class|default('') ~ ' block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6')|trim }) -%}
{%- if errors|length -%} {%- if errors|length -%}
@@ -99,7 +112,7 @@
</label> </label>
</div> </div>
<div class="ml-3 flex h-6 items-center"> <div class="ml-3 flex h-6 items-center">
<input id="{{ child.vars.id }}" name="{{ child.vars.full_name }}" type="checkbox" class="h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary"> {{- form_widget(child) -}}
</div> </div>
</div> </div>
{% endfor -%} {% endfor -%}
-2
View File
@@ -75,7 +75,6 @@
Persönliche Daten Persönliche Daten
</h2> </h2>
<div class="flex flex-col space-y-4"> <div class="flex flex-col space-y-4">
{{ form_row(form.status) }}
{{ form_row(form.salutation) }} {{ form_row(form.salutation) }}
{{ form_row(form.academicTitle) }} {{ form_row(form.academicTitle) }}
{{ form_row(form.firstName) }} {{ form_row(form.firstName) }}
@@ -127,7 +126,6 @@
{{ form_row(form.healthInsuranceCompany) }} {{ form_row(form.healthInsuranceCompany) }}
{{ form_row(form.language) }} {{ form_row(form.language) }}
{{ form_row(form.size) }} {{ form_row(form.size) }}
{{ form_row(form.remarks) }}
</div> </div>
<div {{ stimulus_controller('form-collection', { 'prototype': _self.collectionRow(form.pickups.vars.prototype)|json_encode }) }}> <div {{ stimulus_controller('form-collection', { 'prototype': _self.collectionRow(form.pickups.vars.prototype)|json_encode }) }}>
+77 -23
View File
@@ -4,32 +4,86 @@
{% block content %} {% block content %}
<h2 class="text-xl font-bold pb-2"> <h2 class="text-xl font-bold pb-2">
Lizenzen Ausbildung
</h2> </h2>
<div class="flex flex-col space-x-4 pb-8"> <ul class="list-disc pl-4 pb-8">
{% for license in teamer.licenses %} {% for attendance in teamer.trainingAttendances %}
<div class="flex items-center space-x-2"> <li>
{{ icon(license.type, 'w-5 h-5') }} {{ attendance.training.name }} {{ attendance.date|date('m/Y') }}
<span>{{ license.date|date('m.Y') }}</span> </li>
{% if is_granted('DOWNLOAD', license.certificate) %}
<a href="{{ path('app_common_download', { 'uuid': license.certificate.uuid }) }}" target="_blank">
{{ icon('download', 'w-4 h-4') }}
</a>
{% endif %}
</div>
{% else %} {% else %}
<div class="text-sm pb-8"> <li class="text-sm">
Du hast bisher keine Lizenzen hinterlegt Du hast bisher an keinen Fortbildungen teilgenommen
</div> </li>
{% endfor %} {% endfor %}
</ul>
<div class="pb-8">
<h2 class="text-xl font-bold pb-2">
Lizenzen
</h2>
<ul class="list-disc pl-4 pb-8">
{% for license in teamer.licenses %}
<li>
<div class="flex items-center space-x-4">
{{ icon(license.type, 'w-5 h-5') }}
<span>{{ license.date|date('m/Y') }}</span>
{% if is_granted('DOWNLOAD', license.certificate) %}
<a href="{{ path('app_common_download', { 'uuid': license.certificate.uuid }) }}" target="_blank">
{{ icon('download', 'w-4 h-4') }}
</a>
{% endif %}
{% if is_granted('DELETE', license) %}
<button type="button"
class="text-red-500"
{{ stimulus_controller('modal-button', [], [], {'confirmation-modal': '#confirmation-modal'}) }}
{{ stimulus_action('modal-button', 'confirmation', null, {
'title': 'Bist du sicher?',
'content': 'Möchtest du die Lizenz wirklich löschen?',
'target-url': path('app_teamer_profile_license_delete', { 'uuid': license.uuid })
}) }}>
{{ icon('delete') }}
</button>
{% endif %}
</div>
</li>
{% else %}
<div class="text-sm">
Du hast bisher keine Lizenzen hinterlegt
</div>
{% endfor %}
</ul>
<button type="button"
class="btn"
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
{{ stimulus_action('modal-button', 'ajax', null, {
'title': 'Lizenz hinzufügen',
'url': path('app_teamer_profile_license_add')
}) }}>
Lizenz hinzufügen
</button>
</div> </div>
<button type="button"
class="btn" {{ form_start(form) }}
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
{{ stimulus_action('modal-button', 'ajax', null, { <h2 class="text-xl font-bold pb-2">
'title': 'Lizenz hinzufügen', Mögliche Jobprofile
'url': path('app_teamer_profile_license_add') </h2>
}) }}> <div class="pb-8">
Lizenz hinzufügen {{ form_row(form.jobProfiles) }}
</div>
<h2 class="text-xl font-bold pb-2">
Sonstiges
</h2>
<div class="flex flex-col space-y-4 pb-8">
{{ form_row(form.status) }}
{{ form_row(form.remarks) }}
</div>
<button type="submit" class="btn">
Aktualisieren
</button> </button>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %} {% endblock %}