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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user