feat: additional assignment agnostic teamer feedback by admins
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Autocomplete;
|
||||
|
||||
use App\Repository\TeamerRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class TeamerController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly TeamerRepository $teamerRepository)
|
||||
{}
|
||||
|
||||
#[Route('/admin/autocomplete/teamer', name: 'app_admin_autocomplete_teamer')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$query = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$queryString = $query['search'];
|
||||
} catch (\JsonException $e) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
$dates = $this->teamerRepository->getAutocompletionData($queryString);
|
||||
|
||||
return $this->json($dates);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Feedback;
|
||||
|
||||
use App\Entity\Feedback;
|
||||
use App\Entity\User;
|
||||
use App\Form\AdminFeedbackType;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class ProvideController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/feedback/provide', name: 'app_admin_feedback_provide')]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$form = $this->getFeedbackForm();
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$feedback = $form->getData();
|
||||
|
||||
$this->entityManager->persist($feedback);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->logger->info('Provided feedback', [
|
||||
'teamer' => $feedback->getTeamer()->getUuid(),
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_administrative_feedback_index');
|
||||
}
|
||||
|
||||
return $this->render('admin/feedback/provide.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/feedback/provide/form', name: 'app_admin_feedback_provide_form')]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function form(Request $request): Response
|
||||
{
|
||||
$form = $this->getFeedbackForm();
|
||||
$form->handleRequest($request);
|
||||
|
||||
return $this->renderBlock('admin/feedback/provide.html.twig', 'feedback_form', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function getFeedbackForm(): FormInterface
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$feedback = new Feedback($user);
|
||||
|
||||
return $this->createForm(AdminFeedbackType::class, $feedback);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class Feedback implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
private ?string $status = self::STATUS_NEW;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'feedback')]
|
||||
#[Assert\NotNull(message: 'Bitte auswählen', groups: ['admin'])]
|
||||
private ?Teamer $teamer = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
@@ -71,6 +72,10 @@ class Feedback implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $author;
|
||||
|
||||
// Transient property for form only
|
||||
#[Assert\NotNull(message: 'Bitte auswählen', groups: ['admin'])]
|
||||
private ?FeedbackSet $feedbackSet = null;
|
||||
|
||||
public function __construct(User $author)
|
||||
{
|
||||
$this->uuid = Uuid::v4();
|
||||
@@ -288,4 +293,16 @@ class Feedback implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFeedbackSet(): ?FeedbackSet
|
||||
{
|
||||
return $this->feedbackSet;
|
||||
}
|
||||
|
||||
public function setFeedbackSet(?FeedbackSet $feedbackSet): static
|
||||
{
|
||||
$this->feedbackSet = $feedbackSet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Feedback;
|
||||
use App\Entity\FeedbackSet;
|
||||
use App\Entity\Teamer;
|
||||
use App\Repository\FeedbackSetRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AdminFeedbackType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly FeedbackSetRepository $feedbackSetRepository)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('teamer', AutocompleteEntityType::class, [
|
||||
'label' => 'Teamer',
|
||||
'class' => Teamer::class,
|
||||
'label_property' => 'name',
|
||||
'label_function' => fn(Teamer $teamer) => (string) $teamer,
|
||||
'endpoint_route' => 'app_admin_autocomplete_teamer',
|
||||
])
|
||||
->add('feedbackSet', EntityType::class, [
|
||||
'label' => 'Feedbackvorlage',
|
||||
'class' => FeedbackSet::class,
|
||||
'choice_label' => 'name',
|
||||
'placeholder' => 'Bitte wählen...',
|
||||
])
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$data = $event->getData();
|
||||
$form = $event->getForm();
|
||||
|
||||
if (null === $feedbackSet = $data->getFeedbackSet()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addDynamicForm($feedbackSet, $form);
|
||||
})
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||
$data = $event->getData();
|
||||
$form = $event->getForm();
|
||||
|
||||
if (true === empty($data['feedbackSet'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$feedbackSet = $this->feedbackSetRepository->find($data['feedbackSet']);
|
||||
$this->addDynamicForm($feedbackSet, $form);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
private function addDynamicForm(FeedbackSet $feedbackSet, FormInterface $form): void
|
||||
{
|
||||
$form
|
||||
->add('ratings', FeedbackRatingsType::class, [
|
||||
'label' => false,
|
||||
'feedback_set' => $feedbackSet,
|
||||
])
|
||||
->add('comment', TextareaType::class, [
|
||||
'label' => 'Kommentar (öffentlich)',
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'rows' => 5,
|
||||
],
|
||||
'help' => 'Bitte formuliere deinen Kommentar so, dass er an das Team weitergegeben werden kann',
|
||||
])
|
||||
->add('commentInternal', TextareaType::class, [
|
||||
'label' => 'Kommentar (intern)',
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'rows' => 5,
|
||||
],
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => Feedback::class,
|
||||
'anti_xss' => true,
|
||||
'validation_groups' => [
|
||||
'Default',
|
||||
'admin',
|
||||
]
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\FeedbackSet;
|
||||
use App\Form\DataTransformer\FeedbackToRatingsTransformer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -20,6 +21,10 @@ class FeedbackRatingsType extends AbstractType
|
||||
'choices' => array_combine(range(5, 1), range(5,1)),
|
||||
]);
|
||||
}
|
||||
|
||||
// This is most probably more suitable for DatamapperInterface
|
||||
// but it works very well for the time being
|
||||
$builder->addModelTransformer(new FeedbackToRatingsTransformer($options['feedback_set']));
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Form;
|
||||
|
||||
use App\Entity\Feedback;
|
||||
use App\Entity\FeedbackSet;
|
||||
use App\Form\DataTransformer\FeedbackToRatingsTransformer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -35,13 +34,6 @@ class FeedbackType extends AbstractType
|
||||
],
|
||||
])
|
||||
;
|
||||
|
||||
// This is most probably more suitable for DatamapperInterface
|
||||
// but it works very well for the time being
|
||||
$builder
|
||||
->get('ratings')
|
||||
->addModelTransformer(new FeedbackToRatingsTransformer($options['feedback_set']))
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
||||
@@ -103,4 +103,37 @@ class TeamerRepository extends ServiceEntityRepository
|
||||
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
public function getAutocompletionData(string $search): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('teamer');
|
||||
|
||||
$teamers = $qb
|
||||
->where($qb->expr()->orX(
|
||||
$qb->expr()->like('teamer.lastName', ':search'),
|
||||
$qb->expr()->like('teamer.firstName', ':search'),
|
||||
))
|
||||
->orderBy('teamer.lastName', 'ASC')
|
||||
->addOrderBy('teamer.firstName', 'ASC')
|
||||
->setParameter('search', '%'.$this->escapeLikeWildcards($search).'%')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
$data = [
|
||||
[
|
||||
'value' => '',
|
||||
'text' => '...',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($teamers as $teamer) {
|
||||
$data[] = [
|
||||
'value' => $teamer->getId(),
|
||||
'text' => (string) $teamer,
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
{% extends 'admin/layout.html.twig' %}
|
||||
|
||||
{% block title %}Feedback abgeben{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1 class="text-2xl font-bold pb-4">
|
||||
Neues Feedback
|
||||
</h1>
|
||||
<div class="grid lg:grid-cols-2 gap-8">
|
||||
<div>
|
||||
{{ form_start(form) }}
|
||||
<div class="py-4">
|
||||
{{ form_row(form.teamer) }}
|
||||
</div>
|
||||
<div class="py-4">
|
||||
{{ form_row(form.feedbackSet, { 'attr': {
|
||||
'hx-post': path('app_admin_feedback_provide_form'),
|
||||
'hx-target': '#feedback-form',
|
||||
'hx-swap': 'innerHTML',
|
||||
} }) }}
|
||||
</div>
|
||||
<div id="feedback-form">
|
||||
{% block feedback_form %}
|
||||
{% if form.ratings is defined %}
|
||||
<div class="flex flex-col divide-y divide-gray-200">
|
||||
{% for child in form.ratings.children %}
|
||||
<div class="grid grid-cols-4 gap-x-4 items-start py-4">
|
||||
<h2 class="col-span-3 text-lg font-bold">
|
||||
{{ child.vars.label }}
|
||||
</h2>
|
||||
{{ form_widget(child) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="py-4">
|
||||
{{ form_row(form.comment) }}
|
||||
</div>
|
||||
<div class="py-4">
|
||||
{{ form_row(form.commentInternal) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
<button type="submit" class="btn">
|
||||
Speichern
|
||||
</button>
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
<div>
|
||||
<h2 class="text-lg font-bold pb-2">
|
||||
Bewertungsskala
|
||||
</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th class="whitespace-nowrap">
|
||||
5 Punkte
|
||||
</th>
|
||||
<td>
|
||||
Der/die Wochenteamer:in hat hervorragende Arbeit geleistet und ist beim Team und den Gästen
|
||||
sehr gut angekommen, es gibt nichts auszusetzen.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="whitespace-nowrap">
|
||||
4 Punkte
|
||||
</th>
|
||||
<td>
|
||||
Der/die Wochenteamer:in hat einen sehr guten Job geleistet. Wenn es etwas zu beanstanden oder
|
||||
Ideen zur Verbesserung gibt, dann sind es nur Kleinigkeiten (diese gerne in den Kommentar
|
||||
schreiben).
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="whitespace-nowrap">
|
||||
3 Punkte
|
||||
</th>
|
||||
<td>
|
||||
Der/die Wochenteamer:in hat einen ganz guten Job erledigt. Es gibt einige Dinge, die
|
||||
verbesserungswürdig sind (diese gerne in den Kommentaren vermerken). Der/die Wochenteamer:in
|
||||
ist aber nicht negativ aufgefallen.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="whitespace-nowrap">
|
||||
2 Punkte
|
||||
</th>
|
||||
<td>
|
||||
Der/die Wocheteamer:in hat keinen guten Job geleistet. Der Einsatz hat das Team eher belastet,
|
||||
als es zu unterstützen. Der/die Wochenteamer:in bekommt noch eine Chance sich zu beweisen
|
||||
(hierfür gerne ein schriftliches Feedback im Kommentarfeld hinterlassen).
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="whitespace-nowrap">
|
||||
1 Punkt
|
||||
</th>
|
||||
<td>
|
||||
Der/die Wochenteamer:in hat einen schlechten Job erledigt, ist Team und/oder Gästen negativ
|
||||
aufgefallen und soll keine weiteren Einsätze erhalten.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -77,4 +77,9 @@
|
||||
{{ knp_pagination_render(pagination) }}
|
||||
</div>
|
||||
</div>
|
||||
{% if is_granted('ROLE_ADMIN') %}
|
||||
<a href="{{ path('app_admin_feedback_provide') }}" class="btn" title="Feedback erfassen">
|
||||
Neu
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user