feat: override feedback author
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin\Autocomplete;
|
||||||
|
|
||||||
|
use App\Repository\UserRepository;
|
||||||
|
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 UserController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(private readonly UserRepository $userRepository)
|
||||||
|
{}
|
||||||
|
|
||||||
|
#[Route('/admin/autocomplete/user', name: 'app_admin_autocomplete_user')]
|
||||||
|
#[IsGranted('ROLE_ADMIN')]
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
$role = $request->query->get('role');
|
||||||
|
|
||||||
|
$users = $this->userRepository->getAutocompletionData($queryString, $role);
|
||||||
|
|
||||||
|
return $this->json($users);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,21 +4,22 @@ namespace App\Controller\Admin\Feedback;
|
|||||||
|
|
||||||
use App\Entity\Feedback;
|
use App\Entity\Feedback;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
use App\Event\FeedbackProvidedEvent;
|
||||||
use App\Form\AdminFeedbackType;
|
use App\Form\AdminFeedbackType;
|
||||||
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\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
class ProvideController extends AbstractController
|
class ProvideController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly EntityManagerInterface $entityManager,
|
private readonly EntityManagerInterface $entityManager,
|
||||||
private readonly LoggerInterface $logger
|
private readonly EventDispatcherInterface $eventDispatcher
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,12 +33,17 @@ class ProvideController extends AbstractController
|
|||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$feedback = $form->getData();
|
$feedback = $form->getData();
|
||||||
|
|
||||||
|
if (null !== $form->get('authorOverride')->getData()) {
|
||||||
|
$feedback->setAuthor($form->get('authorOverride')->getData());
|
||||||
|
}
|
||||||
|
|
||||||
$this->entityManager->persist($feedback);
|
$this->entityManager->persist($feedback);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$this->logger->info('Provided feedback', [
|
$this->eventDispatcher->dispatch(
|
||||||
'teamer' => $feedback->getTeamer()->getUuid(),
|
new FeedbackProvidedEvent($feedback),
|
||||||
]);
|
FeedbackProvidedEvent::NAME
|
||||||
|
);
|
||||||
|
|
||||||
return $this->redirectToRoute('app_administrative_feedback_index');
|
return $this->redirectToRoute('app_administrative_feedback_index');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Form;
|
namespace App\Form;
|
||||||
|
|
||||||
use App\Entity\Destination;
|
|
||||||
use App\Entity\Feedback;
|
use App\Entity\Feedback;
|
||||||
use App\Entity\FeedbackSet;
|
use App\Entity\FeedbackSet;
|
||||||
use App\Entity\Teamer;
|
use App\Entity\Teamer;
|
||||||
|
use App\Entity\User;
|
||||||
use App\Repository\FeedbackSetRepository;
|
use App\Repository\FeedbackSetRepository;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
@@ -32,6 +32,17 @@ class AdminFeedbackType extends AbstractType
|
|||||||
'label_function' => fn(Teamer $teamer) => (string) $teamer,
|
'label_function' => fn(Teamer $teamer) => (string) $teamer,
|
||||||
'endpoint_route' => 'app_admin_autocomplete_teamer',
|
'endpoint_route' => 'app_admin_autocomplete_teamer',
|
||||||
])
|
])
|
||||||
|
->add('authorOverride', AutocompleteEntityType::class, [
|
||||||
|
'mapped' => false,
|
||||||
|
'label' => 'abweichender Absender',
|
||||||
|
'class' => User::class,
|
||||||
|
'label_property' => 'lastName',
|
||||||
|
'label_function' => fn(User $user) => (string) $user,
|
||||||
|
'endpoint_route' => 'app_admin_autocomplete_user',
|
||||||
|
'endpoint_parameters' => [
|
||||||
|
'role' => 'ROLE_HOUSE_MANAGER',
|
||||||
|
],
|
||||||
|
])
|
||||||
->add('feedbackSet', EntityType::class, [
|
->add('feedbackSet', EntityType::class, [
|
||||||
'label' => 'Feedbackvorlage',
|
'label' => 'Feedbackvorlage',
|
||||||
'class' => FeedbackSet::class,
|
'class' => FeedbackSet::class,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
use App\Repository\Traits\QueryHelperTrait;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
@@ -16,6 +17,8 @@ use Doctrine\Persistence\ManagerRegistry;
|
|||||||
*/
|
*/
|
||||||
class UserRepository extends ServiceEntityRepository
|
class UserRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
|
use QueryHelperTrait;
|
||||||
|
|
||||||
public function __construct(ManagerRegistry $registry)
|
public function __construct(ManagerRegistry $registry)
|
||||||
{
|
{
|
||||||
parent::__construct($registry, User::class);
|
parent::__construct($registry, User::class);
|
||||||
@@ -67,4 +70,41 @@ class UserRepository extends ServiceEntityRepository
|
|||||||
->getResult()
|
->getResult()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAutocompletionData(string $search, string $role): array
|
||||||
|
{
|
||||||
|
$qb = $this->createQueryBuilder('user');
|
||||||
|
|
||||||
|
$users = $qb
|
||||||
|
->where($qb->expr()->andX(
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->like('user.lastName', ':search'),
|
||||||
|
$qb->expr()->like('user.firstName', ':search'),
|
||||||
|
)),
|
||||||
|
$qb->expr()->like('user.roles', ':role')
|
||||||
|
)
|
||||||
|
->orderBy('user.lastName', 'ASC')
|
||||||
|
->addOrderBy('user.firstName', 'ASC')
|
||||||
|
->setParameter('search', '%'.$this->escapeLikeWildcards($search).'%')
|
||||||
|
->setParameter('role', '%"'.$this->escapeLikeWildcards($role).'"%')
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
[
|
||||||
|
'value' => '',
|
||||||
|
'text' => '...',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$data[] = [
|
||||||
|
'value' => $user->getId(),
|
||||||
|
'text' => (string) $user,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
<div class="py-4">
|
<div class="py-4">
|
||||||
{{ form_row(form.teamer) }}
|
{{ form_row(form.teamer) }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="py-4">
|
||||||
|
{{ form_row(form.authorOverride) }}
|
||||||
|
</div>
|
||||||
<div class="py-4">
|
<div class="py-4">
|
||||||
{{ form_row(form.feedbackSet, { 'attr': {
|
{{ form_row(form.feedbackSet, { 'attr': {
|
||||||
'hx-post': path('app_admin_feedback_provide_form'),
|
'hx-post': path('app_admin_feedback_provide_form'),
|
||||||
|
|||||||
@@ -5,10 +5,14 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="flex flex-col space-y-4">
|
<div class="flex flex-col space-y-4">
|
||||||
<div class="text-lg">
|
<div class="text-lg">
|
||||||
|
{% if feedback.destinationName %}
|
||||||
Einsatz: {{ feedback.destinationName }}
|
Einsatz: {{ feedback.destinationName }}
|
||||||
<br>
|
<br>
|
||||||
|
{% endif %}
|
||||||
|
{% if feedback.assignmentDateFrom and feedback.assignmentDateTo %}
|
||||||
Einsatzzeitraum: {{ feedback.assignmentDateFrom|date('d.m.Y') }} - {{ feedback.assignmentDateTo|date('d.m.Y') }}
|
Einsatzzeitraum: {{ feedback.assignmentDateFrom|date('d.m.Y') }} - {{ feedback.assignmentDateTo|date('d.m.Y') }}
|
||||||
<br>
|
<br>
|
||||||
|
{% endif %}
|
||||||
Feedback von: {{ feedback.author }}
|
Feedback von: {{ feedback.author }}
|
||||||
</div>
|
</div>
|
||||||
<table>
|
<table>
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
{% for feedback in recentFeedback %}
|
{% for feedback in recentFeedback %}
|
||||||
<li class="py-2 first:pt-0 last:pb-0">
|
<li class="py-2 first:pt-0 last:pb-0">
|
||||||
<button type="button"
|
<button type="button"
|
||||||
title="Feedback {{ feedback.destinationName ~ ' ' ~ feedback.assignmentDate|date('m.Y') }}"
|
title="Feedback ansehen"
|
||||||
hx-get="{{ path('app_teamer_feedback', { 'uuid': feedback.uuid }) }}"
|
hx-get="{{ path('app_teamer_feedback', { 'uuid': feedback.uuid }) }}"
|
||||||
hx-target="body"
|
hx-target="body"
|
||||||
hx-swap="beforeend">
|
hx-swap="beforeend">
|
||||||
|
|||||||
Reference in New Issue
Block a user