feat: filter for feedbacks, code cleanup
This commit is contained in:
1 parent
49faa1eb25
commit
a8ccdc8775
11 files changed
+297
-27
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Controller\Administrative\Feedback;
|
||||
|
||||
use App\Repository\FeedbackRepository;
|
||||
use App\Service\Common\FeedbackFilterHandler;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -13,6 +14,7 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly FeedbackFilterHandler $filterHandler,
|
||||
private readonly FeedbackRepository $feedbackRepository,
|
||||
private readonly PaginatorInterface $paginator
|
||||
) {
|
||||
@@ -22,9 +24,11 @@ class IndexController extends AbstractController
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$filterDto = $this->filterHandler->getFilterSettings();
|
||||
|
||||
$query = $this
|
||||
->feedbackRepository
|
||||
->getListQuery()
|
||||
->getListQuery($filterDto)
|
||||
;
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
@@ -39,6 +43,7 @@ class IndexController extends AbstractController
|
||||
|
||||
return $this->render('administrative/feedback/index.html.twig', [
|
||||
'pagination' => $pagination,
|
||||
'filterDto' => $filterDto,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Controller\Common;
|
||||
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Form\AssignmentFilterType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Repository\AssignmentRepository;
|
||||
@@ -15,8 +14,6 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class AssignmentFilterController extends AbstractController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly AssignmentFilterHandler $filterHandler,
|
||||
private readonly AssignmentRepository $assignmentRepository
|
||||
@@ -40,7 +37,7 @@ class AssignmentFilterController extends AbstractController
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->filterHandler->handleRequest($form);
|
||||
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_index');
|
||||
$returnUrl = $this->generateUrl('app_administrative_assignment_index');
|
||||
|
||||
return new HxRedirectResponse($returnUrl);
|
||||
}
|
||||
@@ -55,7 +52,7 @@ class AssignmentFilterController extends AbstractController
|
||||
public function reset(Request $request): Response
|
||||
{
|
||||
$this->filterHandler->resetFilterSettings();
|
||||
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_index');
|
||||
$returnUrl = $this->generateUrl('app_administrative_assignment_index');
|
||||
|
||||
return $this->redirect($returnUrl);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Controller\Common;
|
||||
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Form\DocumentFilterType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Service\Common\DocumentFilterHandler;
|
||||
@@ -14,11 +13,8 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DocumentFilterController extends AbstractController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly DocumentFilterHandler $filterHandler
|
||||
) {
|
||||
public function __construct(private readonly DocumentFilterHandler $filterHandler)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/common/document/filter', name: 'app_common_document_filter')]
|
||||
@@ -32,7 +28,7 @@ class DocumentFilterController extends AbstractController
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->filterHandler->handleRequest($form);
|
||||
$returnUrl = $this->getReturnUrl($request, 'app_administrative_document_index');
|
||||
$returnUrl = $this->generateUrl('app_administrative_document_index');
|
||||
|
||||
return new HxRedirectResponse($returnUrl);
|
||||
}
|
||||
@@ -47,7 +43,7 @@ class DocumentFilterController extends AbstractController
|
||||
public function reset(Request $request): Response
|
||||
{
|
||||
$this->filterHandler->resetFilterSettings();
|
||||
$returnUrl = $this->getReturnUrl($request, 'app_administrative_document_index');
|
||||
$returnUrl = $this->generateUrl('app_administrative_document_index');
|
||||
|
||||
return $this->redirect($returnUrl);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Common;
|
||||
|
||||
use App\Form\FeedbackFilterType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Service\Common\FeedbackFilterHandler;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class FeedbackFilterController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly FeedbackFilterHandler $filterHandler)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/common/feedback/filter', name: 'app_common_feedback_filter')]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$formData = $this->filterHandler->getFilterSettings();
|
||||
$form = $this->createForm(FeedbackFilterType::class, $formData);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->filterHandler->handleRequest($form);
|
||||
$returnUrl = $this->generateUrl('app_administrative_feedback_index');
|
||||
|
||||
return new HxRedirectResponse($returnUrl);
|
||||
}
|
||||
|
||||
return $this->render('common/modal_feedback_filter.html.twig', [
|
||||
'filterForm' => $form->createView(),
|
||||
'filterDto' => $form->getData(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/common/feedback/filter/reset', name: 'app_common_feedback_filter_reset')]
|
||||
public function reset(Request $request): Response
|
||||
{
|
||||
$this->filterHandler->resetFilterSettings();
|
||||
$returnUrl = $this->generateUrl('app_administrative_feedback_index');
|
||||
|
||||
return $this->redirect($returnUrl);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Controller\Common;
|
||||
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Form\TeamerFilterType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Repository\TeamerRepository;
|
||||
use App\Service\Common\TeamerFilterHandler;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -15,12 +13,8 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class TeamerFilterController extends AbstractController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly TeamerFilterHandler $filterHandler,
|
||||
private readonly TeamerRepository $teamerRepository
|
||||
) {
|
||||
public function __construct(private readonly TeamerFilterHandler $filterHandler)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/common/teamer/filter', name: 'app_common_teamer_filter')]
|
||||
@@ -33,7 +27,7 @@ class TeamerFilterController extends AbstractController
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->filterHandler->handleRequest($form);
|
||||
$returnUrl = $this->getReturnUrl($request, 'app_administrative_teamer_index');
|
||||
$returnUrl = $this->generateUrl('app_administrative_teamer_index');
|
||||
|
||||
return new HxRedirectResponse($returnUrl);
|
||||
}
|
||||
@@ -48,7 +42,7 @@ class TeamerFilterController extends AbstractController
|
||||
public function reset(Request $request): Response
|
||||
{
|
||||
$this->filterHandler->resetFilterSettings();
|
||||
$returnUrl = $this->getReturnUrl($request, 'app_administrative_teamer_index');
|
||||
$returnUrl = $this->generateUrl('app_administrative_teamer_index');
|
||||
|
||||
return $this->redirect($returnUrl);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Model\FeedbackFilterDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class FeedbackFilterType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('name', TextType::class, [
|
||||
'label' => 'Name',
|
||||
'required' => false,
|
||||
])
|
||||
->add('dateFrom', DatepickerType::class, [
|
||||
'label' => 'Zeitraum von',
|
||||
'required' => false,
|
||||
])
|
||||
->add('dateTo', DatepickerType::class, [
|
||||
'label' => 'Zeitraum bis',
|
||||
'required' => false,
|
||||
])
|
||||
->add('averageRating', NumberType::class, [
|
||||
'label' => 'durschnittliche Bewertung mindestens',
|
||||
'required' => false,
|
||||
])
|
||||
->add('apply', SubmitType::class, [
|
||||
'label' => 'filtern',
|
||||
])
|
||||
->add('reset', SubmitType::class, [
|
||||
'label' => 'reset',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => FeedbackFilterDto::class,
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
class FeedbackFilterDto extends AbstractFilterDto
|
||||
{
|
||||
protected ?string $name = null;
|
||||
protected ?\DateTimeImmutable $dateFrom = null;
|
||||
protected ?\DateTimeImmutable $dateTo = null;
|
||||
protected ?int $averageRating = null;
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(?string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateFrom(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->dateFrom;
|
||||
}
|
||||
|
||||
public function setDateFrom(?\DateTimeImmutable $dateFrom): static
|
||||
{
|
||||
$this->dateFrom = $dateFrom;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateTo(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->dateTo;
|
||||
}
|
||||
|
||||
public function setDateTo(?\DateTimeImmutable $dateTo): static
|
||||
{
|
||||
$this->dateTo = $dateTo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAverageRating(): ?int
|
||||
{
|
||||
return $this->averageRating;
|
||||
}
|
||||
|
||||
public function setAverageRating(?int $averageRating): static
|
||||
{
|
||||
$this->averageRating = $averageRating;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\Feedback;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\FeedbackFilterDto;
|
||||
use App\Repository\Traits\QueryHelperTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
@@ -18,20 +20,52 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||
*/
|
||||
class FeedbackRepository extends ServiceEntityRepository
|
||||
{
|
||||
use QueryHelperTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Feedback::class);
|
||||
}
|
||||
|
||||
public function getListQuery(): Query
|
||||
public function getListQuery(FeedbackFilterDto $filterDto): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('feedback');
|
||||
|
||||
return $qb
|
||||
$qb
|
||||
->select('feedback', 'teamer')
|
||||
->innerJoin('feedback.teamer', 'teamer')
|
||||
->getQuery()
|
||||
;
|
||||
|
||||
if (null !== $name = $filterDto->getName()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->like('teamer.firstName', ':name'),
|
||||
$qb->expr()->like('teamer.lastName', ':name')
|
||||
))
|
||||
->setParameter('name', '%'.$this->escapeLikeWildcards($name).'%')
|
||||
;
|
||||
}
|
||||
if (null !== $rating = $filterDto->getAverageRating()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->gte('feedback.averageRating', ':rating'))
|
||||
->setParameter('rating', $rating)
|
||||
;
|
||||
}
|
||||
if (null !== $dateFrom = $filterDto->getDateFrom()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->gte('feedback.assignmentDateFrom', ':dateFrom'))
|
||||
->setParameter('dateFrom', $dateFrom)
|
||||
;
|
||||
}
|
||||
|
||||
if (null !== $dateTo = $filterDto->getDateTo()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->lte('feedback.assignmentDateTo', ':dateTo'))
|
||||
->setParameter('dateTo', $dateTo)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
public function getNew(int $limit = 5): array
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Common;
|
||||
|
||||
use App\Model\AbstractFilterDto;
|
||||
use App\Model\FeedbackFilterDto;
|
||||
|
||||
class FeedbackFilterHandler extends AbstractFilterHandler
|
||||
{
|
||||
protected string $namespace = 'filter:feedback';
|
||||
|
||||
public function getFilterSettings(): FeedbackFilterDto
|
||||
{
|
||||
if (null === $data = $this->getSession()->get($this->namespace)) {
|
||||
return new FeedbackFilterDto();
|
||||
}
|
||||
|
||||
$filterDto = new FeedbackFilterDto();
|
||||
|
||||
if (isset($data['name'])) {
|
||||
$filterDto->setName($data['name']);
|
||||
}
|
||||
if (isset($data['date_from'])) {
|
||||
$filterDto->setDateFrom($data['date_from']);
|
||||
}
|
||||
if (isset($data['date_to'])) {
|
||||
$filterDto->setDateTo($data['date_to']);
|
||||
}
|
||||
if (isset($data['average_rating'])) {
|
||||
$filterDto->setAverageRating($data['average_rating']);
|
||||
}
|
||||
|
||||
return $filterDto;
|
||||
}
|
||||
|
||||
protected function saveFilterSettings(AbstractFilterDto $filterDto): void
|
||||
{
|
||||
/** @var FeedbackFilterDto $filterDto */
|
||||
$this->getSession()->set($this->namespace, [
|
||||
'name' => $filterDto->getName(),
|
||||
'date_from' => $filterDto->getDateFrom(),
|
||||
'date_to' => $filterDto->getDateTo(),
|
||||
'average_rating' => $filterDto->getAverageRating(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user